Skip to content

Commit 4cb0fc3

Browse files
cjihrigtargos
authored andcommitted
process: refactor unhandledRejection logic
This commit prevents a deprecation warning from being emitted if the unhandledRejection event was actually handled. PR-URL: #28540Fixes: #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>
1 parent e2adfb7 commit 4cb0fc3

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎lib/internal/process/promises.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ function processPromiseRejections() {
199199
}
200200
casekDefaultUnhandledRejections: {
201201
consthandled=process.emit('unhandledRejection',reason,promise);
202-
if(!handled)emitUnhandledRejectionWarning(uid,reason);
203-
if(!deprecationWarned){
204-
emitDeprecationWarning();
205-
deprecationWarned=true;
202+
if(!handled){
203+
emitUnhandledRejectionWarning(uid,reason);
204+
if(!deprecationWarned){
205+
emitDeprecationWarning();
206+
deprecationWarned=true;
207+
}
206208
}
207209
break;
208210
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
4+
// This test verifies that DEP0018 does not occur when rejections are handled.
5+
common.disableCrashOnUnhandledRejection();
6+
process.on('warning',common.mustNotCall());
7+
process.on('unhandledRejection',common.mustCall());
8+
Promise.reject(newError());

0 commit comments

Comments
 (0)