diff --git a/src/builtins/builtins-promise.cc b/src/builtins/builtins-promise.cc index d07598661e..564fbaf54c 100644 --- a/src/builtins/builtins-promise.cc +++ b/src/builtins/builtins-promise.cc @@ -685,8 +685,8 @@ void PromiseBuiltinsAssembler::InternalResolvePromise(Node* context, Bind(&if_fulfilled); { - CallRuntime(Runtime::kPromiseFulfill, context, promise, - SmiConstant(v8::Promise::kFulfilled), thenable_value); + PromiseFulfill(context, promise, thenable_value, + v8::Promise::kFulfilled); PromiseSetHasHandler(promise); Goto(&out); } @@ -757,8 +757,7 @@ void PromiseBuiltinsAssembler::InternalResolvePromise(Node* context, // 7.b Return FulfillPromise(promise, resolution). Bind(&fulfill); { - CallRuntime(Runtime::kPromiseFulfill, context, promise, - SmiConstant(v8::Promise::kFulfilled), result); + PromiseFulfill(context, promise, result, v8::Promise::kFulfilled); Goto(&out); } @@ -785,6 +784,50 @@ void PromiseBuiltinsAssembler::InternalResolvePromise(Node* context, Bind(&out); } +void PromiseBuiltinsAssembler::PromiseFulfill( + Node* context, Node* promise, Node* result, + v8::Promise::PromiseState status) { + Label do_promisereset(this); + + Node* const status_smi = SmiConstant(static_cast(status)); + Node* const deferred_promise = + LoadObjectField(promise, JSPromise::kDeferredPromiseOffset); + + GotoIf(IsUndefined(deferred_promise), &do_promisereset); + + Node* const tasks = + status == v8::Promise::kFulfilled + ? LoadObjectField(promise, JSPromise::kFulfillReactionsOffset) + : LoadObjectField(promise, JSPromise::kRejectReactionsOffset); + + Node* const deferred_on_resolve = + LoadObjectField(promise, JSPromise::kDeferredOnResolveOffset); + Node* const deferred_on_reject = + LoadObjectField(promise, JSPromise::kDeferredOnRejectOffset); + + Node* const info = AllocatePromiseReactionJobInfo( + promise, result, tasks, deferred_promise, deferred_on_resolve, + deferred_on_reject, context); + CallRuntime(Runtime::kEnqueuePromiseReactionJob, context, info, status_smi); + Goto(&do_promisereset); + + Bind(&do_promisereset); + { + StoreObjectField(promise, JSPromise::kStatusOffset, status_smi); + StoreObjectField(promise, JSPromise::kResultOffset, result); + StoreObjectFieldRoot(promise, JSPromise::kDeferredPromiseOffset, + Heap::kUndefinedValueRootIndex); + StoreObjectFieldRoot(promise, JSPromise::kDeferredOnResolveOffset, + Heap::kUndefinedValueRootIndex); + StoreObjectFieldRoot(promise, JSPromise::kDeferredOnRejectOffset, + Heap::kUndefinedValueRootIndex); + StoreObjectFieldRoot(promise, JSPromise::kFulfillReactionsOffset, + Heap::kUndefinedValueRootIndex); + StoreObjectFieldRoot(promise, JSPromise::kRejectReactionsOffset, + Heap::kUndefinedValueRootIndex); + } +} + // ES#sec-promise-reject-functions // Promise Reject Functions BUILTIN(PromiseRejectClosure) { diff --git a/src/builtins/builtins-promise.h b/src/builtins/builtins-promise.h index eea91ab5c4..7bc53ac2ba 100644 --- a/src/builtins/builtins-promise.h +++ b/src/builtins/builtins-promise.h @@ -67,6 +67,9 @@ class PromiseBuiltinsAssembler : public CodeStubAssembler { Node* CreatePromiseGetCapabilitiesExecutorContext(Node* native_context, Node* promise_capability); + void PromiseFulfill(Node* context, Node* promise, Node* result, + v8::Promise::PromiseState status); + Node* NewPromiseCapability(Node* context, Node* constructor, Node* debug_event = nullptr); diff --git a/src/runtime/runtime-promise.cc b/src/runtime/runtime-promise.cc index d0550a048d..9818408d88 100644 --- a/src/runtime/runtime-promise.cc +++ b/src/runtime/runtime-promise.cc @@ -184,16 +184,6 @@ RUNTIME_FUNCTION(Runtime_PromiseReject) { return isolate->heap()->undefined_value(); } -RUNTIME_FUNCTION(Runtime_PromiseFulfill) { - DCHECK(args.length() == 3); - HandleScope scope(isolate); - CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); - CONVERT_SMI_ARG_CHECKED(status, 1); - CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); - PromiseFulfill(isolate, promise, status, value); - return isolate->heap()->undefined_value(); -} - RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { HandleScope scope(isolate); DCHECK(args.length() == 2); diff --git a/src/runtime/runtime.h b/src/runtime/runtime.h index 01c4200261..9d92ceb7ad 100644 --- a/src/runtime/runtime.h +++ b/src/runtime/runtime.h @@ -306,7 +306,6 @@ namespace internal { F(NewTypeError, 2, 1) \ F(OrdinaryHasInstance, 2, 1) \ F(PromiseReject, 3, 1) \ - F(PromiseFulfill, 3, 1) \ F(PromiseHookInit, 2, 1) \ F(PromiseHookResolve, 1, 1) \ F(PromiseHookBefore, 1, 1) \