Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const {
ERR_TLS_SESSION_ATTACK,
ERR_TLS_SNI_FROM_SERVER
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const { validateObject, validateString } = require('internal/validators');
const kConnectOptions = Symbol('connect-options');
const kDisableRenegotiation = Symbol('disable-renegotiation');
const kErrorEmitted = Symbol('error-emitted');
Expand Down Expand Up @@ -885,8 +885,7 @@ exports.createServer = function createServer(options, listener) {


Server.prototype.setSecureContext = function(options) {
if (options === null || typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
validateObject(options, 'options');

if (options.pfx)
this.pfx = options.pfx;
Expand Down
10 changes: 7 additions & 3 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ const {
ERR_INVALID_OPT_VALUE,
ERR_OUT_OF_RANGE
} = require('internal/errors').codes;
const { validateString, isInt32 } = require('internal/validators');
const {
validateString,
isInt32,
validateObject
} = require('internal/validators');
const child_process = require('internal/child_process');
const {
_validateStdio,
Expand Down Expand Up @@ -417,8 +421,8 @@ 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);
else
validateObject(options, 'options');

// Validate the cwd, if present.
if (options.cwd != null &&
Expand Down
7 changes: 2 additions & 5 deletions lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const {
ERR_INSPECTOR_CLOSED,
ERR_INSPECTOR_NOT_AVAILABLE,
ERR_INSPECTOR_NOT_CONNECTED,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_CALLBACK
} = require('internal/errors').codes;
const { validateString } = require('internal/validators');
const { validateObject, validateString } = require('internal/validators');
const util = require('util');
const { Connection, open, url } = internalBinding('inspector');

Expand Down Expand Up @@ -63,9 +62,7 @@ class Session extends EventEmitter {
callback = params;
params = null;
}
if (params && typeof params !== 'object') {
throw new ERR_INVALID_ARG_TYPE('params', 'Object', params);
}
if (params) validateObject(params, 'params');
if (callback && typeof callback !== 'function') {
throw new ERR_INVALID_CALLBACK();
}
Expand Down
8 changes: 2 additions & 6 deletions lib/internal/assert.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict';

const { inspect } = require('util');
const { codes: {
ERR_INVALID_ARG_TYPE
} } = require('internal/errors');
const { validateObject } = require('internal/validators');

let blue = '';
let green = '';
Expand Down Expand Up @@ -289,9 +287,7 @@ function createErrDiff(actual, expected, operator) {

class AssertionError extends Error {
constructor(options) {
if (typeof options !== 'object' || options === null) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
validateObject(options, 'options');
var {
actual,
expected,
Expand Down
6 changes: 2 additions & 4 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
ERR_MISSING_ARGS
}
} = require('internal/errors');
const { validateString } = require('internal/validators');
const { validateObject, validateString } = require('internal/validators');
const EventEmitter = require('events');
const net = require('net');
const dgram = require('dgram');
Expand Down Expand Up @@ -308,9 +308,7 @@ ChildProcess.prototype.spawn = function(options) {
var ipcFd;
var i;

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

// If no `stdio` option was given - use default
var stdio = options.stdio || 'pipe';
Expand Down
11 changes: 7 additions & 4 deletions lib/internal/crypto/keygen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ const {
PrivateKeyObject
} = require('internal/crypto/keys');
const { customPromisifyArgs } = require('internal/util');
const { isUint32, validateString } = require('internal/validators');
const {
ERR_INVALID_ARG_TYPE,
isUint32,
validateObject,
validateString
} = require('internal/validators');

const {
ERR_INVALID_ARG_VALUE,
ERR_INVALID_CALLBACK,
ERR_INVALID_OPT_VALUE
Expand Down Expand Up @@ -115,8 +119,7 @@ function parseKeyEncoding(keyType, options) {

function check(type, options, callback) {
validateString(type, 'type');
if (options == null || typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'object', options);
validateObject(options, 'options');

// These will be set after parsing the type and type-specific options to make
// the order a bit more intuitive.
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
isHexTable
} = require('internal/querystring');

const { validateObject } = require('internal/validators');
const { getConstructorOf, removeColors } = require('internal/util');
const {
ERR_ARG_NOT_ITERABLE,
Expand Down Expand Up @@ -380,8 +381,7 @@ Object.defineProperties(URL.prototype, {
configurable: false,
// eslint-disable-next-line func-name-matching
value: function format(options) {
if (options && typeof options !== 'object')
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
if (options) validateObject(options, 'options');
options = {
fragment: true,
unicode: false,
Expand Down
12 changes: 3 additions & 9 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ const {
removeColors
} = require('internal/util');

const {
codes: {
ERR_INVALID_ARG_TYPE
},
isStackOverflowError
} = require('internal/errors');
const { isStackOverflowError } = require('internal/errors');
const { validateObject } = require('internal/validators');

const types = internalBinding('types');
Object.assign(types, require('internal/util/types'));
Expand Down Expand Up @@ -200,9 +196,7 @@ Object.defineProperty(inspect, 'defaultOptions', {
return inspectDefaultOptions;
},
set(options) {
if (options === null || typeof options !== 'object') {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
validateObject(options, 'options');
return Object.assign(inspectDefaultOptions, options);
}
});
Expand Down
9 changes: 8 additions & 1 deletion lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ function validateNumber(value, name) {
throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
}

function validateObject(value, name) {
if (typeof value !== 'object' || value === null) {
throw new ERR_INVALID_ARG_TYPE(name, 'object', value);
}
}

module.exports = {
isInt32,
isUint32,
Expand All @@ -138,5 +144,6 @@ module.exports = {
validateInt32,
validateUint32,
validateString,
validateNumber
validateNumber,
validateObject
};
12 changes: 4 additions & 8 deletions lib/internal/vm/source_text_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const { SafePromise } = require('internal/safe_globals');
const {
validateInt32,
validateUint32,
validateObject,
validateString
} = require('internal/validators');

Expand Down Expand Up @@ -59,8 +60,7 @@ class SourceTextModule {
emitExperimentalWarning('vm.SourceTextModule');

validateString(src, 'src');
if (typeof options !== 'object' || options === null)
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
validateObject(options, 'options');

const {
context,
Expand All @@ -71,9 +71,7 @@ class SourceTextModule {
} = options;

if (context !== undefined) {
if (typeof context !== 'object' || context === null) {
throw new ERR_INVALID_ARG_TYPE('options.context', 'Object', context);
}
validateObject(context, 'options.context');
if (!isContext(context)) {
throw new ERR_INVALID_ARG_TYPE('options.context', 'vm.Context',
context);
Expand Down Expand Up @@ -218,9 +216,7 @@ class SourceTextModule {
}

async evaluate(options = {}) {
if (typeof options !== 'object' || options === null) {
throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
validateObject(options, 'options');

let timeout = options.timeout;
if (timeout === undefined) {
Expand Down
11 changes: 3 additions & 8 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

'use strict';

const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
const {
CHAR_UPPERCASE_A,
CHAR_LOWERCASE_A,
Expand All @@ -33,7 +32,7 @@ const {
CHAR_COLON,
CHAR_QUESTION_MARK,
} = require('internal/constants');
const { validateString } = require('internal/validators');
const { validateObject, validateString } = require('internal/validators');

function isPathSeparator(code) {
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
Expand Down Expand Up @@ -892,9 +891,7 @@ const win32 = {


format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new ERR_INVALID_ARG_TYPE('pathObject', 'Object', pathObject);
}
validateObject(pathObject, 'pathObject');
return _format('\\', pathObject);
},

Expand Down Expand Up @@ -1415,9 +1412,7 @@ const posix = {


format: function format(pathObject) {
if (pathObject === null || typeof pathObject !== 'object') {
throw new ERR_INVALID_ARG_TYPE('pathObject', 'Object', pathObject);
}
validateObject(pathObject, 'pathObject');
return _format('/', pathObject);
},

Expand Down
5 changes: 2 additions & 3 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
const { AsyncResource } = require('async_hooks');
const L = require('internal/linkedlist');
const kInspect = require('internal/util').customInspectSymbol;
const { validateObject } = require('internal/validators');

const kCallback = Symbol('callback');
const kTypes = Symbol('types');
Expand Down Expand Up @@ -324,9 +325,7 @@ class PerformanceObserver extends AsyncResource {

observe(options) {
const errors = lazyErrors();
if (typeof options !== 'object' || options == null) {
throw new errors.ERR_INVALID_ARG_TYPE('options', 'Object', options);
}
validateObject(options, 'options');
if (!Array.isArray(options.entryTypes)) {
throw new errors.ERR_INVALID_OPT_VALUE('entryTypes', options);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/trace_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
ERR_TRACE_EVENTS_UNAVAILABLE,
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
const { validateObject } = require('internal/validators');

const { isMainThread } = require('internal/worker');
if (!hasTracing || !isMainThread)
Expand Down Expand Up @@ -70,8 +71,7 @@ class Tracing {
}

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

if (!Array.isArray(options.categories)) {
throw new ERR_INVALID_ARG_TYPE('options.categories', 'string[]',
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ assert.throws(() => {
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
`Received type ${typeof 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 @@ -19,7 +19,7 @@ function typeName(value) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
`Received type ${typeName(options)}`
});
});
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 @@ -226,7 +226,7 @@ function checkFormat(path, testCases) {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "pathObject" argument must be of type Object. ' +
message: 'The "pathObject" argument must be of type object. ' +
`Received type ${typeof 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 @@ -45,7 +45,7 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0);
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
`Received type ${typeof input}`
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-url-format-whatwg.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ assert.strictEqual(
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError [ERR_INVALID_ARG_TYPE]',
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
`Received type ${typeof value}`
}
);
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ if (typeof Symbol !== 'undefined') {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
'Received type object'
}
);
Expand All @@ -1196,7 +1196,7 @@ if (typeof Symbol !== 'undefined') {
}, {
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
'Received type string'
}
);
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-vm-module-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function checkModuleState() {
await m.evaluate(false);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "options" argument must be of type Object. ' +
message: 'The "options" argument must be of type object. ' +
'Received type boolean'
});

Expand Down
2 changes: 1 addition & 1 deletion test/sequential/test-inspector-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ session.post('Runtime.evaluate', { expression: '2 + 2' });
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message:
'The "params" argument must be of type Object. ' +
'The "params" argument must be of type object. ' +
`Received type ${typeof i}`
}
);
Expand Down