Skip to content
Closed
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
console: use validators for consistency
The usage of more validators could clean up validation and keep
consistency.
  • Loading branch information
VoltrexKeyva committed Sep 3, 2021
commit 64bc7b08de60e3a79535fce293afe783cae683aa
20 changes: 10 additions & 10 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
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 @@ -136,18 +139,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 @@ -483,8 +483,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