Skip to content

Commit 7b65400

Browse files
committed
console: use validators for consistency
The usage of more validators could clean up validation and keep consistency.
1 parent 3fe92a2 commit 7b65400

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/internal/console/constructor.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,15 @@ const {
4242
isStackOverflowError,
4343
codes: {
4444
ERR_CONSOLE_WRITABLE_STREAM,
45-
ERR_INVALID_ARG_TYPE,
4645
ERR_INVALID_ARG_VALUE,
4746
ERR_INCOMPATIBLE_OPTION_PAIR,
4847
},
4948
} = require('internal/errors');
50-
const { validateInteger } = require('internal/validators');
49+
const {
50+
validateArray,
51+
validateInteger,
52+
validateObject,
53+
} = require('internal/validators');
5154
const { previewEntries } = internalBinding('util');
5255
const { Buffer: { isBuffer } } = require('buffer');
5356
const {
@@ -136,18 +139,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
136139
0, kMaxGroupIndentation);
137140
}
138141

139-
if (typeof inspectOptions === 'object' && inspectOptions !== null) {
142+
if (inspectOptions !== undefined) {
143+
validateObject(inspectOptions, 'options.inspectOptions');
144+
140145
if (inspectOptions.colors !== undefined &&
141146
options.colorMode !== undefined) {
142147
throw new ERR_INCOMPATIBLE_OPTION_PAIR(
143148
'options.inspectOptions.color', 'colorMode');
144149
}
145150
optionsMap.set(this, inspectOptions);
146-
} else if (inspectOptions !== undefined) {
147-
throw new ERR_INVALID_ARG_TYPE(
148-
'options.inspectOptions',
149-
'object',
150-
inspectOptions);
151151
}
152152

153153
// Bind the prototype functions to this Console instance
@@ -483,8 +483,8 @@ const consoleMethods = {
483483

484484
// https://console.spec.whatwg.org/#table
485485
table(tabularData, properties) {
486-
if (properties !== undefined && !ArrayIsArray(properties))
487-
throw new ERR_INVALID_ARG_TYPE('properties', 'Array', properties);
486+
if (properties !== undefined)
487+
validateArray(properties, 'properties');
488488

489489
if (tabularData === null || typeof tabularData !== 'object')
490490
return this.log(tabularData);

0 commit comments

Comments
 (0)