executeProgram method

dynamic executeProgram(
  1. D4rtProgram program, {
  2. String name = 'main',
  3. List<Object?>? positionalArgs,
  4. Map<String, Object?>? namedArgs,
  5. Map<String, String>? sources,
  6. bool allowFileSystemImports = false,
  7. D4rtExecutionHooks? hooks,
})

Runs a program from parse exactly as execute would run its source, without parsing it again.

Like execute, this resets the global environment first; the arguments mean what they mean there. Only a direct source string can be a program — a root loaded by library URI goes through the module loader and stays with execute.

Implementation

dynamic executeProgram(
  D4rtProgram program, {
  String name = 'main',
  List<Object?>? positionalArgs,
  Map<String, Object?>? namedArgs,
  Map<String, String>? sources,
  bool allowFileSystemImports = false,
  D4rtExecutionHooks? hooks,
}) {
  _moduleLoader = _initModule(
    sources,
    basePath: program.basePath,
    allowFileSystemImports: allowFileSystemImports,
  );
  return _executeInEnvironment(
    compilationUnit: program._unit,
    executionEnvironment: _moduleLoader.scriptEnvironment,
    name: name,
    positionalArgs: positionalArgs,
    namedArgs: namedArgs,
  );
}