Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: use object instead of Object is most cases
  • Loading branch information
BridgeAR committed Dec 19, 2019
commit b03332403e04aff9a133fb1883615c304049205c
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function Server(options, requestListener) {
} else if (options == null || typeof options === 'object') {
options = { ...options };
} else {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
}

this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
Expand Down
4 changes: 2 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function normalizeSpawnArguments(file, args, options) {
} else if (args == null) {
args = [];
} else if (typeof args !== 'object') {
throw new ERR_INVALID_ARG_TYPE('args', 'Object', args);
throw new ERR_INVALID_ARG_TYPE('args', 'object', args);
} else {
options = args;
args = [];
Expand All @@ -421,7 +421,7 @@ function normalizeSpawnArguments(file, args, options) {
if (options === undefined)
options = {};
else if (options === null || typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);

// Validate the cwd, if present.
if (options.cwd != null &&
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ function setupChannel(target, channel, serializationMode) {
typeof message !== 'number' &&
typeof message !== 'boolean') {
throw new ERR_INVALID_ARG_TYPE(
'message', ['string', 'Object', 'number', 'boolean'], message);
'message', ['string', 'object', 'number', 'boolean'], message);
}

// Support legacy function signature
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
}
optionsMap.set(this, inspectOptions);
} else if (inspectOptions !== undefined) {
throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'Object', inspectOptions);
throw new ERR_INVALID_ARG_TYPE('inspectOptions', 'object', inspectOptions);
}

// Bind the prototype functions to this Console instance
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ function check(type, options, callback) {
let cipher, passphrase, publicType, publicFormat, privateType, privateFormat;

if (options !== undefined && typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);

function needOptions() {
if (options == null)
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
return options;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/internal/crypto/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class KeyObject {
if (type !== 'secret' && type !== 'public' && type !== 'private')
throw new ERR_INVALID_ARG_VALUE('type', type);
if (typeof handle !== 'object')
throw new ERR_INVALID_ARG_TYPE('handle', 'Object', handle);
throw new ERR_INVALID_ARG_TYPE('handle', 'object', handle);

this[kKeyType] = type;

Expand Down Expand Up @@ -178,7 +178,7 @@ function isStringOrBuffer(val) {

function parseKeyEncoding(enc, keyType, isPublic, objName) {
if (enc === null || typeof enc !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', enc);
throw new ERR_INVALID_ARG_TYPE('options', 'object', enc);

const isInput = keyType === undefined;

Expand Down
26 changes: 22 additions & 4 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ const messages = new Map();
const codes = {};

const classRegExp = /^([A-Z][a-z0-9]*)+$/;
// Sorted by a rough estimate on most frequently used entries.
const kTypes = [
'string', 'boolean', 'number', 'symbol', 'bigint', 'function'
'string',
'function',
'number',
'object',
// Accept 'Function' and 'Object' as alternative to the lower cased version.
'Function',
'Object',
'boolean',
'bigint',
'symbol'
];

const { kMaxLength } = internalBinding('buffer');
Expand Down Expand Up @@ -940,9 +950,7 @@ E('ERR_INVALID_ARG_TYPE',
assert(typeof value === 'string',
'All expected entries have to be of type string');
if (kTypes.includes(value)) {
types.push(value);
} else if (value === 'Function') { // 'Function' should be handled as type
types.push('function');
types.push(value.toLowerCase());
} else if (classRegExp.test(value)) {
instances.push(value);
} else {
Expand All @@ -952,6 +960,16 @@ E('ERR_INVALID_ARG_TYPE',
}
}

// Special handle `object` in case other instances are allowed to outline
// the differences between each other.
if (instances.length > 0) {
const pos = types.indexOf('object');
if (pos !== -1) {
types.splice(pos, 1);
instances.push('Object');
}
}

if (types.length > 0) {
if (types.length > 2) {
const last = types.pop();
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ const validateRmdirOptions = hideStackFrames((options) => {
if (options === undefined)
return defaultRmdirOptions;
if (options === null || typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);

options = { ...defaultRmdirOptions, ...options };

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ class ServerHttp2Session extends Http2Session {
// be invalid.
if (typeof origin !== 'string') {
throw new ERR_INVALID_ARG_TYPE('originOrStream',
['string', 'number', 'URL', 'Object'],
['string', 'number', 'URL', 'object'],
originOrStream);
} else if (origin === 'null' || origin.length === 0) {
throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN();
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function wrapProcessMethods(binding) {
if (prevValue) {
if (!previousValueIsValid(prevValue.user)) {
if (typeof prevValue !== 'object')
throw new ERR_INVALID_ARG_TYPE('prevValue', 'Object', prevValue);
throw new ERR_INVALID_ARG_TYPE('prevValue', 'object', prevValue);

if (typeof prevValue.user !== 'number') {
throw new ERR_INVALID_ARG_TYPE('prevValue.user',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function eos(stream, opts, callback) {
} else if (opts == null) {
opts = {};
} else if (typeof opts !== 'object') {
throw new ERR_INVALID_ARG_TYPE('opts', 'Object', opts);
throw new ERR_INVALID_ARG_TYPE('opts', 'object', opts);
}
if (typeof callback !== 'function') {
throw new ERR_INVALID_ARG_TYPE('callback', 'function', callback);
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Worker extends EventEmitter {
} else if (options.env !== SHARE_ENV) {
throw new ERR_INVALID_ARG_TYPE(
'options.env',
['Object', 'undefined', 'null', 'worker_threads.SHARE_ENV'],
['object', 'undefined', 'null', 'worker_threads.SHARE_ENV'],
options.env);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/trace_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Tracing {

function createTracing(options) {
if (typeof options !== 'object' || options === null)
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);

if (!ArrayIsArray(options.categories)) {
throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]',
Expand Down
2 changes: 1 addition & 1 deletion lib/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function compileFunction(code, params, options = {}) {
if (typeof extension !== 'object') {
throw new ERR_INVALID_ARG_TYPE(
`options.contextExtensions[${i}]`,
'Object',
'object',
extension
);
}
Expand Down
11 changes: 6 additions & 5 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ assert.throws(() => {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options" argument must be an instance of Object.' +
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
Expand Down Expand Up @@ -937,8 +937,9 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "error" argument must be of type function or an instance of' +
" Object, Error, or RegExp. Received type string ('Error message')"
message: 'The "error" argument must be of type function or ' +
'an instance of Error, RegExp, or Object. Received type string ' +
"('Error message')"
}
);

Expand All @@ -951,8 +952,8 @@ common.expectsError(
() => assert.throws(() => {}, input),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "error" argument must be of type function or an instance ' +
'of Object, Error, or RegExp.' +
message: 'The "error" argument must be of type function or ' +
'an instance of Error, RegExp, or Object.' +
common.invalidArgTypeHelper(input)
}
);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-child-process-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ assert.strictEqual(typeof ChildProcess, 'function');
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be an instance of Object.' +
message: 'The "options" argument must be of type object.' +
`${common.invalidArgTypeHelper(options)}`
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-child-process-fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ assert.throws(() => n.send(), {

assert.throws(() => n.send(Symbol()), {
name: 'TypeError',
message: 'The "message" argument must be one of type string, number, or ' +
'boolean or an instance of Object. Received type symbol (Symbol())',
message: 'The "message" argument must be one of type string,' +
' object, number, or boolean. Received type symbol (Symbol())',
code: 'ERR_INVALID_ARG_TYPE'
});
n.send({ hello: 'world' });
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-console-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ out.write = err.write = (d) => {};
});
},
{
message: 'The "inspectOptions" argument must be an instance of Object.' +
message: 'The "inspectOptions" argument must be of type object.' +
common.invalidArgTypeHelper(inspectOptions),
code: 'ERR_INVALID_ARG_TYPE'
}
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-crypto-key-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message:
'The "handle" argument must be an instance of Object. Received type ' +
'The "handle" argument must be of type object. Received type ' +
"string ('')"
});
}
Expand Down Expand Up @@ -142,7 +142,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem',
common.expectsError(() => publicKey.export(opt), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: /^The "options" argument must be an instance of Object/
message: /^The "options" argument must be of type object/
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-crypto-keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
common.expectsError(() => generateKeyPair('rsa', common.mustNotCall()), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be an instance of Object. ' +
message: 'The "options" argument must be of type object. ' +
'Received undefined'
});

Expand All @@ -624,7 +624,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher);
common.expectsError(() => generateKeyPair('ed448', 0, common.mustNotCall()), {
type: TypeError,
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be an instance of Object. ' +
message: 'The "options" argument must be of type object. ' +
'Received type number (0)'
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-fs-rmdir-recursive.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function removeAsync(dir) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: /^The "options" argument must be an instance of Object\./
message: /^The "options" argument must be of type object\./
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-http2-createsecureserver-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(invalidOption)
}
);
});
Expand All @@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
message: 'The "options.settings" property must be of type object.' +
common.invalidArgTypeHelper(invalidSettingsOption)
}
);
});
Expand Down
8 changes: 4 additions & 4 deletions test/parallel/test-http2-createserver-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ invalidOptions.forEach((invalidOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. Received ' +
`type ${typeof invalidOption}`
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(invalidOption)
}
);
});
Expand All @@ -28,8 +28,8 @@ invalidOptions.forEach((invalidSettingsOption) => {
{
name: 'TypeError',
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options.settings" property must be of type Object. ' +
`Received type ${typeof invalidSettingsOption}`
message: 'The "options.settings" property must be of type object.' +
common.invalidArgTypeHelper(invalidSettingsOption)
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-misc-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ common.expectsError(
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "test" argument must be an instance of Object. Received ' +
message: 'The "test" argument must be of type object. Received ' +
"type string ('foo')"
});

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-util-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
() => assertIsObject(input, 'foo', 'Object'),
{
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "foo" argument must be an instance of Object.' +
message: 'The "foo" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function checkFormat(path, testCases) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be an instance of Object.' +
message: 'The "pathObject" argument must be of type object.' +
common.invalidArgTypeHelper(pathObject)
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-performanceobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be an instance of Object.' +
message: 'The "options" argument must be of type object.' +
common.invalidArgTypeHelper(input)
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-process-cpuUsage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ assert.throws(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "prevValue" argument must be an instance of Object. ' +
message: 'The "prevValue" argument must be of type object. ' +
'Received type number (1)'
}
);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-keyengine-invalid-arg-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ common.expectsError(
privateKeyIdentifier: 'key' });
},
{ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number$/ });
message: / Received type number \(0\)$/ });

common.expectsError(
() => {
tls.createSecureContext({ privateKeyEngine: 'engine',
privateKeyIdentifier: 0 });
},
{ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number$/ });
message: / Received type number \(0\)$/ });
Loading