From a650babef5283c8ee75e01dbc5b1a349b802515e Mon Sep 17 00:00:00 2001 From: Mohammed Keyvanzadeh Date: Fri, 4 Feb 2022 02:59:44 +0330 Subject: [PATCH] fixup! lib: replace validator and error Reverted the changes to the `validateFunction()` validator, added `code` after `error`, removed the link re-directing to `ERR_INAVLID_ARG_TYPE` error code, and reverted the changes to the `ERR_INVALID_ARG_TYPE` error code. --- doc/api/deprecations.md | 5 +---- lib/internal/errors.js | 5 +---- lib/internal/perf/timerify.js | 2 +- lib/internal/validators.js | 16 +++------------- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 974dd5443352e6..1272c652b46085 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3067,11 +3067,9 @@ changes: Type: End-of-Life -This error was removed due to adding more confusion to +This error code was removed due to adding more confusion to the errors used for value type validation. -Use [`ERR_INVALID_ARG_TYPE`][] instead. - [Legacy URL API]: url.md#legacy-url-api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 @@ -3086,7 +3084,6 @@ Use [`ERR_INVALID_ARG_TYPE`][] instead. [`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj [`Cipher`]: crypto.md#class-cipher [`Decipher`]: crypto.md#class-decipher -[`ERR_INVALID_ARG_TYPE`]: errors.md#err_invalid_arg_type [`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand [`ReadStream.open()`]: fs.md#class-fsreadstream [`Server.getConnections()`]: net.md#servergetconnectionscallback diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3b5d0d8e432cf9..a4e32c12cecae1 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1208,10 +1208,7 @@ E('ERR_INVALID_ARG_TYPE', if (actual == null) { msg += `. Received ${actual}`; } else if (typeof actual === 'function' && actual.name) { - const inspected = lazyInternalUtilInspect() - .inspect(actual); - msg += `. Received ${inspected.startsWith('[class') ? - 'class' : 'function'} ${actual.name}`; + msg += `. Received function ${actual.name}`; } else if (typeof actual === 'object') { if (actual.constructor && actual.constructor.name) { msg += `. Received an instance of ${actual.constructor.name}`; diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index cdc0792e582a7e..dae0b06bf80c8a 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -56,7 +56,7 @@ function processComplete(name, start, args, histogram) { } function timerify(fn, options = {}) { - validateFunction(fn, 'fn', true); + validateFunction(fn, 'fn'); validateObject(options, 'options'); const { diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 2bcf876abf5587..b07eebfbd8b1a0 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -32,8 +32,6 @@ const { } = require('internal/util/types'); const { signals } = internalBinding('constants').os; -let inspect; - function isInt32(value) { return value === (value | 0); } @@ -229,17 +227,9 @@ const validateAbortSignal = hideStackFrames((signal, name) => { } }); -const validateFunction = hideStackFrames((value, name, allowClass = false) => { - if (typeof value === 'function') { - if (allowClass) return; - - if (inspect === undefined) - ({ inspect } = require('util')); - - if (!inspect(value).startsWith('[class')) return; - } - - throw new ERR_INVALID_ARG_TYPE(name, 'Function', value); +const validateFunction = hideStackFrames((value, name) => { + if (typeof value !== 'function') + throw new ERR_INVALID_ARG_TYPE(name, 'Function', value); }); const validatePlainFunction = hideStackFrames((value, name) => {