11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst async_hooks = require('async_hooks');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// Regression test for https://github.com/nodejs/node/issues/30080:
71cb0ef41Sopenharmony_ci// An uncaught exception inside a queueMicrotask callback should not lead
81cb0ef41Sopenharmony_ci// to multiple after() calls for it.
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cilet µtaskId;
111cb0ef41Sopenharmony_ciconst events = [];
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciasync_hooks.createHook({
141cb0ef41Sopenharmony_ci  init(id, type, triggerId, resource) {
151cb0ef41Sopenharmony_ci    if (type === 'Microtask') {
161cb0ef41Sopenharmony_ci      µtaskId = id;
171cb0ef41Sopenharmony_ci      events.push('init');
181cb0ef41Sopenharmony_ci    }
191cb0ef41Sopenharmony_ci  },
201cb0ef41Sopenharmony_ci  before(id) {
211cb0ef41Sopenharmony_ci    if (id === µtaskId) events.push('before');
221cb0ef41Sopenharmony_ci  },
231cb0ef41Sopenharmony_ci  after(id) {
241cb0ef41Sopenharmony_ci    if (id === µtaskId) events.push('after');
251cb0ef41Sopenharmony_ci  },
261cb0ef41Sopenharmony_ci  destroy(id) {
271cb0ef41Sopenharmony_ci    if (id === µtaskId) events.push('destroy');
281cb0ef41Sopenharmony_ci  }
291cb0ef41Sopenharmony_ci}).enable();
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciqueueMicrotask(() => { throw new Error(); });
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustCall());
341cb0ef41Sopenharmony_ciprocess.on('exit', () => {
351cb0ef41Sopenharmony_ci  assert.deepStrictEqual(events, ['init', 'after', 'before', 'destroy']);
361cb0ef41Sopenharmony_ci});
37