Skip to content

Commit

Permalink
Fix #1459
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed May 25, 2019
1 parent a518f18 commit 420cf4e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/promise.js
Expand Up @@ -489,6 +489,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {

if (shouldBind) this._propagateFrom(maybePromise, PROPAGATE_BIND);


var promise = maybePromise._target();

if (promise === this) {
Expand All @@ -505,7 +506,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {
}
this._setFollowing();
this._setLength(0);
this._setFollowee(promise);
this._setFollowee(maybePromise);
} else if (BIT_FIELD_CHECK(IS_FULFILLED)) {
this._fulfill(promise._value());
} else if (BIT_FIELD_CHECK(IS_REJECTED)) {
Expand Down
29 changes: 29 additions & 0 deletions test/mocha/cancel.js
Expand Up @@ -281,6 +281,35 @@ describe("Cancellation", function() {
});
});

specify("cancels the followee, calling all onCancel callbacks", function() {
var called = 0;

var promise = new Promise(function(_, __, onCancel) {
onCancel(function() {
called++;
});
})

var promise2 = new Promise(function(resolve, reject, onCancel) {
resolve(promise);
onCancel(function() {
called++;
});
});

var promise3 = new Promise(function(resolve, reject, onCancel) {
resolve(promise2);
onCancel(function() {
called++;
});
});

promise3.cancel();
return awaitLateQueue(function() {
assert.equal(3, called);
});
});

specify("can be used for breaking chains early", function() {
var called = false;
var p = Promise.resolve(1)
Expand Down
18 changes: 16 additions & 2 deletions tools/test.js
Expand Up @@ -18,7 +18,8 @@ jobRunner.setVerbose(0);
// Random slowness after tests complete
function getTests(options) {
var g;
if (options.testName === "all") {

if (options.testName === "all" || options.testName.indexOf("no") === 0) {
g = "./test/mocha/*.js";
} else if (options.testName === "aplus") {
g = "./test/mocha/[0-9].[0-9].[0-9].js";
Expand All @@ -28,11 +29,24 @@ function getTests(options) {
var testName = options.testName.replace(/^(\d)(\d)(\d)$/, "$1.$2.$3");
g = "./test/mocha/" + testName + ".js";
}

var excludes = [];
if (options.testName.indexOf("no") === 0) {
excludes = options.testName.slice(2).split(",");
}

return glob(g).then(function(matches) {
return matches.filter(function(match) {
if (match.indexOf("generator") >= 0) {
return options.generators;
}

for (var i = 0; i < excludes.length; ++i) {
if (match.indexOf(excludes[i]) >= 0) {
return false;
}
}

return true;
})
}).tap(function(m) {
Expand Down Expand Up @@ -144,7 +158,7 @@ if ("run" in argv) {
if (testName.indexOf("*") === -1) {
testName = testName.toLowerCase()
.replace( /\.js$/, "" )
.replace( /[^a-zA-Z0-9_\-.]/g, "" );
.replace( /[^,a-zA-Z0-9_\-.]/g, "" );
}
}

Expand Down

0 comments on commit 420cf4e

Please sign in to comment.