Skip to content

Commit 420cf4e

Browse files
committedMay 25, 2019
Fix #1459
1 parent a518f18 commit 420cf4e

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed
 

‎src/promise.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {
489489

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

492+
492493
var promise = maybePromise._target();
493494

494495
if (promise === this) {
@@ -505,7 +506,7 @@ Promise.prototype._resolveCallback = function(value, shouldBind) {
505506
}
506507
this._setFollowing();
507508
this._setLength(0);
508-
this._setFollowee(promise);
509+
this._setFollowee(maybePromise);
509510
} else if (BIT_FIELD_CHECK(IS_FULFILLED)) {
510511
this._fulfill(promise._value());
511512
} else if (BIT_FIELD_CHECK(IS_REJECTED)) {

‎test/mocha/cancel.js

+29
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,35 @@ describe("Cancellation", function() {
281281
});
282282
});
283283

284+
specify("cancels the followee, calling all onCancel callbacks", function() {
285+
var called = 0;
286+
287+
var promise = new Promise(function(_, __, onCancel) {
288+
onCancel(function() {
289+
called++;
290+
});
291+
})
292+
293+
var promise2 = new Promise(function(resolve, reject, onCancel) {
294+
resolve(promise);
295+
onCancel(function() {
296+
called++;
297+
});
298+
});
299+
300+
var promise3 = new Promise(function(resolve, reject, onCancel) {
301+
resolve(promise2);
302+
onCancel(function() {
303+
called++;
304+
});
305+
});
306+
307+
promise3.cancel();
308+
return awaitLateQueue(function() {
309+
assert.equal(3, called);
310+
});
311+
});
312+
284313
specify("can be used for breaking chains early", function() {
285314
var called = false;
286315
var p = Promise.resolve(1)

‎tools/test.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobRunner.setVerbose(0);
1818
// Random slowness after tests complete
1919
function getTests(options) {
2020
var g;
21-
if (options.testName === "all") {
21+
22+
if (options.testName === "all" || options.testName.indexOf("no") === 0) {
2223
g = "./test/mocha/*.js";
2324
} else if (options.testName === "aplus") {
2425
g = "./test/mocha/[0-9].[0-9].[0-9].js";
@@ -28,11 +29,24 @@ function getTests(options) {
2829
var testName = options.testName.replace(/^(\d)(\d)(\d)$/, "$1.$2.$3");
2930
g = "./test/mocha/" + testName + ".js";
3031
}
32+
33+
var excludes = [];
34+
if (options.testName.indexOf("no") === 0) {
35+
excludes = options.testName.slice(2).split(",");
36+
}
37+
3138
return glob(g).then(function(matches) {
3239
return matches.filter(function(match) {
3340
if (match.indexOf("generator") >= 0) {
3441
return options.generators;
3542
}
43+
44+
for (var i = 0; i < excludes.length; ++i) {
45+
if (match.indexOf(excludes[i]) >= 0) {
46+
return false;
47+
}
48+
}
49+
3650
return true;
3751
})
3852
}).tap(function(m) {
@@ -144,7 +158,7 @@ if ("run" in argv) {
144158
if (testName.indexOf("*") === -1) {
145159
testName = testName.toLowerCase()
146160
.replace( /\.js$/, "" )
147-
.replace( /[^a-zA-Z0-9_\-.]/g, "" );
161+
.replace( /[^,a-zA-Z0-9_\-.]/g, "" );
148162
}
149163
}
150164

0 commit comments

Comments
 (0)
Please sign in to comment.