Index: src/builtins/builtins-promise.cc |
diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc |
index 935da633a511b888780600707fbbfdc4b77c5da2..417814e72acc569dc12a7c221cdd13f0d0794cce 100644 |
--- a/src/builtins/builtins-promise.cc |
+++ b/src/builtins/builtins-promise.cc |
@@ -748,8 +748,7 @@ void PromiseBuiltinsAssembler::InternalResolvePromise(Node* context, |
Bind(&reject); |
// Don't cause a debug event as this case is forwarding a rejection |
- CallRuntime(Runtime::kPromiseReject, context, promise, thenable_value, |
- FalseConstant()); |
+ InternalPromiseReject(context, promise, thenable_value, false); |
PromiseSetHasHandler(result); |
Goto(&out); |
} |
@@ -836,8 +835,7 @@ void PromiseBuiltinsAssembler::InternalResolvePromise(Node* context, |
// 9.a Return RejectPromise(promise, then.[[Value]]). |
Bind(&if_rejectpromise); |
{ |
- CallRuntime(Runtime::kPromiseReject, context, promise, var_reason.value(), |
- TrueConstant()); |
+ InternalPromiseReject(context, promise, var_reason.value(), true); |
Goto(&out); |
} |
@@ -943,6 +941,52 @@ void PromiseBuiltinsAssembler::BranchIfAccessCheckFailed( |
Bind(&has_access); |
} |
+void PromiseBuiltinsAssembler::InternalPromiseReject(Node* context, |
+ Node* promise, Node* value, |
+ Node* debug_event) { |
+ Label out(this); |
+ GotoUnless(IsDebugActive(), &out); |
+ GotoUnless(WordEqual(TrueConstant(), debug_event), &out); |
+ CallRuntime(Runtime::kDebugPromiseReject, context, promise, value); |
+ Goto(&out); |
+ |
+ Bind(&out); |
+ InternalPromiseReject(context, promise, value, false); |
+} |
+ |
+// This duplicates a lot of logic from PromiseRejectEvent in |
+// runtime-promise.cc |
+void PromiseBuiltinsAssembler::InternalPromiseReject(Node* context, |
+ Node* promise, Node* value, |
+ bool debug_event) { |
+ Label fulfill(this), report_unhandledpromise(this), run_promise_hook(this); |
+ |
+ if (debug_event) { |
+ GotoUnless(IsDebugActive(), &run_promise_hook); |
+ CallRuntime(Runtime::kDebugPromiseReject, context, promise, value); |
+ Goto(&run_promise_hook); |
+ } else { |
+ Goto(&run_promise_hook); |
+ } |
+ |
+ Bind(&run_promise_hook); |
+ { |
+ GotoUnless(IsPromiseHookEnabled(), &report_unhandledpromise); |
+ CallRuntime(Runtime::kPromiseHookResolve, context, promise); |
+ Goto(&report_unhandledpromise); |
+ } |
+ |
+ Bind(&report_unhandledpromise); |
+ { |
+ GotoIf(PromiseHasHandler(promise), &fulfill); |
+ CallRuntime(Runtime::kReportPromiseReject, context, promise, value); |
+ Goto(&fulfill); |
+ } |
+ |
+ Bind(&fulfill); |
+ PromiseFulfill(context, promise, value, v8::Promise::kRejected); |
+} |
+ |
// ES#sec-promise-reject-functions |
// Promise Reject Functions |
TF_BUILTIN(PromiseRejectClosure, PromiseBuiltinsAssembler) { |
@@ -970,7 +1014,7 @@ TF_BUILTIN(PromiseRejectClosure, PromiseBuiltinsAssembler) { |
Node* const debug_event = LoadContextElement( |
context, IntPtrConstant(PromiseUtils::kDebugEventSlot)); |
- CallRuntime(Runtime::kPromiseReject, context, promise, value, debug_event); |
+ InternalPromiseReject(context, promise, value, debug_event); |
Return(UndefinedConstant()); |
Bind(&out); |
@@ -1207,8 +1251,7 @@ TF_BUILTIN(PromiseHandleReject, PromiseBuiltinsAssembler) { |
Bind(&if_internalhandler); |
{ |
- CallRuntime(Runtime::kPromiseReject, context, promise, exception, |
- FalseConstant()); |
+ InternalPromiseReject(context, promise, exception, false); |
Return(UndefinedConstant()); |
} |
@@ -1504,5 +1547,15 @@ TF_BUILTIN(PromiseReject, PromiseBuiltinsAssembler) { |
} |
} |
+TF_BUILTIN(InternalPromiseReject, PromiseBuiltinsAssembler) { |
+ Node* const promise = Parameter(1); |
+ Node* const reason = Parameter(2); |
+ Node* const debug_event = Parameter(3); |
+ Node* const context = Parameter(6); |
+ |
+ InternalPromiseReject(context, promise, reason, debug_event); |
+ Return(UndefinedConstant()); |
+} |
+ |
} // namespace internal |
} // namespace v8 |