use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class NodeModuleRecord method instantiate.
@Override
public void instantiate() {
assert realm != null : "module is not linked";
if (environment == null) {
ScriptObject exports = getModuleExportsOrEmpty();
environment = newObjectEnvironment(exports, realm.getGlobalEnv());
// Compile the module.
ExecutionContext cx = realm.defaultContext();
Object compile = Get(cx, moduleObject, "compile");
Callable moduleFn = CreateDynamicFunction(cx, source, function.getFunction());
Callable requireFn = NodeFunctions.createRequireFunction(this);
Call(cx, compile, moduleObject, moduleFn, requireFn);
// Create the module bindings.
ScriptObject currentExports = getModuleExportsOrEmpty();
if (currentExports != exports) {
// Module exports property has changed, update environment with new bindings.
environment = newObjectEnvironment(currentExports, realm.getGlobalEnv());
}
exportedNames = ownNames(currentExports);
instantiated = true;
}
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ObjectConstructor method construct.
/**
* 19.1.1.1 Object ( [ value ] )
*/
@Override
public ScriptObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object value = argument(args, 0);
/* step 1 */
if (newTarget != this) {
return OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.ObjectPrototype);
}
/* step 2 */
if (Type.isUndefinedOrNull(value)) {
// (= `this`) is not the intrinsic %Object% constructor function.
return OrdinaryCreateFromConstructor(calleeContext, this, Intrinsics.ObjectPrototype);
}
/* step 3 */
return ToObject(calleeContext, value);
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class SourceTextModuleRecord method instantiate.
/**
* 15.2.1.16.4 ModuleDeclarationInstantiation( ) Concrete Method
*/
@Override
public void instantiate() throws IOException, MalformedNameException, ResolutionException {
/* step 1 */
SourceTextModuleRecord module = this;
/* step 2 */
Realm realm = module.realm;
/* step 3 */
assert realm != null : "module is not linked";
/* step 4 */
Module code = module.scriptCode;
/* step 5 */
if (module.environment != null) {
return;
}
/* step 6 */
LexicalEnvironment<ModuleEnvironmentRecord> env = newModuleEnvironment(realm.getGlobalEnv());
/* step 7 */
module.environment = env;
/* step 8 */
for (String required : module.requestedModules) {
/* step 8.a (note) */
/* steps 8.b-c */
ModuleRecord requiredModule = HostResolveImportedModule(module, required);
/* steps 8.d-e */
requiredModule.instantiate();
}
/* steps 9-17 */
ExecutionContext context = newModuleDeclarationExecutionContext(realm, code);
code.getModuleBody().moduleDeclarationInstantiation(context, this, env);
module.instantiated = true;
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ArrayConstructor method construct.
/**
* 22.1.1.1 Array ( )<br>
* 22.1.1.2 Array (len)<br>
* 22.1.1.3 Array (...items )
*/
@Override
public ArrayObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
/* step 1 */
int numberOfArgs = args.length;
/* steps 2-3 (not applicable) */
/* steps 4-5 */
ScriptObject proto = GetPrototypeFromConstructor(calleeContext, newTarget, Intrinsics.ArrayPrototype);
if (numberOfArgs == 0) {
/* step 6 */
return ArrayCreate(calleeContext, 0, proto);
} else if (numberOfArgs == 1) {
// [22.1.1.2]
Object len = args[0];
/* steps 6-11 */
if (!Type.isNumber(len)) {
return DenseArrayCreate(calleeContext, proto, len);
} else {
double llen = Type.numberValue(len);
long intLen = ToUint32(llen);
if (intLen != llen) {
throw newRangeError(calleeContext, Messages.Key.InvalidArrayLength);
}
return ArrayCreate(calleeContext, intLen, proto);
}
} else {
/* steps 6-12 */
return DenseArrayCreate(calleeContext, proto, args);
}
}
use of com.github.anba.es6draft.runtime.ExecutionContext in project es6draft by anba.
the class ErrorConstructor method construct.
/**
* 19.5.1.1 Error (message)
* <p>
* <strong>Extension</strong>: Error (message, fileName, lineNumber, columnNumber)
*/
@Override
public ErrorObject construct(ExecutionContext callerContext, Constructor newTarget, Object... args) {
ExecutionContext calleeContext = calleeContext();
Object message = argument(args, 0);
/* step 1 (not applicable) */
/* steps 2-3 */
ErrorObject obj = OrdinaryCreateFromConstructor(calleeContext, newTarget, Intrinsics.ErrorPrototype, ErrorObject::new);
/* step 4 */
if (!Type.isUndefined(message)) {
CharSequence msg = ToString(calleeContext, message);
obj.defineErrorProperty("message", msg, false);
}
/* extension: fileName, lineNumber and columnNumber arguments */
if (args.length > 1) {
CharSequence fileName = ToString(calleeContext, args[1]);
obj.defineErrorProperty("fileName", fileName, true);
}
if (args.length > 2) {
int line = ToInt32(calleeContext, args[2]);
obj.defineErrorProperty("lineNumber", line, true);
}
if (args.length > 3) {
int column = ToInt32(calleeContext, args[3]);
obj.defineErrorProperty("columnNumber", column, true);
}
/* step 5 */
return obj;
}
Aggregations