From fc2b1ec3081c606e88df28b4596f5690fdcfd75a Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Fri, 4 Jun 2021 17:49:04 +0800 Subject: [PATCH] child_process: refactor to use `validateBoolean` PR-URL: https://github.com/nodejs/node/pull/38927 Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen Reviewed-By: Khaidi Chu Reviewed-By: Zijian Liu Reviewed-By: James M Snell --- lib/child_process.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 42bdaa86448e83..68fb8ddd3d254a 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -62,6 +62,7 @@ const { validateString, isInt32, validateAbortSignal, + validateBoolean, } = require('internal/validators'); const child_process = require('internal/child_process'); const { @@ -463,10 +464,8 @@ function normalizeSpawnArguments(file, args, options) { } // Validate detached, if present. - if (options.detached != null && - typeof options.detached !== 'boolean') { - throw new ERR_INVALID_ARG_TYPE('options.detached', - 'boolean', options.detached); + if (options.detached != null) { + validateBoolean(options.detached, 'options.detached'); } // Validate the uid, if present. @@ -494,19 +493,15 @@ function normalizeSpawnArguments(file, args, options) { } // Validate windowsHide, if present. - if (options.windowsHide != null && - typeof options.windowsHide !== 'boolean') { - throw new ERR_INVALID_ARG_TYPE('options.windowsHide', - 'boolean', options.windowsHide); + if (options.windowsHide != null) { + validateBoolean(options.windowsHide, 'options.windowsHide'); } // Validate windowsVerbatimArguments, if present. let { windowsVerbatimArguments } = options; - if (windowsVerbatimArguments != null && - typeof windowsVerbatimArguments !== 'boolean') { - throw new ERR_INVALID_ARG_TYPE('options.windowsVerbatimArguments', - 'boolean', - windowsVerbatimArguments); + if (windowsVerbatimArguments != null) { + validateBoolean(windowsVerbatimArguments, + 'options.windowsVerbatimArguments'); } if (options.shell) {