@@ -4,19 +4,13 @@ const { safeToString } = process.binding('util');
44
55const promiseRejectEvent = process . _promiseRejectEvent ;
66const hasBeenNotifiedProperty = new WeakMap ( ) ;
7- const promiseToGuidProperty = new WeakMap ( ) ;
87const pendingUnhandledRejections = [ ] ;
9- let lastPromiseId = 1 ;
108
119exports . setup = setupPromises ;
1210
13- function getAsynchronousRejectionWarningObject ( uid ) {
14- return new Error ( 'Promise rejection was handled ' +
15- `asynchronously (rejection id: ${ uid } )` ) ;
16- }
17-
1811function setupPromises ( scheduleMicrotasks ) {
1912 let deprecationWarned = false ;
13+ const promiseInternals = { } ;
2014
2115 process . _setupPromises ( function ( event , promise , reason ) {
2216 if ( event === promiseRejectEvent . unhandled )
@@ -25,34 +19,23 @@ function setupPromises(scheduleMicrotasks) {
2519 rejectionHandled ( promise ) ;
2620 else
2721 require ( 'assert' ) . fail ( null , null , 'unexpected PromiseRejectEvent' ) ;
28- } ) ;
22+ } , function getPromiseReason ( data ) {
23+ return data [ data . indexOf ( '[[PromiseValue]]' ) + 1 ] ;
24+ } , promiseInternals ) ;
2925
3026 function unhandledRejection ( promise , reason ) {
3127 hasBeenNotifiedProperty . set ( promise , false ) ;
32- promiseToGuidProperty . set ( promise , lastPromiseId ++ ) ;
3328 addPendingUnhandledRejection ( promise , reason ) ;
3429 }
3530
3631 function rejectionHandled ( promise ) {
3732 const hasBeenNotified = hasBeenNotifiedProperty . get ( promise ) ;
3833 if ( hasBeenNotified !== undefined ) {
3934 hasBeenNotifiedProperty . delete ( promise ) ;
40- const uid = promiseToGuidProperty . get ( promise ) ;
41- promiseToGuidProperty . delete ( promise ) ;
4235 if ( hasBeenNotified === true ) {
43- let warning = null ;
44- if ( ! process . listenerCount ( 'rejectionHandled' ) ) {
45- // Generate the warning object early to get a good stack trace.
46- warning = getAsynchronousRejectionWarningObject ( uid ) ;
47- }
36+ promiseInternals . untrackPromise ( promise ) ;
4837 process . nextTick ( function ( ) {
49- if ( ! process . emit ( 'rejectionHandled' , promise ) ) {
50- if ( warning === null )
51- warning = getAsynchronousRejectionWarningObject ( uid ) ;
52- warning . name = 'PromiseRejectionHandledWarning' ;
53- warning . id = uid ;
54- process . emitWarning ( warning ) ;
55- }
38+ process . emit ( 'rejectionHandled' , promise ) ;
5639 } ) ;
5740 }
5841
@@ -90,9 +73,8 @@ function setupPromises(scheduleMicrotasks) {
9073 const reason = pendingUnhandledRejections . shift ( ) ;
9174 if ( hasBeenNotifiedProperty . get ( promise ) === false ) {
9275 hasBeenNotifiedProperty . set ( promise , true ) ;
93- const uid = promiseToGuidProperty . get ( promise ) ;
9476 if ( ! process . emit ( 'unhandledRejection' , reason , promise ) ) {
95- emitWarning ( uid , reason ) ;
77+ promiseInternals . trackPromise ( promise ) ;
9678 } else {
9779 hadListeners = true ;
9880 }
0 commit comments