Commit 4dc97f4a authored by gsathya's avatar gsathya Committed by Commit bot

[promises] dont create resolving closures in PromiseThen

When we create native promises as part of PromiseThen, we don't have
to create resolving closures. The closure will only ever be called
once from PromiseHandle, therefore we don't need the alreadyResolved
check.

This results in a 21.76% improvement in the bluebird benchmark
over 5 runs.

BUG=v8:5046

Review-Url: https://codereview.chromium.org/2396763002
Cr-Commit-Position: refs/heads/master@{#40018}
parent 0c7e1bef
...@@ -169,9 +169,21 @@ function PromiseHandle(value, handler, deferred) { ...@@ -169,9 +169,21 @@ function PromiseHandle(value, handler, deferred) {
try { try {
if (debug_is_active) %DebugPushPromise(deferred.promise); if (debug_is_active) %DebugPushPromise(deferred.promise);
var result = handler(value); var result = handler(value);
deferred.resolve(result); if (IS_UNDEFINED(deferred.resolve)) {
ResolvePromise(deferred.promise, result);
} else {
deferred.resolve(result);
}
} %catch (exception) { // Natives syntax to mark this catch block. } %catch (exception) { // Natives syntax to mark this catch block.
try { deferred.reject(exception); } catch (e) { } try {
if (IS_UNDEFINED(deferred.reject)) {
// Pass false for debugEvent so .then chaining does not trigger
// redundant ExceptionEvents.
RejectPromise(deferred.promise, exception, false);
} else {
deferred.reject(exception);
}
} catch (e) { }
} finally { } finally {
if (debug_is_active) %DebugPopPromise(); if (debug_is_active) %DebugPopPromise();
} }
...@@ -452,9 +464,23 @@ function PromiseThen(onResolve, onReject) { ...@@ -452,9 +464,23 @@ function PromiseThen(onResolve, onReject) {
} }
var constructor = SpeciesConstructor(this, GlobalPromise); var constructor = SpeciesConstructor(this, GlobalPromise);
// Pass false for debugEvent so .then chaining does not trigger var resultCapability;
// redundant ExceptionEvents.
var resultCapability = NewPromiseCapability(constructor, false); // The resultCapability.promise is only ever fulfilled internally,
// so we don't need the closures to protect against accidentally
// calling them multiple times.
if (constructor === GlobalPromise) {
// TODO(gsathya): Combine this into NewPromiseCapability.
resultCapability = {
promise: PromiseCreate(),
resolve: UNDEFINED,
reject: UNDEFINED
};
} else {
// Pass false for debugEvent so .then chaining does not trigger
// redundant ExceptionEvents.
resultCapability = NewPromiseCapability(constructor, false);
}
return PerformPromiseThen(this, onResolve, onReject, resultCapability); return PerformPromiseThen(this, onResolve, onReject, resultCapability);
} }
......
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