Commit 8e826802 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[builtins] Simplify PromiseHandle a bit.

Refactor the PromiseHandle builtin and move the separate debug checks
into the PromiseHookBefore and PromiseHookAfter runtime calls, so they
are performed only when we've already hit the slow-path.

Bug: v8:7253
Change-Id: I01ab8592a474b6897280734b995cab0b90a5e010
Reviewed-on: https://chromium-review.googlesource.com/884583Reviewed-by: 's avatarSathya Gunasekaran <gsathya@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50856}
parent 26bc62e8
......@@ -1135,17 +1135,15 @@ TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) {
VARIABLE(var_reason, MachineRepresentation::kTagged);
Node* const is_debug_active = IsDebugActive();
Label run_handler(this), if_rejectpromise(this), promisehook_before(this),
promisehook_after(this), debug_pop(this);
Label run_handler(this), if_rejectpromise(this),
promisehook_before(this, Label::kDeferred),
promisehook_after(this, Label::kDeferred), done(this), out(this);
GotoIfNot(is_debug_active, &promisehook_before);
CallRuntime(Runtime::kDebugPushPromise, context, deferred_promise);
Goto(&promisehook_before);
Branch(IsPromiseHookEnabledOrDebugIsActive(), &promisehook_before,
&run_handler);
BIND(&promisehook_before);
{
GotoIfNot(IsPromiseHookEnabledOrDebugIsActive(), &run_handler);
CallRuntime(Runtime::kPromiseHookBefore, context, deferred_promise);
Goto(&run_handler);
}
......@@ -1191,7 +1189,7 @@ TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) {
BIND(&if_internalhandler);
InternalResolvePromise(context, deferred_promise, var_result.value());
Goto(&promisehook_after);
Goto(&done);
BIND(&if_customhandler);
{
......@@ -1200,7 +1198,7 @@ TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) {
context, deferred_on_resolve, UndefinedConstant(),
var_result.value());
GotoIfException(maybe_exception, &if_rejectpromise, &var_reason);
Goto(&promisehook_after);
Goto(&done);
}
}
......@@ -1208,23 +1206,18 @@ TF_BUILTIN(PromiseHandle, PromiseBuiltinsAssembler) {
{
CallBuiltin(Builtins::kPromiseHandleReject, context, deferred_promise,
deferred_on_reject, var_reason.value());
Goto(&promisehook_after);
}
BIND(&promisehook_after);
{
GotoIfNot(IsPromiseHookEnabledOrDebugIsActive(), &debug_pop);
CallRuntime(Runtime::kPromiseHookAfter, context, deferred_promise);
Goto(&debug_pop);
Goto(&done);
}
BIND(&debug_pop);
BIND(&done);
{
Label out(this);
Branch(IsPromiseHookEnabledOrDebugIsActive(), &promisehook_after, &out);
GotoIfNot(is_debug_active, &out);
CallRuntime(Runtime::kDebugPopPromise, context);
Goto(&out);
BIND(&promisehook_after);
{
CallRuntime(Runtime::kPromiseHookAfter, context, deferred_promise);
Goto(&out);
}
BIND(&out);
Return(UndefinedConstant());
......
......@@ -131,6 +131,7 @@ RUNTIME_FUNCTION(Runtime_PromiseHookBefore) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
if (isolate->debug()->is_active()) isolate->PushPromise(promise);
if (promise->IsJSPromise()) {
isolate->RunPromiseHook(PromiseHookType::kBefore,
Handle<JSPromise>::cast(promise),
......@@ -143,6 +144,7 @@ RUNTIME_FUNCTION(Runtime_PromiseHookAfter) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
if (isolate->debug()->is_active()) isolate->PopPromise();
if (promise->IsJSPromise()) {
isolate->RunPromiseHook(PromiseHookType::kAfter,
Handle<JSPromise>::cast(promise),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment