Search in sources :

Example 41 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class TestRealms method newRealm.

public final Realm newRealm(Console console, TEST test) throws MalformedNameException, ResolutionException, IOException {
    RuntimeContext context = createContext(console, test);
    World world = new World(context);
    Realm realm = Realm.InitializeHostDefinedRealm(world);
    // 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);
    }
    return realm;
}
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 42 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class Test262TestRealm method executeStrict.

/**
 * Executes the supplied test object.
 *
 * @param test
 *            the test-info object
 * @throws ParserException
 *             if the module source contains any syntax errors
 * @throws CompilationException
 *             if the parsed module source cannot be compiled
 */
void executeStrict(Test262Info test) throws ParserException, CompilationException {
    // Return early if no source code is available.
    if (sourceCode == null) {
        return;
    }
    assert !test.isAsync() || async != null;
    assert !(test.isModule() || test.isRaw());
    Realm realm = get();
    // Parse the test-script
    Source source = new Source(test.toFile(), test.getScript().toString(), 1);
    ScriptLoader scriptLoader = realm.getScriptLoader();
    EnumSet<Parser.Option> parserOptions = EnumSet.copyOf(realm.getRuntimeContext().getParserOptions());
    parserOptions.add(Parser.Option.Strict);
    Parser parser = new Parser(realm.getRuntimeContext(), source, parserOptions);
    com.github.anba.es6draft.ast.Script parsedScript = parser.parseScript(sourceCode);
    // Evaluate the test-script
    Script script = scriptLoader.load(parsedScript);
    script.evaluate(realm);
    // Wait for pending jobs to finish
    waitForPendingJobs(realm, test);
}
Also used : Script(com.github.anba.es6draft.Script) Realm(com.github.anba.es6draft.runtime.Realm) StringModuleSource(com.github.anba.es6draft.runtime.modules.loader.StringModuleSource) Source(com.github.anba.es6draft.runtime.internal.Source) ModuleSource(com.github.anba.es6draft.runtime.modules.ModuleSource) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader) Parser(com.github.anba.es6draft.parser.Parser)

Example 43 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class WebkitTest method runTest.

@Test
public void runTest() throws Throwable {
    Realm realm = this.realm.get();
    // Evaluate actual test-script
    // - load and execute pre and post before resp. after test-script
    ScriptLoading.include(realm, test.getBaseDir().resolve("resources/standalone-pre.js"));
    ScriptLoading.eval(realm, test.getScript(), test.toFile());
    ScriptLoading.include(realm, test.getBaseDir().resolve("resources/standalone-post.js"));
    // Wait for pending jobs to finish
    realm.getWorld().runEventLoop();
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm) TestRealm(com.github.anba.es6draft.util.TestRealm) Test(org.junit.Test)

Example 44 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class TestRealm method execute.

/**
 * Executes the supplied test object.
 *
 * @param test
 *            the test-info object
 * @throws IOException
 *             if there was any I/O error
 * @throws MalformedNameException
 *             if any imported module request cannot be normalized
 * @throws ResolutionException
 *             if any export binding cannot be resolved
 * @throws ParserException
 *             if the module source contains any syntax errors
 * @throws CompilationException
 *             if the parsed module source cannot be compiled
 */
public void execute(TEST test) throws ParserException, CompilationException, IOException, MalformedNameException, ResolutionException {
    Realm realm = get();
    // Evaluate actual test-script
    if (test.isModule()) {
        ScriptLoading.evalModule(realm, test.toModuleName());
    } else {
        ScriptLoading.eval(realm, test.getScript(), test.toFile());
    }
    // Wait for pending jobs to finish
    realm.getWorld().runEventLoop();
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Example 45 with Realm

use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.

the class TestRealm method execute.

/**
 * Executes the supplied test object.
 *
 * @param test
 *            the test-info object
 * @param jobSource
 *            the job source
 * @throws IOException
 *             if there was any I/O error
 * @throws MalformedNameException
 *             if any imported module request cannot be normalized
 * @throws ResolutionException
 *             if any export binding cannot be resolved
 * @throws ParserException
 *             if the module source contains any syntax errors
 * @throws CompilationException
 *             if the parsed module source cannot be compiled
 * @throws InterruptedException
 *             if interrupted while waiting
 */
public void execute(TEST test, JobSource jobSource) throws ParserException, CompilationException, IOException, MalformedNameException, ResolutionException, InterruptedException {
    Realm realm = get();
    // Evaluate actual test-script
    if (test.isModule()) {
        ScriptLoading.evalModule(realm, test.toModuleName());
    } else {
        ScriptLoading.eval(realm, test.getScript(), test.toFile());
    }
    // Wait for pending jobs to finish
    realm.getWorld().runEventLoop(jobSource);
}
Also used : Realm(com.github.anba.es6draft.runtime.Realm)

Aggregations

Realm (com.github.anba.es6draft.runtime.Realm)96 Test (org.junit.Test)39 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)17 Script (com.github.anba.es6draft.Script)16 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)16 Source (com.github.anba.es6draft.runtime.internal.Source)15 ParserException (com.github.anba.es6draft.parser.ParserException)9 Function (com.github.anba.es6draft.runtime.internal.Properties.Function)9 ModuleRecord (com.github.anba.es6draft.runtime.modules.ModuleRecord)8 ModuleLoader (com.github.anba.es6draft.runtime.modules.ModuleLoader)7 IOException (java.io.IOException)7 CompilationException (com.github.anba.es6draft.compiler.CompilationException)6 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)6 ToSource (com.github.anba.es6draft.repl.SourceBuilder.ToSource)5 World (com.github.anba.es6draft.runtime.World)5 RuntimeContext (com.github.anba.es6draft.runtime.internal.RuntimeContext)5 ModuleSource (com.github.anba.es6draft.runtime.modules.ModuleSource)5 SourceIdentifier (com.github.anba.es6draft.runtime.modules.SourceIdentifier)5 GlobalObject (com.github.anba.es6draft.runtime.objects.GlobalObject)5 ExecutionContext.newEvalExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext.newEvalExecutionContext)4