|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const { |
4 | | - ArrayPrototypePush, |
5 | | - ArrayPrototypeShift, |
6 | 4 | Error, |
7 | 5 | ObjectPrototypeHasOwnProperty, |
8 | 6 | SafeMap, |
9 | 7 | SafeWeakMap, |
10 | 8 | } = primordials; |
11 | 9 |
|
| 10 | +const FixedQueue = require('internal/fixed_queue'); |
| 11 | + |
12 | 12 | const { |
13 | 13 | tickInfo, |
14 | 14 | promiseRejectEvents: { |
@@ -119,9 +119,9 @@ const maybeUnhandledPromises = new SafeWeakMap(); |
119 | 119 | let pendingUnhandledRejections = new SafeMap(); |
120 | 120 |
|
121 | 121 | /** |
122 | | - * @type {Array<{promise: Promise, warning: Error}>} |
| 122 | + * @type {import('internal/fixed_queue')<{promise: Promise, warning: Error}>} |
123 | 123 | */ |
124 | | -const asyncHandledRejections = []; |
| 124 | +const asyncHandledRejections = new FixedQueue(); |
125 | 125 |
|
126 | 126 | /** |
127 | 127 | * @type {number} |
@@ -219,7 +219,7 @@ function handledRejection(promise) { |
219 | 219 | if (promiseInfo.warned) { |
220 | 220 | // Generate the warning object early to get a good stack trace. |
221 | 221 | const warning = new PromiseRejectionHandledWarning(promiseInfo.uid); |
222 | | - ArrayPrototypePush(asyncHandledRejections, { promise, warning }); |
| 222 | + asyncHandledRejections.push({ promise, warning }); |
223 | 223 | setHasRejectionToWarn(true); |
224 | 224 | } |
225 | 225 | } |
@@ -375,10 +375,10 @@ function getUnhandledRejectionsMode() { |
375 | 375 | // a warning to be emitted which requires the microtask and next tick |
376 | 376 | // queues to be drained again. |
377 | 377 | function processPromiseRejections() { |
378 | | - let maybeScheduledTicksOrMicrotasks = asyncHandledRejections.length > 0; |
| 378 | + let maybeScheduledTicksOrMicrotasks = !asyncHandledRejections.isEmpty(); |
379 | 379 |
|
380 | | - while (asyncHandledRejections.length !== 0) { |
381 | | - const { promise, warning } = ArrayPrototypeShift(asyncHandledRejections); |
| 380 | + while (!asyncHandledRejections.isEmpty()) { |
| 381 | + const { promise, warning } = asyncHandledRejections.shift(); |
382 | 382 | if (!process.emit('rejectionHandled', promise)) { |
383 | 383 | process.emitWarning(warning); |
384 | 384 | } |
|
0 commit comments