Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f2fe3f3

Browse files
committedFeb 3, 2022
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.
1 parent b194e2a commit f2fe3f3

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed
 

‎doc/api/deprecations.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -3067,11 +3067,9 @@ changes:
30673067

30683068
Type: End-of-Life
30693069

3070-
This error was removed due to adding more confusion to
3070+
This error code was removed due to adding more confusion to
30713071
the errors used for value type validation.
30723072

3073-
Use [`ERR_INVALID_ARG_TYPE`][] instead.
3074-
30753073
[Legacy URL API]: url.md#legacy-url-api
30763074
[NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf
30773075
[RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3
@@ -3086,7 +3084,6 @@ Use [`ERR_INVALID_ARG_TYPE`][] instead.
30863084
[`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj
30873085
[`Cipher`]: crypto.md#class-cipher
30883086
[`Decipher`]: crypto.md#class-decipher
3089-
[`ERR_INVALID_ARG_TYPE`]: errors.md#err_invalid_arg_type
30903087
[`REPLServer.clearBufferedCommand()`]: repl.md#replserverclearbufferedcommand
30913088
[`ReadStream.open()`]: fs.md#class-fsreadstream
30923089
[`Server.getConnections()`]: net.md#servergetconnectionscallback

‎lib/internal/errors.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,7 @@ E('ERR_INVALID_ARG_TYPE',
12081208
if (actual == null) {
12091209
msg += `. Received ${actual}`;
12101210
} else if (typeof actual === 'function' && actual.name) {
1211-
const inspected = lazyInternalUtilInspect()
1212-
.inspect(actual);
1213-
msg += `. Received ${inspected.startsWith('[class') ?
1214-
'class' : 'function'} ${actual.name}`;
1211+
msg += `. Received function ${actual.name}`;
12151212
} else if (typeof actual === 'object') {
12161213
if (actual.constructor && actual.constructor.name) {
12171214
msg += `. Received an instance of ${actual.constructor.name}`;

‎lib/internal/perf/timerify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function processComplete(name, start, args, histogram) {
5656
}
5757

5858
function timerify(fn, options = {}) {
59-
validateFunction(fn, 'fn', true);
59+
validateFunction(fn, 'fn');
6060

6161
validateObject(options, 'options');
6262
const {

‎lib/internal/validators.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const {
3232
} = require('internal/util/types');
3333
const { signals } = internalBinding('constants').os;
3434

35-
let inspect;
36-
3735
function isInt32(value) {
3836
return value === (value | 0);
3937
}
@@ -229,17 +227,9 @@ const validateAbortSignal = hideStackFrames((signal, name) => {
229227
}
230228
});
231229

232-
const validateFunction = hideStackFrames((value, name, allowClass = false) => {
233-
if (typeof value === 'function') {
234-
if (allowClass) return;
235-
236-
if (inspect === undefined)
237-
({ inspect } = require('util'));
238-
239-
if (!inspect(value).startsWith('[class')) return;
240-
}
241-
242-
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
230+
const validateFunction = hideStackFrames((value, name) => {
231+
if (typeof value !== 'function')
232+
throw new ERR_INVALID_ARG_TYPE(name, 'Function', value);
243233
});
244234

245235
const validatePlainFunction = hideStackFrames((value, name) => {

0 commit comments

Comments
 (0)
Please sign in to comment.