11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { promiseHooks } = require('v8');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst expected = [];
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction testHook(name) {
91cb0ef41Sopenharmony_ci  const hook = promiseHooks[name];
101cb0ef41Sopenharmony_ci  const error = new Error(`${name} error`);
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  const stop = hook(common.mustCall(() => {
131cb0ef41Sopenharmony_ci    stop();
141cb0ef41Sopenharmony_ci    throw error;
151cb0ef41Sopenharmony_ci  }));
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  expected.push(error);
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustCall((received) => {
211cb0ef41Sopenharmony_ci  assert.strictEqual(received, expected.shift());
221cb0ef41Sopenharmony_ci}, 4));
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_citestHook('onInit');
251cb0ef41Sopenharmony_citestHook('onSettled');
261cb0ef41Sopenharmony_citestHook('onBefore');
271cb0ef41Sopenharmony_citestHook('onAfter');
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ciconst stop = promiseHooks.onInit(common.mustCall(2));
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciPromise.resolve().then(stop);
32