• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const async_hooks = require('async_hooks');
5
6// Regression test for https://github.com/nodejs/node/issues/30080:
7// An uncaught exception inside a queueMicrotask callback should not lead
8// to multiple after() calls for it.
9
10let µtaskId;
11const events = [];
12
13async_hooks.createHook({
14  init(id, type, triggerId, resoure) {
15    if (type === 'Microtask') {
16      µtaskId = id;
17      events.push('init');
18    }
19  },
20  before(id) {
21    if (id === µtaskId) events.push('before');
22  },
23  after(id) {
24    if (id === µtaskId) events.push('after');
25  },
26  destroy(id) {
27    if (id === µtaskId) events.push('destroy');
28  }
29}).enable();
30
31queueMicrotask(() => { throw new Error(); });
32
33process.on('uncaughtException', common.mustCall());
34process.on('exit', () => {
35  assert.deepStrictEqual(events, ['init', 'after', 'before', 'destroy']);
36});
37