Skip to content

Commit 4b117fb

Browse files
VoltrexKeyvatargos
authored andcommitted
console: use validators for consistency
The usage of more validators could clean up validation and keep consistency. PR-URL: #39812 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 73a127b commit 4b117fb

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 {
@@ -132,18 +135,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
132135
0, kMaxGroupIndentation);
133136
}
134137

135-
if (typeof inspectOptions === 'object' && inspectOptions !== null) {
138+
if (inspectOptions !== undefined) {
139+
validateObject(inspectOptions, 'options.inspectOptions');
140+
136141
if (inspectOptions.colors !== undefined &&
137142
options.colorMode !== undefined) {
138143
throw new ERR_INCOMPATIBLE_OPTION_PAIR(
139144
'options.inspectOptions.color', 'colorMode');
140145
}
141146
optionsMap.set(this, inspectOptions);
142-
} else if (inspectOptions !== undefined) {
143-
throw new ERR_INVALID_ARG_TYPE(
144-
'options.inspectOptions',
145-
'object',
146-
inspectOptions);
147147
}
148148

149149
// Bind the prototype functions to this Console instance
@@ -479,8 +479,8 @@ const consoleMethods = {
479479

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

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

0 commit comments

Comments
 (0)