Search in sources :

Example 6 with OrdinaryAsyncFunction

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.

the class FunctionCodeGenerator method generateAsyncFunctionCall.

/**
     * Generate bytecode for:
     * 
     * <pre>
     * calleeContext = newFunctionExecutionContext(function, null, thisValue)
     * function_init(calleeContext, function, arguments)
     * return EvaluateBody(calleeContext, generator)
     * </pre>
     * 
     * @param node
     *            the function node
     * @param mv
     *            the instruction visitor
     */
private void generateAsyncFunctionCall(FunctionNode node, InstructionVisitor mv) {
    Variable<OrdinaryAsyncFunction> function = mv.getParameter(FUNCTION, OrdinaryAsyncFunction.class);
    Variable<Object> thisValue = mv.getParameter(THIS_VALUE, Object.class);
    Variable<Object[]> arguments = mv.getParameter(ARGUMENTS, Object[].class);
    Variable<ExecutionContext> calleeContext = mv.newVariable("calleeContext", ExecutionContext.class);
    // (1) Create a new ExecutionContext
    prepareCallAndBindThis(node, calleeContext, function, thisValue, mv);
    // (2) Perform FunctionDeclarationInstantiation
    {
        TryCatchLabel startCatch = new TryCatchLabel();
        TryCatchLabel endCatch = new TryCatchLabel(), handlerCatch = new TryCatchLabel();
        Jump noException = new Jump();
        mv.mark(startCatch);
        functionDeclarationInstantiation(node, calleeContext, function, arguments, mv);
        mv.goTo(noException);
        mv.mark(endCatch);
        mv.catchHandler(handlerCatch, Types.ScriptException);
        {
            // stack: [exception] -> [cx, exception]
            mv.load(calleeContext);
            mv.swap();
            // stack: [cx, exception] -> [promise]
            mv.invoke(Methods.PromiseAbstractOperations_PromiseOf);
            mv._return();
        }
        mv.mark(noException);
        mv.tryCatch(startCatch, endCatch, handlerCatch, Types.ScriptException);
    }
    // (3) Perform EvaluateBody
    mv.load(calleeContext);
    mv.load(function);
    mv.invoke(Methods.OrdinaryAsyncFunction_EvaluateBody);
    // (4) Return result value
    mv._return();
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) TryCatchLabel(com.github.anba.es6draft.compiler.assembler.TryCatchLabel) OrdinaryAsyncFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction) Jump(com.github.anba.es6draft.compiler.assembler.Jump)

Example 7 with OrdinaryAsyncFunction

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.

the class AsyncFunctionConstructor method CreateDynamicFunction.

/**
     * 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
     * 
     * @param callerContext
     *            the caller execution context
     * @param cx
     *            the execution context
     * @param newTarget
     *            the newTarget constructor function
     * @param args
     *            the function arguments
     * @return the new generator function object
     */
private static OrdinaryAsyncFunction CreateDynamicFunction(ExecutionContext callerContext, ExecutionContext cx, Constructor newTarget, Object... args) {
    /* step 1 (not applicable) */
    /* step 2 (not applicable) */
    /* step 3 */
    Intrinsics fallbackProto = Intrinsics.AsyncFunction;
    /* steps 4-10 */
    String[] sourceText = functionSourceText(cx, args);
    String parameters = sourceText[0], bodyText = sourceText[1];
    /* steps 11, 13-20 */
    Source source = functionSource(SourceKind.AsyncFunction, cx.getRealm(), callerContext);
    RuntimeInfo.Function function;
    try {
        ScriptLoader scriptLoader = cx.getRealm().getScriptLoader();
        function = scriptLoader.asyncFunction(source, parameters, bodyText).getFunction();
    } catch (ParserException | CompilationException e) {
        throw e.toScriptException(cx);
    }
    /* step 12 */
    boolean strict = function.isStrict();
    /* steps 21-22 */
    ScriptObject proto = GetPrototypeFromConstructor(cx, newTarget, fallbackProto);
    /* step 23 */
    OrdinaryAsyncFunction f = FunctionAllocate(cx, proto, strict, FunctionKind.Normal);
    /* steps 24-25 */
    LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
    /* step 26 */
    FunctionInitialize(f, FunctionKind.Normal, function, scope, newFunctionExecutable(source));
    /* steps 27-28 (not applicable) */
    /* step 29 */
    SetFunctionName(f, "anonymous");
    /* step 30 */
    return f;
}
Also used : ParserException(com.github.anba.es6draft.parser.ParserException) CompilationException(com.github.anba.es6draft.compiler.CompilationException) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) RuntimeInfo(com.github.anba.es6draft.runtime.internal.RuntimeInfo) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) FunctionConstructor.functionSource(com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource) Source(com.github.anba.es6draft.runtime.internal.Source) Intrinsics(com.github.anba.es6draft.runtime.types.Intrinsics) OrdinaryAsyncFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction) ScriptLoader(com.github.anba.es6draft.runtime.internal.ScriptLoader)

Example 8 with OrdinaryAsyncFunction

use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.

the class FunctionOperations method EvaluateAsyncArrowFunction.

/**
 * Extension: Async Function Definitions
 *
 * @param fd
 *            the function runtime info object
 * @param cx
 *            the execution context
 * @return the new async function instance
 */
public static OrdinaryAsyncFunction EvaluateAsyncArrowFunction(RuntimeInfo.Function fd, ExecutionContext cx) {
    /* step 1 (not applicable) */
    /* step 2 */
    LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
    /* steps 3-4/3-5 */
    OrdinaryAsyncFunction closure = AsyncFunctionCreate(cx, FunctionKind.Arrow, fd, scope);
    /* step 5/6 */
    return closure;
}
Also used : OrdinaryAsyncFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction)

Aggregations

OrdinaryAsyncFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction)8 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)3 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)2 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)2 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)2 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)2 RuntimeInfo (com.github.anba.es6draft.runtime.internal.RuntimeInfo)2 CompilationException (com.github.anba.es6draft.compiler.CompilationException)1 ParserException (com.github.anba.es6draft.parser.ParserException)1 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)1 ScriptLoader (com.github.anba.es6draft.runtime.internal.ScriptLoader)1 Source (com.github.anba.es6draft.runtime.internal.Source)1 FunctionConstructor.functionSource (com.github.anba.es6draft.runtime.objects.FunctionConstructor.functionSource)1 Intrinsics (com.github.anba.es6draft.runtime.types.Intrinsics)1 Property (com.github.anba.es6draft.runtime.types.Property)1 LegacyConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.LegacyConstructorFunction)1 OrdinaryAsyncGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncGenerator)1 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)1 OrdinaryGenerator (com.github.anba.es6draft.runtime.types.builtins.OrdinaryGenerator)1