Skip to content

Commit cce3af9

Browse files
committed
lib: make validateAbortSignal stricter
We should not force-check if the passed signal is **NOT** undefined and then proceed to check whether the value is an abort signal or not as the validator won't throw an error if the value is undefined as we straight up validate the values instead of checking if they're not undefined first. This unnecessary check can be done explicitly outside of the validator to only pass the value to the validator if its not undefined.
1 parent e937662 commit cce3af9

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lib/child_process.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,9 @@ function abortChildProcess(child, killSignal) {
690690
function spawn(file, args, options) {
691691
options = normalizeSpawnArguments(file, args, options);
692692
validateTimeout(options.timeout);
693-
validateAbortSignal(options.signal, 'options.signal');
693+
if (options.signal !== undefined)
694+
validateAbortSignal(options.signal, 'options.signal');
695+
694696
const killSignal = sanitizeKillSignal(options.killSignal);
695697
const child = new ChildProcess();
696698

lib/internal/fs/promises.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,8 @@ async function writeFile(path, data, options) {
813813
data = Buffer.from(data, options.encoding || 'utf8');
814814
}
815815

816-
validateAbortSignal(options.signal);
816+
if (options.signal !== undefined)
817+
validateAbortSignal(options.signal);
817818
if (path instanceof FileHandle)
818819
return writeFileHandle(path, data, options.signal, options.encoding);
819820

lib/internal/validators.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,8 @@ const validateCallback = hideStackFrames((callback) => {
224224
});
225225

226226
const validateAbortSignal = hideStackFrames((signal, name) => {
227-
if (signal !== undefined &&
228-
(signal === null ||
229-
typeof signal !== 'object' ||
230-
!('aborted' in signal))) {
227+
if (signal === null || typeof signal !== 'object' ||
228+
!('aborted' in signal)) {
231229
throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal);
232230
}
233231
});

0 commit comments

Comments
 (0)