use of com.github.anba.es6draft.runtime.internal.ScriptLoader in project es6draft by anba.
the class GeneratorFunctionConstructor method CreateDynamicGenerator.
private static OrdinaryGenerator CreateDynamicGenerator(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.Generator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.Generator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.generator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryGenerator f = OrdinaryGenerator.FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.internal.ScriptLoader in project es6draft by anba.
the class AsyncGeneratorFunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param callerContext
* the caller execution context
* @param cx
* the execution context
* @param newTarget
* the newTarget constructor function
* @param args
* the function arguments
* @return the new async generator function object
*/
private static FunctionObject CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
/* step 1 (not applicable) */
/* step 2 (not applicable) */
/* step 3 */
Intrinsics fallbackProto = Intrinsics.AsyncGenerator;
/* steps 4-10 */
String[] sourceText = functionSourceText(cx, args);
String parameters = sourceText[0], bodyText = sourceText[1];
/* steps 11, 13-20 */
Source source = functionSource(SourceKind.AsyncGenerator, cx.getRealm(), callerContext);
RuntimeInfo.Function function;
try {
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
function = scriptLoader.asyncGenerator(source, parameters, bodyText).getFunction();
} catch (ParserException | CompilationException e) {
throw e.toScriptException(cx);
}
/* step 12 */
boolean strict = function.isStrict();
/* steps 21-22 */
ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
/* step 23 */
OrdinaryAsyncGenerator f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
/* steps 24-25 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 26 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
/* step 27 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
/* step 28 (not applicable) */
/* step 29 */
SetFunctionName(f, "anonymous");
/* step 30 */
return f;
}
use of com.github.anba.es6draft.runtime.internal.ScriptLoader in project es6draft by anba.
the class TestGlobals method compileModules.
private PreloadModules compileModules() throws IOException, MalformedNameException {
List<?> moduleNames = configuration.getList("modules", emptyList());
if (moduleNames.isEmpty()) {
return new PreloadModules(Collections.<ModuleRecord>emptyList(), Collections.<ModuleRecord>emptyList());
}
RuntimeContext context = createContext();
ScriptLoader scriptLoader = new ScriptLoader(context);
TestModuleLoader<?> moduleLoader = this.moduleLoader.apply(context, scriptLoader);
ArrayList<ModuleRecord> modules = new ArrayList<>();
for (String moduleName : nonEmpty(moduleNames)) {
SourceIdentifier moduleId = moduleLoader.normalizeName(moduleName, null);
modules.add(moduleLoader.load(moduleId));
}
return new PreloadModules(modules, moduleLoader.getModules());
}
use of com.github.anba.es6draft.runtime.internal.ScriptLoader in project es6draft by anba.
the class TestRealms method compileScripts.
private List<Script> compileScripts() throws IOException {
List<String> scriptNames = Resources.list(configuration, "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 : scriptNames) {
Map.Entry<Either<Path, URL>, InputStream> resourceScript = Resources.resourceScript(scriptName, basedir);
Source source = resourceScript.getKey().map(path -> new Source(path, scriptName, 1), url -> new Source(new URLSourceIdentifier(url), scriptName, 1));
Script script = scriptLoader.script(source, resourceScript.getValue());
scripts.add(script);
}
return scripts;
}
use of com.github.anba.es6draft.runtime.internal.ScriptLoader 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);
}
Aggregations