@@ -24,19 +24,29 @@ const getInfo = async function({
2424
2525// Retrieve promise's resolved/rejected state and value.
2626const parsePromise = async function ( { eventName, promise, value } ) {
27- // `uncaughtException` and `warning` events do not have `rejected`.
28- if ( promise === undefined ) {
27+ if ( NO_PROMISE_EVENTS . includes ( eventName ) ) {
2928 return { value }
3029 }
3130
32- // `unhandledRejection` should not use the following code because:
33- // - we already know `rejected` and `value`
34- // - using `try/catch` will fire `rejectionHandled`
35- if ( eventName === 'unhandledRejection ' ) {
36- return { rejected : true , value }
31+ const { rejected , value : valueA } = await getPromiseValue ( { promise } )
32+
33+ // `rejected` is always `true` with `rejectionHandled`, so we skip it
34+ if ( eventName === 'rejectionHandled ' ) {
35+ return { value : valueA }
3736 }
3837
39- // `rejectionHandled` and `multipleResolves` use `await promise`
38+ return { rejected, value : valueA }
39+ }
40+
41+ // Those events do not try to get the promise value.
42+ // For `uncaughtException` and `warning`, they are not promise-specific.
43+ // For `unhandledRejection`:
44+ // - we already know `rejected` and `value`
45+ // - using `try/catch` will fire `rejectionHandled`
46+ const NO_PROMISE_EVENTS = [ 'uncaughtException' , 'warning' , 'unhandledRejection' ]
47+
48+ // `rejectionHandled` and `multipleResolves` otherwise use `await promise`
49+ const getPromiseValue = async function ( { promise } ) {
4050 try {
4151 return { rejected : false , value : await promise }
4252 } catch ( error ) {
0 commit comments