Commit a18de9cf authored by gsathya's avatar gsathya Committed by Commit bot

[promises] Move PromiseFulfill to TF

BUG=v8:5343

Review-Url: https://codereview.chromium.org/2614603003
Cr-Commit-Position: refs/heads/master@{#42073}
parent 3e20d381
......@@ -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<int>(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) {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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) \
......
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