Skip to content
Permalink
Browse files

process: refactor unhandledRejection logic

This commit prevents a deprecation warning from being emitted
if the unhandledRejection event was actually handled.

PR-URL: #28540
Fixes: #28539
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
cjihrig authored and targos committed Jul 4, 2019
1 parent e2adfb7 commit 4cb0fc3ab150f3f60e6d100ee7dd83b60c1885db
Showing with 14 additions and 4 deletions.
  1. +6 −4 lib/internal/process/promises.js
  2. +8 −0 test/parallel/test-promise-handled-rejection-no-warning.js
@@ -199,10 +199,12 @@ function processPromiseRejections() {
}
case kDefaultUnhandledRejections: {
const handled = process.emit('unhandledRejection', reason, promise);
if (!handled) emitUnhandledRejectionWarning(uid, reason);
if (!deprecationWarned) {
emitDeprecationWarning();
deprecationWarned = true;
if (!handled) {
emitUnhandledRejectionWarning(uid, reason);
if (!deprecationWarned) {
emitDeprecationWarning();
deprecationWarned = true;
}
}
break;
}
@@ -0,0 +1,8 @@
'use strict';
const common = require('../common');

// This test verifies that DEP0018 does not occur when rejections are handled.
common.disableCrashOnUnhandledRejection();
process.on('warning', common.mustNotCall());
process.on('unhandledRejection', common.mustCall());
Promise.reject(new Error());

0 comments on commit 4cb0fc3

Please sign in to comment.
You can’t perform that action at this time.