Skip to content

Commit 2c94e58

Browse files
committed
lib: use validators for argument validation
This refactors internal validation helpers in `child_process` to use the common validators in `lib/internal/validators.js` where possible. This improves code consistency and maintainability.
1 parent 7079041 commit 2c94e58

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

lib/child_process.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const {
3333
ArrayPrototypeSort,
3434
ArrayPrototypeSplice,
3535
ArrayPrototypeUnshift,
36-
NumberIsInteger,
3736
ObjectAssign,
3837
ObjectDefineProperty,
3938
ObjectPrototypeHasOwnProperty,
@@ -70,18 +69,19 @@ const {
7069
ERR_CHILD_PROCESS_STDIO_MAXBUFFER,
7170
ERR_INVALID_ARG_TYPE,
7271
ERR_INVALID_ARG_VALUE,
73-
ERR_OUT_OF_RANGE,
7472
},
7573
genericNodeError,
7674
} = require('internal/errors');
7775
const { clearTimeout, setTimeout } = require('timers');
7876
const { getValidatedPath } = require('internal/fs/utils');
7977
const {
80-
isInt32,
8178
validateAbortSignal,
8279
validateArray,
8380
validateBoolean,
8481
validateFunction,
82+
validateInteger,
83+
validateInt32,
84+
validateNumber,
8585
validateObject,
8686
validateString,
8787
} = require('internal/validators');
@@ -603,13 +603,13 @@ function normalizeSpawnArguments(file, args, options) {
603603
}
604604

605605
// Validate the uid, if present.
606-
if (options.uid != null && !isInt32(options.uid)) {
607-
throw new ERR_INVALID_ARG_TYPE('options.uid', 'int32', options.uid);
606+
if (options.uid != null) {
607+
validateInt32(options.uid, 'options.uid');
608608
}
609609

610610
// Validate the gid, if present.
611-
if (options.gid != null && !isInt32(options.gid)) {
612-
throw new ERR_INVALID_ARG_TYPE('options.gid', 'int32', options.gid);
611+
if (options.gid != null) {
612+
validateInt32(options.gid, 'options.gid');
613613
}
614614

615615
// Validate the shell, if present.
@@ -1017,17 +1017,15 @@ function validateArgumentsNullCheck(args, propName) {
10171017

10181018

10191019
function validateTimeout(timeout) {
1020-
if (timeout != null && !(NumberIsInteger(timeout) && timeout >= 0)) {
1021-
throw new ERR_OUT_OF_RANGE('timeout', 'an unsigned integer', timeout);
1020+
if (timeout != null) {
1021+
validateInteger(timeout, 'timeout', 0);
10221022
}
10231023
}
10241024

10251025

10261026
function validateMaxBuffer(maxBuffer) {
1027-
if (maxBuffer != null && !(typeof maxBuffer === 'number' && maxBuffer >= 0)) {
1028-
throw new ERR_OUT_OF_RANGE('options.maxBuffer',
1029-
'a positive number',
1030-
maxBuffer);
1027+
if (maxBuffer != null) {
1028+
validateNumber(maxBuffer, 'options.maxBuffer', 0);
10311029
}
10321030
}
10331031

0 commit comments

Comments
 (0)