Search in sources :

Example 6 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class TestGlobals method newGlobal.

public final GLOBAL newGlobal(Console console, TEST test) throws MalformedNameException, ResolutionException, IOException, URISyntaxException {
    RuntimeContext context = createContext(console, test);
    World world = new World(context);
    Realm realm = world.newInitializedRealm();
    // Evaluate additional initialization scripts and modules
    TestModuleLoader<?> moduleLoader = (TestModuleLoader<?>) world.getModuleLoader();
    for (ModuleRecord module : modules.allModules) {
        moduleLoader.defineFromTemplate(module, realm);
    }
    for (ModuleRecord module : modules.mainModules) {
        ModuleRecord testModule = moduleLoader.get(module.getSourceCodeId(), realm);
        testModule.instantiate();
        testModule.evaluate();
    }
    for (Script script : scripts) {
        script.evaluate(realm);
    }
    @SuppressWarnings("unchecked") GLOBAL global = (GLOBAL) realm.getGlobalObject();
    return global;
}
Also used : Script(com.github.anba.es6draft.Script) ModuleRecord(com.github.anba.es6draft.runtime.modules.ModuleRecord) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) World(com.github.anba.es6draft.runtime.World) Realm(com.github.anba.es6draft.runtime.Realm)

Example 7 with RuntimeContext

use of com.github.anba.es6draft.runtime.internal.RuntimeContext in project es6draft by anba.

the class TestGlobals method compileScripts.

private List<Script> compileScripts() throws IOException {
    List<?> scriptNames = configuration.getList("scripts", emptyList());
    if (scriptNames.isEmpty()) {
        return Collections.emptyList();
    }
    Path basedir = getBaseDirectory();
    RuntimeContext context = createContext();
    ScriptLoader scriptLoader = new ScriptLoader(context);
    ArrayList<Script> scripts = new ArrayList<>();
    for (String scriptName : nonEmpty(scriptNames)) {
        Source source = new Source(Resources.resourcePath(scriptName, basedir), scriptName, 1);
        Script script = scriptLoader.script(source, Resources.resource(scriptName, basedir));
        scripts.add(script);
    }
    return scripts;
}
Also used : Path(java.nio.file.Path) Script(com.github.anba.es6draft.Script) ArrayList(java.util.ArrayList) RuntimeContext(com.github.anba.es6draft.runtime.internal.RuntimeContext) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) Source(com.github.anba.es6draft.runtime.internal.Source)

Aggregations

RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)7 Realm (com.github.anba.es6draft.runtime.Realm)4 Script (com.github.anba.es6draft.Script)3 World (com.github.anba.es6draft.runtime.World)3 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 ExecutionContext.newScriptingExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newScriptingExecutionContext)2 Console (com.github.anba.es6draft.runtime.internal.Console)2 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)2 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)2 Source (com.github.anba.es6draft.runtime.internal.Source)2 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)2 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)2 ArrayList (java.util.ArrayList)2 NodeModuleLoader (com.github.anba.es6draft.repl.loader.NodeModuleLoader)1 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)1 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)1 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)1 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)1 SharedArrayBufferObject (com.github.anba.es6draft.runtime.objects.atomics.SharedArrayBufferObject)1 Callable (com.github.anba.es6draft.runtime.types.Callable)1