summaryrefslogtreecommitdiff
path: root/deps/v8/src/builtins/builtins-async-function-gen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/src/builtins/builtins-async-function-gen.cc')
-rw-r--r--deps/v8/src/builtins/builtins-async-function-gen.cc71
1 files changed, 19 insertions, 52 deletions
diff --git a/deps/v8/src/builtins/builtins-async-function-gen.cc b/deps/v8/src/builtins/builtins-async-function-gen.cc
index 1373e66397..66b3e432f8 100644
--- a/deps/v8/src/builtins/builtins-async-function-gen.cc
+++ b/deps/v8/src/builtins/builtins-async-function-gen.cc
@@ -46,7 +46,7 @@ void AsyncFunctionBuiltinsAssembler::AsyncFunctionAwaitResumeClosure(
{
TNode<JSPromise> promise = LoadObjectField<JSPromise>(
async_function_object, JSAsyncFunctionObject::kPromiseOffset);
- CallRuntime(Runtime::kDebugAsyncFunctionResumed, context, promise);
+ CallRuntime(Runtime::kDebugPushPromise, context, promise);
Goto(&if_instrumentation_done);
}
BIND(&if_instrumentation_done);
@@ -103,21 +103,10 @@ TF_BUILTIN(AsyncFunctionEnter, AsyncFunctionBuiltinsAssembler) {
RootIndex::kUndefinedValue);
// Allocate and initialize the promise.
- TNode<NativeContext> native_context = LoadNativeContext(context);
- TNode<JSFunction> promise_function =
- CAST(LoadContextElement(native_context, Context::PROMISE_FUNCTION_INDEX));
- TNode<Map> promise_map = LoadObjectField<Map>(
- promise_function, JSFunction::kPrototypeOrInitialMapOffset);
- TNode<JSPromise> promise = UncheckedCast<JSPromise>(
- AllocateInNewSpace(JSPromise::kSizeWithEmbedderFields));
- StoreMapNoWriteBarrier(promise, promise_map);
- StoreObjectFieldRoot(promise, JSPromise::kPropertiesOrHashOffset,
- RootIndex::kEmptyFixedArray);
- StoreObjectFieldRoot(promise, JSPromise::kElementsOffset,
- RootIndex::kEmptyFixedArray);
- PromiseInit(promise);
+ TNode<JSPromise> promise = NewJSPromise(context);
// Allocate and initialize the async function object.
+ TNode<NativeContext> native_context = LoadNativeContext(context);
TNode<Map> async_function_object_map = CAST(LoadContextElement(
native_context, Context::ASYNC_FUNCTION_OBJECT_MAP_INDEX));
TNode<JSAsyncFunctionObject> async_function_object =
@@ -152,22 +141,15 @@ TF_BUILTIN(AsyncFunctionEnter, AsyncFunctionBuiltinsAssembler) {
StoreObjectFieldNoWriteBarrier(
async_function_object, JSAsyncFunctionObject::kPromiseOffset, promise);
- RunContextPromiseHookInit(context, promise, UndefinedConstant());
-
- // Fire promise hooks if enabled and push the Promise under construction
- // in an async function on the catch prediction stack to handle exceptions
- // thrown before the first await.
- Label if_instrumentation(this, Label::kDeferred),
- if_instrumentation_done(this);
- Branch(IsIsolatePromiseHookEnabledOrDebugIsActiveOrHasAsyncEventDelegate(),
- &if_instrumentation, &if_instrumentation_done);
- BIND(&if_instrumentation);
- {
- CallRuntime(Runtime::kDebugAsyncFunctionEntered, context, promise);
- Goto(&if_instrumentation_done);
- }
- BIND(&if_instrumentation_done);
+ // While we are executing an async function, we need to have the implicit
+ // promise on the stack to get the catch prediction right, even before we
+ // awaited for the first time.
+ Label if_debugging(this);
+ GotoIf(IsDebugActive(), &if_debugging);
+ Return(async_function_object);
+ BIND(&if_debugging);
+ CallRuntime(Runtime::kDebugPushPromise, context, promise);
Return(async_function_object);
}
@@ -175,7 +157,6 @@ TF_BUILTIN(AsyncFunctionReject, AsyncFunctionBuiltinsAssembler) {
auto async_function_object =
Parameter<JSAsyncFunctionObject>(Descriptor::kAsyncFunctionObject);
auto reason = Parameter<Object>(Descriptor::kReason);
- auto can_suspend = Parameter<Oddball>(Descriptor::kCanSuspend);
auto context = Parameter<Context>(Descriptor::kContext);
TNode<JSPromise> promise = LoadObjectField<JSPromise>(
async_function_object, JSAsyncFunctionObject::kPromiseOffset);
@@ -186,35 +167,32 @@ TF_BUILTIN(AsyncFunctionReject, AsyncFunctionBuiltinsAssembler) {
CallBuiltin(Builtin::kRejectPromise, context, promise, reason,
FalseConstant());
- Label if_debugging(this, Label::kDeferred);
- GotoIf(HasAsyncEventDelegate(), &if_debugging);
+ Label if_debugging(this);
GotoIf(IsDebugActive(), &if_debugging);
Return(promise);
BIND(&if_debugging);
- TailCallRuntime(Runtime::kDebugAsyncFunctionFinished, context, can_suspend,
- promise);
+ CallRuntime(Runtime::kDebugPopPromise, context);
+ Return(promise);
}
TF_BUILTIN(AsyncFunctionResolve, AsyncFunctionBuiltinsAssembler) {
auto async_function_object =
Parameter<JSAsyncFunctionObject>(Descriptor::kAsyncFunctionObject);
auto value = Parameter<Object>(Descriptor::kValue);
- auto can_suspend = Parameter<Oddball>(Descriptor::kCanSuspend);
auto context = Parameter<Context>(Descriptor::kContext);
TNode<JSPromise> promise = LoadObjectField<JSPromise>(
async_function_object, JSAsyncFunctionObject::kPromiseOffset);
CallBuiltin(Builtin::kResolvePromise, context, promise, value);
- Label if_debugging(this, Label::kDeferred);
- GotoIf(HasAsyncEventDelegate(), &if_debugging);
+ Label if_debugging(this);
GotoIf(IsDebugActive(), &if_debugging);
Return(promise);
BIND(&if_debugging);
- TailCallRuntime(Runtime::kDebugAsyncFunctionFinished, context, can_suspend,
- promise);
+ CallRuntime(Runtime::kDebugPopPromise, context);
+ Return(promise);
}
// AsyncFunctionReject and AsyncFunctionResolve are both required to return
@@ -260,29 +238,18 @@ void AsyncFunctionBuiltinsAssembler::AsyncFunctionAwait(
auto value = Parameter<Object>(Descriptor::kValue);
auto context = Parameter<Context>(Descriptor::kContext);
- TNode<JSPromise> outer_promise = LoadObjectField<JSPromise>(
- async_function_object, JSAsyncFunctionObject::kPromiseOffset);
-
- Label after_debug_hook(this), call_debug_hook(this, Label::kDeferred);
- GotoIf(HasAsyncEventDelegate(), &call_debug_hook);
- GotoIf(IsDebugActive(), &call_debug_hook);
- Goto(&after_debug_hook);
- BIND(&after_debug_hook);
-
TNode<SharedFunctionInfo> on_resolve_sfi =
AsyncFunctionAwaitResolveSharedFunConstant();
TNode<SharedFunctionInfo> on_reject_sfi =
AsyncFunctionAwaitRejectSharedFunConstant();
+ TNode<JSPromise> outer_promise = LoadObjectField<JSPromise>(
+ async_function_object, JSAsyncFunctionObject::kPromiseOffset);
Await(context, async_function_object, value, outer_promise, on_resolve_sfi,
on_reject_sfi, is_predicted_as_caught);
// Return outer promise to avoid adding an load of the outer promise before
// suspending in BytecodeGenerator.
Return(outer_promise);
-
- BIND(&call_debug_hook);
- CallRuntime(Runtime::kDebugAsyncFunctionSuspended, context, outer_promise);
- Goto(&after_debug_hook);
}
// Called by the parser from the desugaring of 'await' when catch