Skip to content

Commit

Permalink
Streamline common case in promiseReactionJob.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscott committed Dec 8, 2015
1 parent b342ed1 commit 93ff998
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,26 @@ var PROMISE_FULFILLED = 1;
var PROMISE_REJECTED = 2;

var promiseReactionJob = function(handler, promiseCapability, argument) {
var handlerException = false;
var handlerResult, f;
var handlerResult, resolve, reject;
if (handler === PROMISE_IDENTITY) {
handlerResult = argument;
} else if (handler === PROMISE_THROWER) {
handlerResult = argument;
handlerException = true;
reject = promiseCapability.reject;
reject(handlerResult);
return;
} else {
// Encapsulate try/catch here to avoid deoptimization.
handlerResult = tryCatch1(handler, argument);
if (handlerResult === errorObj) {
handlerResult = handlerResult.e;
handlerException = true;
reject = promiseCapability.reject;
reject(handlerResult);
return;
}
}
f = handlerException ? promiseCapability.reject : promiseCapability.resolve;
f(handlerResult);
resolve = promiseCapability.resolve;
resolve(handlerResult);
};

var triggerPromiseReaction = function(handler, capability, argument) {
Expand Down

0 comments on commit 93ff998

Please sign in to comment.