use of com.github.anba.es6draft.Script in project es6draft by anba.
the class Properties method createConstructor.
private static OrdinaryObject createConstructor(ExecutionContext cx, String className, OrdinaryObject proto, Converter converter, ObjectLayout layout) {
Entry<Function, MethodHandle> constructorEntry = findConstructor(layout);
if (constructorEntry != null) {
// User supplied method, perform manual ClassDefinitionEvaluation for constructors
Function function = constructorEntry.getKey();
MethodHandle unreflect = constructorEntry.getValue();
MethodHandle callMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Call);
MethodHandle constructMethod = getConstructorStaticMethodHandle(cx, converter, unreflect, MethodKind.Construct);
NativeConstructor constructor = new NativeConstructor(cx.getRealm(), className, function.arity(), callMethod, constructMethod);
constructor.defineOwnProperty(cx, "prototype", new PropertyDescriptor(proto, false, false, false));
proto.defineOwnProperty(cx, "constructor", new PropertyDescriptor(constructor, true, false, true));
return constructor;
}
// Create default constructor
String sourceText = String.format("(class %s { })", sanitizeName(className));
ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
Script script = scriptLoader.script(new Source("<Constructor>", 1), sourceText);
Object constructor = script.evaluate(cx);
assert constructor instanceof OrdinaryConstructorFunction : constructor.getClass();
return (OrdinaryConstructorFunction) constructor;
}
use of com.github.anba.es6draft.Script 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;
}
use of com.github.anba.es6draft.Script 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;
}
Aggregations