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:
parent
327c6734cb
commit
7cf6f9e964
@ -199,10 +199,12 @@ function processPromiseRejections() {
|
|||||||
}
|
}
|
||||||
case kDefaultUnhandledRejections: {
|
case kDefaultUnhandledRejections: {
|
||||||
const handled = process.emit('unhandledRejection', reason, promise);
|
const handled = process.emit('unhandledRejection', reason, promise);
|
||||||
if (!handled) emitUnhandledRejectionWarning(uid, reason);
|
if (!handled) {
|
||||||
if (!deprecationWarned) {
|
emitUnhandledRejectionWarning(uid, reason);
|
||||||
emitDeprecationWarning();
|
if (!deprecationWarned) {
|
||||||
deprecationWarned = true;
|
emitDeprecationWarning();
|
||||||
|
deprecationWarned = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
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());
|
Loading…
x
Reference in New Issue
Block a user