diff --git a/src/map.js b/src/map.js index 7de61635f..793210dae 100644 --- a/src/map.js +++ b/src/map.js @@ -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); diff --git a/src/promise_array.js b/src/promise_array.js index 359a4249c..6256889dc 100644 --- a/src/promise_array.js +++ b/src/promise_array.js @@ -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; diff --git a/test/mocha/unhandled_rejections.js b/test/mocha/unhandled_rejections.js index 542788a20..672b7d009 100644 --- a/test/mocha/unhandled_rejections.js +++ b/test/mocha/unhandled_rejections.js @@ -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; + }); })