11cb0ef41Sopenharmony_ci// Flags: --unhandled-rejections=warn
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Verify that ignoring unhandled rejection works fine and that no warning is
81cb0ef41Sopenharmony_ci// logged.
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cinew Promise(() => {
111cb0ef41Sopenharmony_ci  throw new Error('One');
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciPromise.reject('test');
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_cifunction lookForMeInStackTrace() {
171cb0ef41Sopenharmony_ci  Promise.reject(new class ErrorLike {
181cb0ef41Sopenharmony_ci    constructor() {
191cb0ef41Sopenharmony_ci      Error.captureStackTrace(this);
201cb0ef41Sopenharmony_ci      this.message = 'ErrorLike';
211cb0ef41Sopenharmony_ci    }
221cb0ef41Sopenharmony_ci  }());
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_cilookForMeInStackTrace();
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci// Unhandled rejections trigger two warning per rejection. One is the rejection
271cb0ef41Sopenharmony_ci// reason and the other is a note where this warning is coming from.
281cb0ef41Sopenharmony_ciprocess.on('warning', common.mustCall((reason) => {
291cb0ef41Sopenharmony_ci  if (reason.message.includes('ErrorLike')) {
301cb0ef41Sopenharmony_ci    assert.match(reason.stack, /lookForMeInStackTrace/);
311cb0ef41Sopenharmony_ci  }
321cb0ef41Sopenharmony_ci}, 6));
331cb0ef41Sopenharmony_ciprocess.on('uncaughtException', common.mustNotCall('uncaughtException'));
341cb0ef41Sopenharmony_ciprocess.on('rejectionHandled', common.mustCall(3));
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ciprocess.on('unhandledRejection', (reason, promise) => {
371cb0ef41Sopenharmony_ci  // Handle promises but still warn!
381cb0ef41Sopenharmony_ci  promise.catch(() => {});
391cb0ef41Sopenharmony_ci});
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_cisetTimeout(common.mustCall(), 2);
42