From 28e2c3771d3da014c35b57cc55f7808627e43f2d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 20 Mar 2019 12:15:06 +0100 Subject: [PATCH] child_process: rename _validateStdtio to getValidStdio The name indicated only validation while it did much more and it returned a different value to the callee function. The underscore was also not necessary as the function is internal one way or the other. PR-URL: https://github.com/nodejs/node/pull/26809 Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- lib/child_process.js | 4 ++-- lib/internal/child_process.js | 6 +++--- test/parallel/test-child-process-validate-stdio.js | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 8f16b707ea8ac6..683b4aec319140 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -41,7 +41,7 @@ const { const { validateString, isInt32 } = require('internal/validators'); const child_process = require('internal/child_process'); const { - _validateStdio, + getValidStdio, setupChannel, ChildProcess } = child_process; @@ -577,7 +577,7 @@ function spawnSync(file, args, options) { // Validate and translate the kill signal, if present. options.killSignal = sanitizeKillSignal(options.killSignal); - options.stdio = _validateStdio(options.stdio || 'pipe', true).stdio; + options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio; if (options.input) { var stdin = options.stdio[0] = { ...options.stdio[0] }; diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 0894fd1bcf0d9e..dddfd7cbeceb73 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -315,7 +315,7 @@ ChildProcess.prototype.spawn = function(options) { // If no `stdio` option was given - use default var stdio = options.stdio || 'pipe'; - stdio = _validateStdio(stdio, false); + stdio = getValidStdio(stdio, false); ipc = stdio.ipc; ipcFd = stdio.ipcFd; @@ -873,7 +873,7 @@ function isInternal(message) { function nop() { } -function _validateStdio(stdio, sync) { +function getValidStdio(stdio, sync) { var ipc; var ipcFd; @@ -1028,6 +1028,6 @@ function spawnSync(opts) { module.exports = { ChildProcess, setupChannel, - _validateStdio, + getValidStdio, spawnSync }; diff --git a/test/parallel/test-child-process-validate-stdio.js b/test/parallel/test-child-process-validate-stdio.js index 3566c8f9520f30..23b3fe2c95a877 100644 --- a/test/parallel/test-child-process-validate-stdio.js +++ b/test/parallel/test-child-process-validate-stdio.js @@ -3,21 +3,21 @@ const common = require('../common'); const assert = require('assert'); -const _validateStdio = require('internal/child_process')._validateStdio; +const getValidStdio = require('internal/child_process').getValidStdio; const expectedError = common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }, 2); // Should throw if string and not ignore, pipe, or inherit -assert.throws(() => _validateStdio('foo'), expectedError); +assert.throws(() => getValidStdio('foo'), expectedError); // Should throw if not a string or array -assert.throws(() => _validateStdio(600), expectedError); +assert.throws(() => getValidStdio(600), expectedError); // Should populate stdio with undefined if len < 3 { const stdio1 = []; - const result = _validateStdio(stdio1, false); + const result = getValidStdio(stdio1, false); assert.strictEqual(stdio1.length, 3); assert.strictEqual(result.hasOwnProperty('stdio'), true); assert.strictEqual(result.hasOwnProperty('ipc'), true); @@ -26,14 +26,14 @@ assert.throws(() => _validateStdio(600), expectedError); // Should throw if stdio has ipc and sync is true const stdio2 = ['ipc', 'ipc', 'ipc']; -common.expectsError(() => _validateStdio(stdio2, true), +common.expectsError(() => getValidStdio(stdio2, true), { code: 'ERR_IPC_SYNC_FORK', type: Error } ); if (common.isMainThread) { const stdio3 = [process.stdin, process.stdout, process.stderr]; - const result = _validateStdio(stdio3, false); + const result = getValidStdio(stdio3, false); assert.deepStrictEqual(result, { stdio: [ { type: 'fd', fd: 0 },