Search in sources :

Example 21 with DeclarativeEnvironmentRecord

use of com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord in project es6draft by anba.

the class InterpretedScriptBody method evalScriptEvaluation.

/**
     * 18.2.1.1 Runtime Semantics: PerformEval( x, evalRealm, strictCaller, direct)
     * 
     * @param cx
     *            the execution context
     * @param script
     *            the script object
     * @return the script evaluation result
     */
private Object evalScriptEvaluation(ExecutionContext cx, Script script) {
    // TODO: Skip allocating lex-env if not needed
    /* steps 1-5 (not applicable) */
    /* steps 6-7 */
    boolean strictEval = parsedScript.isStrict();
    /* step 8 (omitted) */
    /* steps 9-10 */
    LexicalEnvironment<DeclarativeEnvironmentRecord> lexEnv;
    LexicalEnvironment<?> varEnv;
    if (parsedScript.isDirectEval()) {
        /* step 9 */
        lexEnv = newDeclarativeEnvironment(cx.getLexicalEnvironment());
        varEnv = cx.getVariableEnvironment();
    } else {
        Realm evalRealm = cx.getRealm();
        /* step 10 */
        lexEnv = newDeclarativeEnvironment(evalRealm.getGlobalEnv());
        varEnv = evalRealm.getGlobalEnv();
    }
    /* step 11 */
    if (strictEval) {
        varEnv = lexEnv;
    }
    /* steps 12-17 */
    ExecutionContext evalCxt = newEvalExecutionContext(cx, script, varEnv, lexEnv);
    /* step 18 */
    EvalDeclarationInstantiation(evalCxt, parsedScript, varEnv, lexEnv);
    /* steps 19-23 */
    return parsedScript.accept(new Interpreter(parsedScript), evalCxt);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ExecutionContext.newScriptExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newScriptExecutionContext) ExecutionContext.newEvalExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext.newEvalExecutionContext) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) Realm(com.github.anba.es6draft.runtime.Realm)

Example 22 with DeclarativeEnvironmentRecord

use of com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord in project es6draft by anba.

the class ScriptRuntime method EvaluateConstructorGeneratorExpression.

/**
     * 14.4 Generator Function Definitions
     * <p>
     * 14.4.14 Runtime Semantics: Evaluation
     * <ul>
     * <li>GeneratorExpression: function* ( FormalParameters ) { FunctionBody }
     * <li>GeneratorExpression: function* BindingIdentifier ( FormalParameters ) { FunctionBody }
     * </ul>
     * 
     * @param fd
     *            the function runtime info object
     * @param cx
     *            the execution context
     * @return the new generator function instance
     */
public static OrdinaryConstructorGenerator EvaluateConstructorGeneratorExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
    OrdinaryConstructorGenerator closure;
    if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        closure = ConstructorGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
        /* step 4 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
        /* step 5 */
        MakeConstructor(closure, true, prototype);
    } else {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        LexicalEnvironment<DeclarativeEnvironmentRecord> funcEnv = newDeclarativeEnvironment(scope);
        /* step 4 */
        DeclarativeEnvironmentRecord envRec = funcEnv.getEnvRec();
        /* step 5 */
        String name = fd.functionName();
        /* step 6 */
        envRec.createImmutableBinding(name, false);
        /* step 7 */
        closure = ConstructorGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
        /* step 8 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
        /* step 9 */
        MakeConstructor(closure, true, prototype);
        /* step 10 */
        SetFunctionName(closure, name);
        /* step 11 */
        envRec.initializeBinding(name, closure);
    }
    /* step 6/12 */
    return closure;
}
Also used : ConsString(org.mozilla.javascript.ConsString) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 23 with DeclarativeEnvironmentRecord

use of com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord in project es6draft by anba.

the class ScriptRuntime method EvaluateLegacyGeneratorExpression.

/**
     * 14.4 Generator Function Definitions
     * <p>
     * 14.4.14 Runtime Semantics: Evaluation
     * <ul>
     * <li>GeneratorExpression: function* ( FormalParameters ) { FunctionBody }
     * <li>GeneratorExpression: function* BindingIdentifier ( FormalParameters ) { FunctionBody }
     * </ul>
     * 
     * @param fd
     *            the function runtime info object
     * @param cx
     *            the execution context
     * @return the new generator function instance
     */
public static OrdinaryConstructorGenerator EvaluateLegacyGeneratorExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
    OrdinaryConstructorGenerator closure;
    if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        closure = ConstructorGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
        /* step 4 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.LegacyGeneratorPrototype);
        /* step 5 */
        MakeConstructor(closure, true, prototype);
    } else {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 2 */
        LexicalEnvironment<DeclarativeEnvironmentRecord> funcEnv = newDeclarativeEnvironment(scope);
        /* step 4 */
        DeclarativeEnvironmentRecord envRec = funcEnv.getEnvRec();
        /* step 5 */
        String name = fd.functionName();
        /* step 6 */
        envRec.createImmutableBinding(name, false);
        /* step 7 */
        closure = ConstructorGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
        /* step 8 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.LegacyGeneratorPrototype);
        /* step 9 */
        MakeConstructor(closure, true, prototype);
        /* step 10 */
        SetFunctionName(closure, name);
        /* step 11 */
        envRec.initializeBinding(name, closure);
    }
    /* step 6/12 */
    return closure;
}
Also used : ConsString(org.mozilla.javascript.ConsString) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 24 with DeclarativeEnvironmentRecord

use of com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord in project es6draft by anba.

the class ScriptRuntime method EvaluateGeneratorExpression.

/**
     * 14.4 Generator Function Definitions
     * <p>
     * 14.4.14 Runtime Semantics: Evaluation
     * <ul>
     * <li>GeneratorExpression: function* ( FormalParameters ) { FunctionBody }
     * <li>GeneratorExpression: function* BindingIdentifier ( FormalParameters ) { FunctionBody }
     * </ul>
     * 
     * @param fd
     *            the function runtime info object
     * @param cx
     *            the execution context
     * @return the new generator function instance
     */
public static OrdinaryGenerator EvaluateGeneratorExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
    OrdinaryGenerator closure;
    if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        closure = GeneratorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
        /* step 4 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
        /* step 5 */
        closure.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    } else {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        LexicalEnvironment<DeclarativeEnvironmentRecord> funcEnv = newDeclarativeEnvironment(scope);
        /* step 4 */
        DeclarativeEnvironmentRecord envRec = funcEnv.getEnvRec();
        /* step 5 */
        String name = fd.functionName();
        /* step 6 */
        envRec.createImmutableBinding(name, false);
        /* step 7 */
        closure = GeneratorFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
        /* step 8 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
        /* step 9 */
        closure.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
        /* step 10 */
        SetFunctionName(closure, name);
        /* step 11 */
        envRec.initializeBinding(name, closure);
    }
    /* step 6/12 */
    return closure;
}
Also used : ConsString(org.mozilla.javascript.ConsString) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 25 with DeclarativeEnvironmentRecord

use of com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord in project es6draft by anba.

the class ScriptRuntime method EvaluateAsyncGeneratorExpression.

/**
     * Extension: Async Generator Function Definitions
     * 
     * @param fd
     *            the function runtime info object
     * @param cx
     *            the execution context
     * @return the new async generator instance
     */
public static OrdinaryAsyncGenerator EvaluateAsyncGeneratorExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
    OrdinaryAsyncGenerator closure;
    if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        closure = AsyncGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, scope);
        /* step 4 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
        /* step 5 */
        closure.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
    } else {
        /* step 1 (not applicable) */
        /* step 2 */
        LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
        /* step 3 */
        LexicalEnvironment<DeclarativeEnvironmentRecord> funcEnv = newDeclarativeEnvironment(scope);
        /* step 4 */
        DeclarativeEnvironmentRecord envRec = funcEnv.getEnvRec();
        /* step 5 */
        String name = fd.functionName();
        /* step 6 */
        envRec.createImmutableBinding(name, false);
        /* step 7 */
        closure = AsyncGeneratorFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
        /* step 8 */
        OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
        /* step 9 */
        closure.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
        /* step 10 */
        SetFunctionName(closure, name);
        /* step 11 */
        envRec.initializeBinding(name, closure);
    }
    /* step 6/12 */
    return closure;
}
Also used : ConsString(org.mozilla.javascript.ConsString) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Aggregations

DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)25 Name (com.github.anba.es6draft.ast.scope.Name)16 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)15 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)8 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)7 Jump (com.github.anba.es6draft.compiler.assembler.Jump)7 ConsString (org.mozilla.javascript.ConsString)7 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)6 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)6 ScriptName (com.github.anba.es6draft.compiler.CodeGenerator.ScriptName)5 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)4 InitializeBoundName (com.github.anba.es6draft.compiler.BindingInitializationGenerator.InitializeBoundName)4 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)4 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)4 Declaration (com.github.anba.es6draft.ast.Declaration)3 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)3 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)3 ArrayDeque (java.util.ArrayDeque)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3