Skip to content

Commit a518f18

Browse files
committedMay 25, 2019
Fix #1487 #1489
1 parent c9618f0 commit a518f18

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
 

‎src/map.js

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ function MappingPromiseArray(promises, fn, limit, _filter) {
2323
this._inFlight = 0;
2424
this._queue = [];
2525
async.invoke(this._asyncInit, this, undefined);
26+
if (util.isArray(promises)) {
27+
for (var i = 0; i < promises.length; ++i) {
28+
var maybePromise = promises[i];
29+
if (maybePromise instanceof Promise) {
30+
maybePromise.suppressUnhandledRejections();
31+
}
32+
}
33+
}
2634
}
2735
util.inherits(MappingPromiseArray, PromiseArray);
2836

‎src/promise_array.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function PromiseArray(values) {
2121
var promise = this._promise = new Promise(INTERNAL);
2222
if (values instanceof Promise) {
2323
promise._propagateFrom(values, PROPAGATE_ALL);
24+
values.suppressUnhandledRejections();
2425
}
2526
promise._setOnCancel(this);
2627
this._values = values;

‎test/mocha/unhandled_rejections.js

+58
Original file line numberDiff line numberDiff line change
@@ -809,4 +809,62 @@ describe("issues", function () {
809809
Promise.reject(new Error("reason2"))).caught(function() {});
810810
return ret;
811811
});
812+
813+
specify("GH-1487-1", function testFunction() {
814+
var ret = onUnhandledFail(testFunction);
815+
var p = Promise.reject( new Error('foo') );
816+
Promise.map( p, function() {} ).caught( function() {} );
817+
return ret;
818+
});
819+
820+
specify("GH-1487-2", function testFunction() {
821+
var ret = onUnhandledFail(testFunction);
822+
var arr = [ Promise.reject( new Error('foo') ) ];
823+
Promise.map( arr, function() {} ).caught( function() {} );
824+
return ret;
825+
});
826+
827+
specify("GH-1487-3", function testFunction() {
828+
var ret = onUnhandledFail(testFunction);
829+
var p = Promise.reject( new Error('foo') );
830+
p.map( function() {} ).caught( function() {} );
831+
return ret;
832+
});
833+
834+
specify("GH-1487-4", function testFunction() {
835+
var ret = onUnhandledFail(testFunction);
836+
var arr = [ Promise.reject( new Error('foo') ) ];
837+
var p = Promise.resolve( arr );
838+
p.map( function() {} ).caught( function() {} );
839+
return ret;
840+
});
841+
842+
specify("GH-1487-5", function testFunction() {
843+
var ret = onUnhandledFail(testFunction);
844+
var p = Promise.reject( new Error('foo') );
845+
Promise.filter( p, function() {} ).caught( function() {} );
846+
return ret;
847+
});
848+
849+
specify("GH-1487-6", function testFunction() {
850+
var ret = onUnhandledFail(testFunction);
851+
var arr = [ Promise.reject( new Error('foo') ) ];
852+
Promise.filter( arr, function() {} ).caught( function() {} );
853+
return ret;
854+
});
855+
856+
specify("GH-1487-7", function testFunction() {
857+
var ret = onUnhandledFail(testFunction);
858+
var p = Promise.reject( new Error('foo') );
859+
p.filter( function() {} ).caught( function() {} );
860+
return ret;
861+
});
862+
863+
specify("GH-1487-8", function testFunction() {
864+
var ret = onUnhandledFail(testFunction);
865+
var arr = [ Promise.reject( new Error('foo') ) ];
866+
var p = Promise.resolve( arr );
867+
p.filter( function() {} ).caught( function() {} );
868+
return ret;
869+
});
812870
})

0 commit comments

Comments
 (0)
Please sign in to comment.