From 64bc7b08de60e3a79535fce293afe783cae683aa Mon Sep 17 00:00:00 2001 From: Voltrex Date: Thu, 19 Aug 2021 22:03:59 +0430 Subject: [PATCH] console: use validators for consistency The usage of more validators could clean up validation and keep consistency. --- lib/internal/console/constructor.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index 22b84e5e42b956..3821f6f9880686 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -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 { @@ -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 @@ -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);