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();
}
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;
}
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;
}
Aggregations