Search in sources :

Example 1 with ExecutionContext

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

the class ListIteratorNext method call.

@Override
public OrdinaryObject call(ExecutionContext callerContext, Object thisValue, Object... args) {
    ExecutionContext calleeContext = calleeContext();
    /* steps 3, 6 */
    if (!(thisValue instanceof ListIterator)) {
        throw newTypeError(calleeContext, Messages.Key.IncompatibleObject);
    }
    ListIterator<?> listIterator = (ListIterator<?>) thisValue;
    /* steps 4-5 */
    if (this != listIterator.getIteratorNext()) {
        throw newTypeError(calleeContext, Messages.Key.IncompatibleObject);
    }
    /* step 7 */
    Iterator<?> iterator = listIterator.getIterator();
    /* steps 8-10 */
    if (!iterator.hasNext()) {
        return CreateIterResultObject(calleeContext, UNDEFINED, true);
    }
    /* steps 11-12 */
    return CreateIterResultObject(calleeContext, iterator.next(), false);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext)

Example 2 with ExecutionContext

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

the class CodeGenerator method compile.

MethodName compile(SwitchStatement node, BlockDeclarationInstantiationGenerator generator) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
        body.lineInfo(node);
        body.begin();
        Variable<ExecutionContext> cx = body.getExecutionContext();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
        generator.generateMethod(node, cx, env, body);
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 3 with ExecutionContext

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

the class CodeGenerator method compile.

MethodName compile(SwitchStatement node, List<Declaration> declarations, BlockDeclarationInstantiationGenerator generator) {
    MethodCode method = newMethod2(node);
    BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
    body.lineInfo(node);
    body.begin();
    Variable<ExecutionContext> cx = body.getExecutionContext();
    Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
    generator.generateMethod(declarations, cx, env, body);
    body._return();
    body.end();
    return methodDesc(node, method.methodName);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 4 with ExecutionContext

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

the class CodeGenerator method compile.

MethodName compile(BlockStatement node, BlockDeclarationInstantiationGenerator generator) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
        body.lineInfo(node);
        body.begin();
        Variable<ExecutionContext> cx = body.getExecutionContext();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
        generator.generateMethod(node, cx, env, body);
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 5 with ExecutionContext

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

the class FunctionCodeGenerator method generateLegacyFunctionConstruct.

/**
     * Generate bytecode for:
     * 
     * <pre>
     * oldCaller = function.getLegacyCaller()
     * oldArguments = function.getLegacyArguments()
     * function.setLegacyCaller(callerContext.getCurrentFunction())
     * try {
     *   thisArgument = OrdinaryCreateFromConstructor(callerContext, newTarget, %ObjectPrototype%)
     *   calleeContext = newFunctionExecutionContext(function, newTarget, thisArgument)
     *   result = OrdinaryCallEvaluateBody(function, argumentsList)
     *   return returnResultOrThis(result)
     * } finally {
     *   function.restoreLegacyProperties(oldCaller, oldArguments)
     * }
     * </pre>
     * 
     * @param node
     *            the function node
     * @param mv
     *            the instruction visitor
     */
private void generateLegacyFunctionConstruct(FunctionNode node, InstructionVisitor mv) {
    final boolean hasArguments = codegen.isEnabled(CompatibilityOption.FunctionArguments);
    final boolean hasCaller = codegen.isEnabled(CompatibilityOption.FunctionCaller);
    Variable<LegacyConstructorFunction> function = mv.getParameter(FUNCTION, LegacyConstructorFunction.class);
    Variable<ExecutionContext> callerContext = mv.getParameter(EXECUTION_CONTEXT, ExecutionContext.class);
    Variable<Constructor> newTarget = mv.getParameter(NEW_TARGET, Constructor.class);
    Variable<Object[]> arguments = mv.getParameter(ARGUMENTS, Object[].class);
    Variable<ScriptObject> thisArg = mv.newVariable("thisArgument", ScriptObject.class);
    Variable<ExecutionContext> calleeContext = mv.newVariable("calleeContext", ExecutionContext.class);
    Variable<FunctionObject> oldCaller = mv.newVariable("oldCaller", FunctionObject.class);
    Variable<LegacyConstructorFunction.Arguments> oldArguments = mv.newVariable("oldArguments", LegacyConstructorFunction.Arguments.class);
    Variable<Throwable> throwable = mv.newVariable("throwable", Throwable.class);
    // (1) Retrieve 'caller' and 'arguments' and store in local variables
    if (hasCaller) {
        mv.load(function);
        mv.invoke(Methods.LegacyConstructorFunction_getLegacyCaller);
    } else {
        mv.anull();
    }
    mv.store(oldCaller);
    if (hasArguments) {
        mv.load(function);
        mv.invoke(Methods.LegacyConstructorFunction_getLegacyArguments);
    } else {
        mv.anull();
    }
    mv.store(oldArguments);
    // (2) Update 'caller' and 'arguments' properties
    if (hasCaller) {
        setLegacyCaller(function, callerContext, mv);
    }
    if (hasArguments) {
        setLegacyArguments(function, arguments, mv);
    }
    TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
    TryCatchLabel handlerFinally = new TryCatchLabel();
    mv.mark(startFinally);
    {
        // (3) Create this-argument
        ordinaryCreateFromConstructor(callerContext, newTarget, thisArg, mv);
        // (4) Create a new ExecutionContext
        prepareCallAndBindThis(node, calleeContext, function, newTarget, thisArg, mv);
        // (5) Call OrdinaryCallEvaluateBody
        ordinaryCallEvaluateBody(node, calleeContext, function, arguments, mv);
        // (6) Restore 'caller' and 'arguments'
        restoreLegacyProperties(function, oldCaller, oldArguments, mv);
        // (7) Return result value
        returnResultOrThis(thisArg, false, mv);
    }
    mv.mark(endFinally);
    // Exception: Restore 'caller' and 'arguments' and then rethrow exception
    mv.finallyHandler(handlerFinally);
    mv.store(throwable);
    restoreLegacyProperties(function, oldCaller, oldArguments, mv);
    mv.load(throwable);
    mv.athrow();
    mv.tryFinally(startFinally, endFinally, handlerFinally);
}
Also used : ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) Constructor(com.github.anba.es6draft.runtime.types.Constructor) TryCatchLabel(com.github.anba.es6draft.compiler.assembler.TryCatchLabel) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) LegacyConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.LegacyConstructorFunction)

Aggregations

ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)95 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)61 Realm (com.github.anba.es6draft.runtime.Realm)17 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)16 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)15 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)14 AbstractOperations (com.github.anba.es6draft.runtime.AbstractOperations)11 Declaration (com.github.anba.es6draft.ast.Declaration)10 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)10 Name (com.github.anba.es6draft.ast.scope.Name)10 Callable (com.github.anba.es6draft.runtime.types.Callable)10 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)10 HashSet (java.util.HashSet)10 StatementListItem (com.github.anba.es6draft.ast.StatementListItem)9 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)9 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)8 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)8 ScriptException (com.github.anba.es6draft.runtime.internal.ScriptException)8 ArrayDeque (java.util.ArrayDeque)8 FunctionDeclaration (com.github.anba.es6draft.ast.FunctionDeclaration)7