Search in sources :

Example 16 with ExecutionContext

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;
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Callable(com.github.anba.es6draft.runtime.types.Callable)

Example 17 with ExecutionContext

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);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ImmutablePrototypeObject(com.github.anba.es6draft.runtime.types.builtins.ImmutablePrototypeObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 18 with ExecutionContext

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;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newModuleDeclarationExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleDeclarationExecutionContext) ExecutionContext.newModuleExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newModuleExecutionContext) HostResolveImportedModule(com.github.anba.es6draft.runtime.modules.ModuleSemantics.HostResolveImportedModule) Module(com.github.anba.es6draft.Module) Realm(com.github.anba.es6draft.runtime.Realm) ModuleEnvironmentRecord(com.github.anba.es6draft.runtime.ModuleEnvironmentRecord)

Example 19 with ExecutionContext

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);
    }
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject)

Example 20 with ExecutionContext

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;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)70 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)46 AbstractOperations (com.github.anba.es6draft.runtime.AbstractOperations)10 Realm (com.github.anba.es6draft.runtime.Realm)10 Callable (com.github.anba.es6draft.runtime.types.Callable)10 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)9 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)8 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)7 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)6 Name (com.github.anba.es6draft.ast.scope.Name)5 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)5 HashSet (java.util.HashSet)5 Declaration (com.github.anba.es6draft.ast.Declaration)4 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)4 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)4 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)4 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)4 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)4 IsCallable (com.github.anba.es6draft.runtime.AbstractOperations.IsCallable)4 ToObject (com.github.anba.es6draft.runtime.AbstractOperations.ToObject)4