Skip to content

Commit

Permalink
fixup! lib: replace validator and error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
VoltrexKeyva committed Feb 3, 2022
1 parent 2af3577 commit 8606e6b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
5 changes: 1 addition & 4 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/perf/timerify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 3 additions & 13 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const {
} = require('internal/util/types');
const { signals } = internalBinding('constants').os;

let inspect;

function isInt32(value) {
return value === (value | 0);
}
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 8606e6b

Please sign in to comment.