use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.
the class FunctionCodeGenerator method asyncFunctionCall.
/**
* Generate bytecode for:
*
* <pre>
* calleeContext = newFunctionExecutionContext(function, null, thisValue)
* function_init(calleeContext, function, arguments)
* return EvaluateBody(calleeContext, generator)
* </pre>
*
* @param codegen
* the code generator
* @param node
* the function node
* @param method
* the bytecode method
* @param function
* the script function
*/
static void asyncFunctionCall(CodeGenerator codegen, FunctionNode node, MethodCode method, FunctionCode function) {
callMethod(node, method, mv -> {
Variable<OrdinaryAsyncFunction> fn = mv.getFunction(OrdinaryAsyncFunction.class);
Variable<Object> thisValue = mv.getThisValue();
Variable<Object[]> arguments = mv.getArguments();
Variable<ExecutionContext> calleeContext = mv.newVariable("calleeContext", ExecutionContext.class);
// (1) Create a new ExecutionContext
prepareCallAndBindThis(node, calleeContext, fn, thisValue, mv);
// (2) Perform FunctionDeclarationInstantiation
{
TryCatchLabel startCatch = new TryCatchLabel();
TryCatchLabel endCatch = new TryCatchLabel(), handlerCatch = new TryCatchLabel();
Jump noException = new Jump();
mv.mark(startCatch);
functionDeclarationInstantiation(function.instantiation, calleeContext, fn, 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(fn);
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 FunctionOperations method EvaluateAsyncFunctionExpression.
/**
* 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 EvaluateAsyncFunctionExpression(RuntimeInfo.Function fd, ExecutionContext cx) {
OrdinaryAsyncFunction closure;
if (!fd.is(RuntimeInfo.FunctionFlags.ScopedName)) {
/* step 1 (not applicable) */
/* step 2 */
LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
/* step 3 */
closure = AsyncFunctionCreate(cx, FunctionKind.Normal, fd, scope);
} 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 = AsyncFunctionCreate(cx, FunctionKind.Normal, fd, funcEnv);
/* step 8 */
SetFunctionName(closure, name);
/* step 9 */
envRec.initializeBinding(name, closure);
}
/* step 4/10 */
return closure;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.
the class FunctionOperations method EvaluatePropertyDefinitionAsync.
/**
* Extension: Async Function Definitions
*
* @param object
* the script object
* @param propKey
* the property key
* @param cx
* the execution context
* @param fd
* the function runtime info object
* @return the async method
*/
public static OrdinaryAsyncFunction EvaluatePropertyDefinitionAsync(OrdinaryObject object, Object propKey, RuntimeInfo.Function fd, ExecutionContext cx) {
/* steps 1-2 (generated code) */
/* step 3 (not applicable) */
/* step 4 */
LexicalEnvironment<?> scope = cx.getLexicalEnvironment();
/* step 5 */
OrdinaryAsyncFunction closure = AsyncFunctionCreate(cx, FunctionKind.Method, fd, scope);
/* step 6 */
MakeMethod(closure, object);
/* step 7 */
SetFunctionName(closure, propKey);
/* steps 8-9 (generated code) */
return closure;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.
the class FunctionOperations method InstantiateAsyncFunctionObject.
/**
* Extension: Async Function Definitions
*
* @param scope
* the current lexical scope
* @param cx
* the execution context
* @param fd
* the function runtime info object
* @return the new async function instance
*/
public static OrdinaryAsyncFunction InstantiateAsyncFunctionObject(LexicalEnvironment<?> scope, ExecutionContext cx, RuntimeInfo.Function fd) {
/* step 1 (not applicable) */
/* step 2 */
String name = fd.functionName();
/* step 3 */
OrdinaryAsyncFunction f = AsyncFunctionCreate(cx, FunctionKind.Normal, fd, scope);
/* step 4 */
SetFunctionName(f, name);
/* step 5 */
return f;
}
use of com.github.anba.es6draft.runtime.types.builtins.OrdinaryAsyncFunction in project es6draft by anba.
the class FunctionConstructor method CreateDynamicFunction.
/**
* 19.2.1.1.1 RuntimeSemantics: CreateDynamicFunction(constructor, newTarget, kind, args)
*
* @param cx
* the execution context
* @param kind
* the function kind
* @param compiledFunction
* the compiled function
* @param proto
* the function prototype
* @return the new function object
*/
public static FunctionObject CreateDynamicFunction(ExecutionContext cx, SourceKind kind, CompiledFunction compiledFunction, ScriptObject proto) {
RuntimeInfo.Function function = compiledFunction.getFunction();
/* step 18 */
boolean strict = function.isStrict();
/* step 30 */
ObjectAllocator<? extends FunctionObject> allocator;
switch(kind) {
case AsyncFunction:
allocator = OrdinaryAsyncFunction::new;
break;
case AsyncGenerator:
allocator = OrdinaryAsyncGenerator::new;
break;
case Function:
if (function.is(RuntimeInfo.FunctionFlags.Legacy)) {
assert !strict;
allocator = LegacyConstructorFunction::new;
} else {
allocator = OrdinaryConstructorFunction::new;
}
break;
case Generator:
allocator = OrdinaryGenerator::new;
break;
default:
throw new AssertionError();
}
FunctionObject f = FunctionAllocate(cx, allocator, proto, strict, FunctionKind.Normal);
/* steps 31-32 */
LexicalEnvironment<GlobalEnvironmentRecord> scope = f.getRealm().getGlobalEnv();
/* step 33 */
FunctionInitialize(f, FunctionKind.Normal, function, scope, compiledFunction);
/* steps 34-36 */
switch(kind) {
case AsyncFunction:
/* step 36 */
break;
case AsyncGenerator:
{
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.AsyncGeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
break;
}
case Function:
/* step 35 */
if (f instanceof LegacyConstructorFunction) {
MakeConstructor(cx, (LegacyConstructorFunction) f);
} else {
MakeConstructor(cx, (OrdinaryConstructorFunction) f);
}
break;
case Generator:
{
/* step 34 */
OrdinaryObject prototype = ObjectCreate(cx, Intrinsics.GeneratorPrototype);
f.infallibleDefineOwnProperty("prototype", new Property(prototype, true, false, false));
break;
}
default:
throw new AssertionError();
}
/* step 37 */
SetFunctionName(f, "anonymous");
/* step 38 */
return f;
}
Aggregations