11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ci// This test ensures that console methods cannot be invoked as constructors and
51cb0ef41Sopenharmony_ci// that their name is always correct.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst assert = require('assert');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst { Console } = console;
101cb0ef41Sopenharmony_ciconst newInstance = new Console(process.stdout);
111cb0ef41Sopenharmony_ciconst err = TypeError;
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst methods = [
141cb0ef41Sopenharmony_ci  'log',
151cb0ef41Sopenharmony_ci  'warn',
161cb0ef41Sopenharmony_ci  'dir',
171cb0ef41Sopenharmony_ci  'time',
181cb0ef41Sopenharmony_ci  'timeEnd',
191cb0ef41Sopenharmony_ci  'timeLog',
201cb0ef41Sopenharmony_ci  'trace',
211cb0ef41Sopenharmony_ci  'assert',
221cb0ef41Sopenharmony_ci  'clear',
231cb0ef41Sopenharmony_ci  'count',
241cb0ef41Sopenharmony_ci  'countReset',
251cb0ef41Sopenharmony_ci  'group',
261cb0ef41Sopenharmony_ci  'groupEnd',
271cb0ef41Sopenharmony_ci  'table',
281cb0ef41Sopenharmony_ci  'debug',
291cb0ef41Sopenharmony_ci  'info',
301cb0ef41Sopenharmony_ci  'dirxml',
311cb0ef41Sopenharmony_ci  'error',
321cb0ef41Sopenharmony_ci  'groupCollapsed',
331cb0ef41Sopenharmony_ci];
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciconst alternateNames = {
361cb0ef41Sopenharmony_ci  debug: 'log',
371cb0ef41Sopenharmony_ci  info: 'log',
381cb0ef41Sopenharmony_ci  dirxml: 'log',
391cb0ef41Sopenharmony_ci  error: 'warn',
401cb0ef41Sopenharmony_ci  groupCollapsed: 'group'
411cb0ef41Sopenharmony_ci};
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_cifunction assertEqualName(method) {
441cb0ef41Sopenharmony_ci  try {
451cb0ef41Sopenharmony_ci    assert.strictEqual(console[method].name, method);
461cb0ef41Sopenharmony_ci  } catch {
471cb0ef41Sopenharmony_ci    assert.strictEqual(console[method].name, alternateNames[method]);
481cb0ef41Sopenharmony_ci  }
491cb0ef41Sopenharmony_ci  try {
501cb0ef41Sopenharmony_ci    assert.strictEqual(newInstance[method].name, method);
511cb0ef41Sopenharmony_ci  } catch {
521cb0ef41Sopenharmony_ci    assert.strictEqual(newInstance[method].name, alternateNames[method]);
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci}
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_cifor (const method of methods) {
571cb0ef41Sopenharmony_ci  assertEqualName(method);
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  assert.throws(() => new console[method](), err);
601cb0ef41Sopenharmony_ci  assert.throws(() => new newInstance[method](), err);
611cb0ef41Sopenharmony_ci  assert.throws(() => Reflect.construct({}, [], console[method]), err);
621cb0ef41Sopenharmony_ci  assert.throws(() => Reflect.construct({}, [], newInstance[method]), err);
631cb0ef41Sopenharmony_ci}
64