11cb0ef41Sopenharmony_ci// Flags: --unhandled-rejections=throw
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciconst Countdown = require('../common/countdown');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ci// Verify that the unhandledRejection handler prevents triggering
91cb0ef41Sopenharmony_ci// uncaught exceptions
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst err1 = new Error('One');
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst errors = [err1, null];
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciconst ref = new Promise(() => {
161cb0ef41Sopenharmony_ci  throw err1;
171cb0ef41Sopenharmony_ci});
181cb0ef41Sopenharmony_ci// Explicitly reject `null`.
191cb0ef41Sopenharmony_ciPromise.reject(null);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciprocess.on('warning', common.mustNotCall('warning'));
221cb0ef41Sopenharmony_ciprocess.on('rejectionHandled', common.mustNotCall('rejectionHandled'));
231cb0ef41Sopenharmony_ciprocess.on('exit', assert.strictEqual.bind(null, 0));
241cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustNotCall('uncaughtException'));
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciconst timer = setTimeout(() => console.log(ref), 1000);
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciconst counter = new Countdown(2, () => {
291cb0ef41Sopenharmony_ci  clearTimeout(timer);
301cb0ef41Sopenharmony_ci});
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciprocess.on('unhandledRejection', common.mustCall((err) => {
331cb0ef41Sopenharmony_ci  counter.dec();
341cb0ef41Sopenharmony_ci  const knownError = errors.shift();
351cb0ef41Sopenharmony_ci  assert.deepStrictEqual(err, knownError);
361cb0ef41Sopenharmony_ci}, 2));
37