Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
VoltrexKeyva authored and targos committed Oct 4, 2021
1 parent 73a127b commit 4b117fb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/internal/console/constructor.js
Expand Up @@ -42,12 +42,15 @@ const {
isStackOverflowError,
codes: {
ERR_CONSOLE_WRITABLE_STREAM,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_INCOMPATIBLE_OPTION_PAIR,
},
} = require('internal/errors');
const { validateInteger } = require('internal/validators');
const {
validateArray,
validateInteger,
validateObject,
} = require('internal/validators');
const { previewEntries } = internalBinding('util');
const { Buffer: { isBuffer } } = require('buffer');
const {
Expand Down Expand Up @@ -132,18 +135,15 @@ function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
0, kMaxGroupIndentation);
}

if (typeof inspectOptions === 'object' && inspectOptions !== null) {
if (inspectOptions !== undefined) {
validateObject(inspectOptions, 'options.inspectOptions');

if (inspectOptions.colors !== undefined &&
options.colorMode !== undefined) {
throw new ERR_INCOMPATIBLE_OPTION_PAIR(
'options.inspectOptions.color', 'colorMode');
}
optionsMap.set(this, inspectOptions);
} else if (inspectOptions !== undefined) {
throw new ERR_INVALID_ARG_TYPE(
'options.inspectOptions',
'object',
inspectOptions);
}

// Bind the prototype functions to this Console instance
Expand Down Expand Up @@ -479,8 +479,8 @@ const consoleMethods = {

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

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

0 comments on commit 4b117fb

Please sign in to comment.