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();
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class ModuleOperations method HostImportModuleDynamically.
/**
* Runtime Semantics: HostImportModuleDynamically ( referencingScriptOrModule, specifier, promiseCapability )
*
* @param cx
* the execution context
* @param specifier
* the module specifier
* @param promiseCapability
* the promise capability
*/
private static void HostImportModuleDynamically(ExecutionContext cx, String specifier, PromiseCapability<PromiseObject> promiseCapability) {
Source source = cx.getCurrentExecutable().getSource();
assert source != null : "HostImportModuleDynamically is only called from compiled code";
// FIXME: spec bug - cannot assert referencingScriptOrModule is non-null, e.g. consider:
// Promise.resolve(`import("./t.js").catch(e => print("caught", e))`).then(eval);
// Or:
// Promise.resolve(`import("./t.js").catch(e => print("caught",
// e))`).then(Function).then(Function.prototype.call.bind(Function.prototype.call));
SourceIdentifier referredId = source.getSourceId();
if (referredId == null) {
ScriptException exception = newReferenceError(cx, Messages.Key.ModulesInvalidName, specifier);
FinishDynamicImport(cx, specifier, promiseCapability, exception);
return;
}
Realm realm = cx.getRealm();
ModuleLoader moduleLoader = realm.getModuleLoader();
SourceIdentifier moduleId;
try {
moduleId = moduleLoader.normalizeName(specifier, referredId);
} catch (MalformedNameException e) {
FinishDynamicImport(cx, specifier, promiseCapability, e.toScriptException(cx));
return;
}
moduleLoader.resolveAsync(moduleId, realm).whenComplete((module, err) -> {
realm.enqueueAsyncJob(() -> {
Throwable error = err;
if (module != null) {
try {
module.instantiate();
module.evaluate();
} catch (ScriptException | IOException | MalformedNameException | ResolutionException e) {
assert error == null;
error = e;
}
}
if (error != null) {
ScriptException exception = toScriptException(cx, error, moduleId, referredId);
FinishDynamicImport(cx, specifier, promiseCapability, exception);
} else {
FinishDynamicImport(cx, specifier, promiseCapability, module, referredId);
}
});
});
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class Eval method script.
private static Script script(ExecutionContext cx, ExecutionContext caller, String sourceCode, int flags) {
try {
Realm realm = cx.getRealm();
Source source = evalSource(caller);
EnumSet<Parser.Option> options = EvalFlags.toOptions(flags);
EnumSet<Parser.Option> contextOptions = realm.getRuntimeContext().getParserOptions();
if (contextOptions.contains(Parser.Option.NativeCall)) {
options.add(Parser.Option.NativeCall);
}
return realm.getScriptLoader().evalScript(source, sourceCode, options);
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class SourceTextModuleRecord method ModuleDeclarationEnvironmentSetup.
/**
* 15.2.1.16.4.2 ModuleDeclarationEnvironmentSetup( module )
*/
private static void ModuleDeclarationEnvironmentSetup(SourceTextModuleRecord module) throws IOException, ResolutionException, MalformedNameException {
/* step 3 */
Realm realm = module.realm;
/* step 4 */
assert realm != null : "module is not linked";
/* step 5 */
LexicalEnvironment<ModuleEnvironmentRecord> env = newModuleEnvironment(realm.getGlobalEnv());
/* step 6 */
module.environment = env;
/* steps 1-2, 7-14 (generated code) */
Module code = module.scriptCode;
ExecutionContext context = newModuleDeclarationExecutionContext(realm, code);
code.getModuleBody().moduleDeclarationInstantiation(context, module, env);
}
use of com.github.anba.es6draft.runtime.Realm in project es6draft by anba.
the class SourceTextModuleRecord method ModuleExecution.
/**
* 15.2.1.16.5.2 ModuleExecution( module )
*/
private static Object ModuleExecution(SourceTextModuleRecord module) {
/* step 3 */
Realm realm = module.realm;
assert realm != null : "module is not linked";
/* steps 1-2, 4-8 */
ExecutionContext moduleContext = newModuleExecutionContext(realm, module);
/* step 9 */
ExecutionContext oldScriptContext = realm.getWorld().getScriptContext();
try {
/* step 10 */
realm.getWorld().setScriptContext(moduleContext);
/* step 11 */
Object result = module.scriptCode.evaluate(moduleContext);
/* step 14 */
return result;
} finally {
/* steps 12-13 */
realm.getWorld().setScriptContext(oldScriptContext);
}
}
Aggregations