11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci'use strict';
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci// This tests `internal/errors.useOriginalName`
61cb0ef41Sopenharmony_ci// This testing feature is needed to allows us to assert the types of
71cb0ef41Sopenharmony_ci// errors without using instanceof, which is necessary in WPT harness.
81cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/pull/22556
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cirequire('../common');
111cb0ef41Sopenharmony_ciconst assert = require('assert');
121cb0ef41Sopenharmony_ciconst errors = require('internal/errors');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cierrors.E('TEST_ERROR_1', 'Error for testing purposes: %s',
161cb0ef41Sopenharmony_ci         Error);
171cb0ef41Sopenharmony_ci{
181cb0ef41Sopenharmony_ci  const err = new errors.codes.TEST_ERROR_1('test');
191cb0ef41Sopenharmony_ci  assert(err instanceof Error);
201cb0ef41Sopenharmony_ci  assert.strictEqual(err.name, 'Error');
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci{
241cb0ef41Sopenharmony_ci  errors.useOriginalName = true;
251cb0ef41Sopenharmony_ci  const err = new errors.codes.TEST_ERROR_1('test');
261cb0ef41Sopenharmony_ci  assert(err instanceof Error);
271cb0ef41Sopenharmony_ci  assert.strictEqual(err.name, 'Error');
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci{
311cb0ef41Sopenharmony_ci  errors.useOriginalName = false;
321cb0ef41Sopenharmony_ci  const err = new errors.codes.TEST_ERROR_1('test');
331cb0ef41Sopenharmony_ci  assert(err instanceof Error);
341cb0ef41Sopenharmony_ci  assert.strictEqual(err.name, 'Error');
351cb0ef41Sopenharmony_ci}
36