Skip to content

Commit

Permalink
Fixes #1006
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Feb 13, 2016
1 parent e9f8502 commit ffcad46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/finally.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function PassThroughHandlerContext(promise, type, handler) {
this.cancelPromise = null;
}

PassThroughHandlerContext.prototype.isFinallyHandler = function() {
return this.type === FINALLY_TYPE;
};

function FinallyHandlerCancelReaction(finallyHandler) {
this.finallyHandler = finallyHandler;
}
Expand Down Expand Up @@ -47,7 +51,7 @@ function finallyHandler(reasonOrValue) {

if (!this.called) {
this.called = true;
var ret = this.type === FINALLY_TYPE
var ret = this.isFinallyHandler()
? handler.call(promise._boundValue())
: handler.call(promise._boundValue(), reasonOrValue);
if (ret !== undefined) {
Expand Down
3 changes: 2 additions & 1 deletion src/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ Promise.prototype._settlePromise = function(promise, handler, receiver, value) {
if (BIT_FIELD_CHECK(IS_CANCELLED)) {
if (isPromise) promise._invokeInternalOnCancel();

if (receiver instanceof PassThroughHandlerContext) {
if (receiver instanceof PassThroughHandlerContext &&
receiver.isFinallyHandler()) {
receiver.cancelPromise = promise;
if (tryCatch(handler).call(receiver, value) === errorObj) {
promise._reject(errorObj.e);
Expand Down
6 changes: 6 additions & 0 deletions test/mocha/regress.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ describe("regressions", function() {
});
});

specify("gh-1006", function() {
return Promise.resolve().then(function() {
new Promise(function() {}).tap(function() {}).cancel();
});
});

if (testUtils.isNodeJS) {
describe("github-689", function() {
var originalProperty = Object.getOwnPropertyDescriptor(process, "domain");
Expand Down

0 comments on commit ffcad46

Please sign in to comment.