Skip to content

Commit

Permalink
Fix #1487 #1489
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed May 25, 2019
1 parent c9618f0 commit a518f18
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ function MappingPromiseArray(promises, fn, limit, _filter) {
this._inFlight = 0;
this._queue = [];
async.invoke(this._asyncInit, this, undefined);
if (util.isArray(promises)) {
for (var i = 0; i < promises.length; ++i) {
var maybePromise = promises[i];
if (maybePromise instanceof Promise) {
maybePromise.suppressUnhandledRejections();
}
}
}
}
util.inherits(MappingPromiseArray, PromiseArray);

Expand Down
1 change: 1 addition & 0 deletions src/promise_array.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function PromiseArray(values) {
var promise = this._promise = new Promise(INTERNAL);
if (values instanceof Promise) {
promise._propagateFrom(values, PROPAGATE_ALL);
values.suppressUnhandledRejections();
}
promise._setOnCancel(this);
this._values = values;
Expand Down
58 changes: 58 additions & 0 deletions test/mocha/unhandled_rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,62 @@ describe("issues", function () {
Promise.reject(new Error("reason2"))).caught(function() {});
return ret;
});

specify("GH-1487-1", function testFunction() {
var ret = onUnhandledFail(testFunction);
var p = Promise.reject( new Error('foo') );
Promise.map( p, function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-2", function testFunction() {
var ret = onUnhandledFail(testFunction);
var arr = [ Promise.reject( new Error('foo') ) ];
Promise.map( arr, function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-3", function testFunction() {
var ret = onUnhandledFail(testFunction);
var p = Promise.reject( new Error('foo') );
p.map( function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-4", function testFunction() {
var ret = onUnhandledFail(testFunction);
var arr = [ Promise.reject( new Error('foo') ) ];
var p = Promise.resolve( arr );
p.map( function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-5", function testFunction() {
var ret = onUnhandledFail(testFunction);
var p = Promise.reject( new Error('foo') );
Promise.filter( p, function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-6", function testFunction() {
var ret = onUnhandledFail(testFunction);
var arr = [ Promise.reject( new Error('foo') ) ];
Promise.filter( arr, function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-7", function testFunction() {
var ret = onUnhandledFail(testFunction);
var p = Promise.reject( new Error('foo') );
p.filter( function() {} ).caught( function() {} );
return ret;
});

specify("GH-1487-8", function testFunction() {
var ret = onUnhandledFail(testFunction);
var arr = [ Promise.reject( new Error('foo') ) ];
var p = Promise.resolve( arr );
p.filter( function() {} ).caught( function() {} );
return ret;
});
})

0 comments on commit a518f18

Please sign in to comment.