Skip to content

Commit

Permalink
Fixes #1404
Browse files Browse the repository at this point in the history
  • Loading branch information
petkaantonov committed Oct 4, 2017
1 parent 3c93a91 commit 48c8591
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/debuggability.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ Promise.prototype.suppressUnhandledRejections = function() {
Promise.prototype._ensurePossibleRejectionHandled = function () {
if ((this._bitField & IS_REJECTION_IGNORED) !== 0) return;
this._setRejectionIsUnhandled();
async.invokeLater(this._notifyUnhandledRejection, this, undefined);
var self = this;
setTimeout(function() {
self._notifyUnhandledRejection();
}, 1);
};

Promise.prototype._notifyUnhandledRejectionIsHandled = function () {
Expand Down
22 changes: 22 additions & 0 deletions test/mocha/unhandled_rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,25 @@ describe("Unhandled rejection when joining chains with common rejected parent",
return Promise.all([test1, test2]);
});
});

var asyncAwaitSupported = (function() {
try {
new Function("async function abc() {}");
return true;
} catch (e) {
return false;
}
})();

if (asyncAwaitSupported) {
describe("No unhandled rejection from async await", function () {
setupCleanUps();
specify("gh-1404", function testFunction() {
var ret = onUnhandledFail(testFunction);
Promise.using(Promise.resolve(),
(new Function("Bluebird", "return async function() { await Bluebird.reject(new Error('foo')); }"))(Promise))
.caught(function() {});
return ret;
});
});
}

0 comments on commit 48c8591

Please sign in to comment.