|
3 | 3 | const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; |
4 | 4 | const { AsyncResource } = require('async_hooks'); |
5 | 5 | const { getDefaultTriggerAsyncId } = require('internal/async_hooks'); |
6 | | -const { enqueueMicrotask } = internalBinding('util'); |
| 6 | +const { |
| 7 | + enqueueMicrotask, |
| 8 | + triggerFatalException |
| 9 | +} = internalBinding('util'); |
7 | 10 |
|
8 | | -const setupQueueMicrotask = (triggerFatalException) => { |
9 | | - const queueMicrotask = (callback) => { |
10 | | - if (typeof callback !== 'function') { |
11 | | - throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback); |
12 | | - } |
| 11 | +function queueMicrotask(callback) { |
| 12 | + if (typeof callback !== 'function') { |
| 13 | + throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback); |
| 14 | + } |
13 | 15 |
|
14 | | - const asyncResource = new AsyncResource('Microtask', { |
15 | | - triggerAsyncId: getDefaultTriggerAsyncId(), |
16 | | - requireManualDestroy: true, |
17 | | - }); |
| 16 | + const asyncResource = new AsyncResource('Microtask', { |
| 17 | + triggerAsyncId: getDefaultTriggerAsyncId(), |
| 18 | + requireManualDestroy: true, |
| 19 | + }); |
18 | 20 |
|
19 | | - enqueueMicrotask(() => { |
20 | | - asyncResource.runInAsyncScope(() => { |
21 | | - try { |
22 | | - callback(); |
23 | | - } catch (error) { |
24 | | - // TODO(devsnek) remove this if |
25 | | - // https://bugs.chromium.org/p/v8/issues/detail?id=8326 |
26 | | - // is resolved such that V8 triggers the fatal exception |
27 | | - // handler for microtasks |
28 | | - triggerFatalException(error); |
29 | | - } finally { |
30 | | - asyncResource.emitDestroy(); |
31 | | - } |
32 | | - }); |
| 21 | + enqueueMicrotask(() => { |
| 22 | + asyncResource.runInAsyncScope(() => { |
| 23 | + try { |
| 24 | + callback(); |
| 25 | + } catch (error) { |
| 26 | + // TODO(devsnek) remove this if |
| 27 | + // https://bugs.chromium.org/p/v8/issues/detail?id=8326 |
| 28 | + // is resolved such that V8 triggers the fatal exception |
| 29 | + // handler for microtasks |
| 30 | + triggerFatalException(error); |
| 31 | + } finally { |
| 32 | + asyncResource.emitDestroy(); |
| 33 | + } |
33 | 34 | }); |
34 | | - }; |
35 | | - |
36 | | - return queueMicrotask; |
37 | | -}; |
| 35 | + }); |
| 36 | +} |
38 | 37 |
|
39 | | -module.exports = { setupQueueMicrotask }; |
| 38 | +module.exports = { queueMicrotask }; |
0 commit comments