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 <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2019-03-20 12:15:06 +01:00
parent 9e8c9be3ff
commit 28e2c3771d
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
3 changed files with 11 additions and 11 deletions

View File

@ -41,7 +41,7 @@ const {
const { validateString, isInt32 } = require('internal/validators'); const { validateString, isInt32 } = require('internal/validators');
const child_process = require('internal/child_process'); const child_process = require('internal/child_process');
const { const {
_validateStdio, getValidStdio,
setupChannel, setupChannel,
ChildProcess ChildProcess
} = child_process; } = child_process;
@ -577,7 +577,7 @@ function spawnSync(file, args, options) {
// Validate and translate the kill signal, if present. // Validate and translate the kill signal, if present.
options.killSignal = sanitizeKillSignal(options.killSignal); options.killSignal = sanitizeKillSignal(options.killSignal);
options.stdio = _validateStdio(options.stdio || 'pipe', true).stdio; options.stdio = getValidStdio(options.stdio || 'pipe', true).stdio;
if (options.input) { if (options.input) {
var stdin = options.stdio[0] = { ...options.stdio[0] }; var stdin = options.stdio[0] = { ...options.stdio[0] };

View File

@ -315,7 +315,7 @@ ChildProcess.prototype.spawn = function(options) {
// If no `stdio` option was given - use default // If no `stdio` option was given - use default
var stdio = options.stdio || 'pipe'; var stdio = options.stdio || 'pipe';
stdio = _validateStdio(stdio, false); stdio = getValidStdio(stdio, false);
ipc = stdio.ipc; ipc = stdio.ipc;
ipcFd = stdio.ipcFd; ipcFd = stdio.ipcFd;
@ -873,7 +873,7 @@ function isInternal(message) {
function nop() { } function nop() { }
function _validateStdio(stdio, sync) { function getValidStdio(stdio, sync) {
var ipc; var ipc;
var ipcFd; var ipcFd;
@ -1028,6 +1028,6 @@ function spawnSync(opts) {
module.exports = { module.exports = {
ChildProcess, ChildProcess,
setupChannel, setupChannel,
_validateStdio, getValidStdio,
spawnSync spawnSync
}; };

View File

@ -3,21 +3,21 @@
const common = require('../common'); const common = require('../common');
const assert = require('assert'); const assert = require('assert');
const _validateStdio = require('internal/child_process')._validateStdio; const getValidStdio = require('internal/child_process').getValidStdio;
const expectedError = const expectedError =
common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }, 2); common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }, 2);
// Should throw if string and not ignore, pipe, or inherit // 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 // 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 // Should populate stdio with undefined if len < 3
{ {
const stdio1 = []; const stdio1 = [];
const result = _validateStdio(stdio1, false); const result = getValidStdio(stdio1, false);
assert.strictEqual(stdio1.length, 3); assert.strictEqual(stdio1.length, 3);
assert.strictEqual(result.hasOwnProperty('stdio'), true); assert.strictEqual(result.hasOwnProperty('stdio'), true);
assert.strictEqual(result.hasOwnProperty('ipc'), 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 // Should throw if stdio has ipc and sync is true
const stdio2 = ['ipc', 'ipc', 'ipc']; const stdio2 = ['ipc', 'ipc', 'ipc'];
common.expectsError(() => _validateStdio(stdio2, true), common.expectsError(() => getValidStdio(stdio2, true),
{ code: 'ERR_IPC_SYNC_FORK', type: Error } { code: 'ERR_IPC_SYNC_FORK', type: Error }
); );
if (common.isMainThread) { if (common.isMainThread) {
const stdio3 = [process.stdin, process.stdout, process.stderr]; const stdio3 = [process.stdin, process.stdout, process.stderr];
const result = _validateStdio(stdio3, false); const result = getValidStdio(stdio3, false);
assert.deepStrictEqual(result, { assert.deepStrictEqual(result, {
stdio: [ stdio: [
{ type: 'fd', fd: 0 }, { type: 'fd', fd: 0 },