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) {
try {
if (debug_is_active) %DebugPushPromise(deferred.promise);
var result = handler(value);
if (IS_UNDEFINED(deferred.resolve)) {
ResolvePromise(deferred.promise, result);
} else {
deferred.resolve(result);
}
} %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 {
if (debug_is_active) %DebugPopPromise();
}
......@@ -452,9 +464,23 @@ function PromiseThen(onResolve, onReject) {
}
var constructor = SpeciesConstructor(this, GlobalPromise);
var resultCapability;
// 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.
var resultCapability = NewPromiseCapability(constructor, false);
resultCapability = NewPromiseCapability(constructor, false);
}
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