process: refactor unhandledRejection logic

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

PR-URL: https://github.com/nodejs/node/pull/28540
Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
cjihrig authored and Michaël Zasso committed 2019-07-20 11:05:21 +02:00
1 parent e2adfb79b0
commit 4cb0fc3ab1
2 files changed
+14 -4

No files matched your search

+6 -4
View File
@@ -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());