11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ciconst {
71cb0ef41Sopenharmony_ci  getSystemErrorName,
81cb0ef41Sopenharmony_ci  _errnoException
91cb0ef41Sopenharmony_ci} = require('util');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding');
121cb0ef41Sopenharmony_ciconst uv = internalBinding('uv');
131cb0ef41Sopenharmony_ciconst keys = Object.keys(uv);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciassert.strictEqual(uv.errname(-111111), 'Unknown system error -111111');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cikeys.forEach((key) => {
181cb0ef41Sopenharmony_ci  if (!key.startsWith('UV_'))
191cb0ef41Sopenharmony_ci    return;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  const err = _errnoException(uv[key], 'test');
221cb0ef41Sopenharmony_ci  const name = uv.errname(uv[key]);
231cb0ef41Sopenharmony_ci  assert.strictEqual(getSystemErrorName(uv[key]), name);
241cb0ef41Sopenharmony_ci  assert.strictEqual(err.code, name);
251cb0ef41Sopenharmony_ci  assert.strictEqual(err.code, getSystemErrorName(err.errno));
261cb0ef41Sopenharmony_ci  assert.strictEqual(err.message, `test ${name}`);
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cifunction runTest(fn) {
301cb0ef41Sopenharmony_ci  ['test', {}, []].forEach((err) => {
311cb0ef41Sopenharmony_ci    assert.throws(
321cb0ef41Sopenharmony_ci      () => fn(err),
331cb0ef41Sopenharmony_ci      {
341cb0ef41Sopenharmony_ci        code: 'ERR_INVALID_ARG_TYPE',
351cb0ef41Sopenharmony_ci        name: 'TypeError',
361cb0ef41Sopenharmony_ci        message: 'The "err" argument must be of type number.' +
371cb0ef41Sopenharmony_ci                 common.invalidArgTypeHelper(err)
381cb0ef41Sopenharmony_ci      });
391cb0ef41Sopenharmony_ci  });
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci  [0, 1, Infinity, -Infinity, NaN].forEach((err) => {
421cb0ef41Sopenharmony_ci    assert.throws(
431cb0ef41Sopenharmony_ci      () => fn(err),
441cb0ef41Sopenharmony_ci      {
451cb0ef41Sopenharmony_ci        code: 'ERR_OUT_OF_RANGE',
461cb0ef41Sopenharmony_ci        name: 'RangeError',
471cb0ef41Sopenharmony_ci        message: 'The value of "err" is out of range. ' +
481cb0ef41Sopenharmony_ci                 'It must be a negative integer. ' +
491cb0ef41Sopenharmony_ci                 `Received ${err}`
501cb0ef41Sopenharmony_ci      });
511cb0ef41Sopenharmony_ci  });
521cb0ef41Sopenharmony_ci}
531cb0ef41Sopenharmony_ci
541cb0ef41Sopenharmony_cirunTest(_errnoException);
551cb0ef41Sopenharmony_cirunTest(getSystemErrorName);
56