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

[promises] move most of FulfillPromise to c++

This causes a 3.1% regression because we unconditionally call out to a
runtime function.

This patch refactors out most of EnqueuePromiseReactionJob
runtime function into a separate function.

BUG=v8:5343

Review-Url: https://codereview.chromium.org/2449053003
Cr-Commit-Position: refs/heads/master@{#40570}
parent 968caeb4
...@@ -143,11 +143,7 @@ function PromiseInit(promise) { ...@@ -143,11 +143,7 @@ function PromiseInit(promise) {
} }
function FulfillPromise(promise, status, value, promiseQueue) { function FulfillPromise(promise, status, value, promiseQueue) {
var tasks = GET_PRIVATE(promise, promiseQueue); %PromiseFulfill(promise, status, value, promiseQueue);
if (!IS_UNDEFINED(tasks)) {
var deferred = GET_PRIVATE(promise, promiseDeferredReactionSymbol);
%EnqueuePromiseReactionJob(value, tasks, deferred, status);
}
PromiseSet(promise, status, value); PromiseSet(promise, status, value);
} }
......
...@@ -572,18 +572,16 @@ RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) { ...@@ -572,18 +572,16 @@ RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
} }
} }
RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { namespace {
HandleScope scope(isolate); void EnqueuePromiseReactionJob(Isolate* isolate, Handle<Object> value,
DCHECK(args.length() == 4); Handle<Object> tasks, Handle<Object> deferred,
CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); Handle<Object> status) {
CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, status, 3);
Handle<Object> debug_id = isolate->factory()->undefined_value(); Handle<Object> debug_id = isolate->factory()->undefined_value();
Handle<Object> debug_name = isolate->factory()->undefined_value(); Handle<Object> debug_name = isolate->factory()->undefined_value();
if (isolate->debug()->is_active()) { if (isolate->debug()->is_active()) {
MaybeHandle<Object> maybe_result;
Handle<Object> argv[] = {deferred, status}; Handle<Object> argv[] = {deferred, status};
MaybeHandle<Object> maybe_result = Execution::TryCall( maybe_result = Execution::TryCall(
isolate, isolate->promise_debug_get_info(), isolate, isolate->promise_debug_get_info(),
isolate->factory()->undefined_value(), arraysize(argv), argv); isolate->factory()->undefined_value(), arraysize(argv), argv);
Handle<Object> result; Handle<Object> result;
...@@ -602,6 +600,33 @@ RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { ...@@ -602,6 +600,33 @@ RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
debug_id, debug_name, debug_id, debug_name,
isolate->native_context()); isolate->native_context());
isolate->EnqueueMicrotask(info); isolate->EnqueueMicrotask(info);
}
} // namespace
RUNTIME_FUNCTION(Runtime_PromiseFulfill) {
DCHECK(args.length() == 4);
HandleScope scope(isolate);
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, promise, 0);
CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
CONVERT_ARG_HANDLE_CHECKED(Symbol, reaction, 3);
Handle<Object> tasks = JSReceiver::GetDataProperty(promise, reaction);
if (!tasks->IsUndefined(isolate)) {
Handle<Object> deferred = JSReceiver::GetDataProperty(
promise, isolate->factory()->promise_deferred_reaction_symbol());
EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
}
return isolate->heap()->undefined_value();
}
RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
HandleScope scope(isolate);
DCHECK(args.length() == 4);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2);
CONVERT_ARG_HANDLE_CHECKED(Object, status, 3);
EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
return isolate->heap()->undefined_value(); return isolate->heap()->undefined_value();
} }
......
...@@ -304,6 +304,7 @@ namespace internal { ...@@ -304,6 +304,7 @@ namespace internal {
F(NewSyntaxError, 2, 1) \ F(NewSyntaxError, 2, 1) \
F(NewTypeError, 2, 1) \ F(NewTypeError, 2, 1) \
F(OrdinaryHasInstance, 2, 1) \ F(OrdinaryHasInstance, 2, 1) \
F(PromiseFulfill, 4, 1) \
F(PromiseRejectEvent, 3, 1) \ F(PromiseRejectEvent, 3, 1) \
F(PromiseRejectEventFromStack, 2, 1) \ F(PromiseRejectEventFromStack, 2, 1) \
F(PromiseRevokeReject, 1, 1) \ F(PromiseRevokeReject, 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