Skip to content

Commit 558dd48

Browse files
committed
fs: validate options in promises stat, lstat and fstat
Add validateObject before reading options.signal in the promises stat, lstat and fstat, matching the rest of the module. Import the PromiseWithResolvers primordial and drop the now-unused kResistStopPropagation left over from the raceWithSignal rewrite.
1 parent 3308f44 commit 558dd48

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

lib/internal/fs/promises.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
PromisePrototypeThen,
1313
PromiseReject,
1414
PromiseResolve,
15+
PromiseWithResolvers,
1516
SafeArrayIterator,
1617
SafePromisePrototypeFinally,
1718
SafePromiseRace,
@@ -126,7 +127,6 @@ const kLocked = Symbol('kLocked');
126127
const kCloseSync = Symbol('kCloseSync');
127128

128129
const { kUsePromises } = binding;
129-
let kResistStopPropagation;
130130
const { Interface } = require('internal/readline/interface');
131131
const {
132132
kDeserialize, kTransfer, kTransferList, markTransferMode,
@@ -1121,6 +1121,7 @@ function checkAborted(signal) {
11211121
async function raceWithSignal(opPromise, signal) {
11221122
if (!signal) return opPromise;
11231123
const { promise: abortPromise, reject } = PromiseWithResolvers();
1124+
// eslint-disable-next-line no-unused-vars
11241125
using _ = EventEmitter.addAbortListener(signal, () => reject(new AbortError(undefined, { cause: signal.reason })));
11251126
return await SafePromiseRace([opPromise, abortPromise]);
11261127
}
@@ -1663,7 +1664,8 @@ async function symlink(target, path, type) {
16631664
}
16641665

16651666
async function fstat(handle, options = { bigint: false }) {
1666-
const signal = options?.signal;
1667+
validateObject(options, 'options');
1668+
const { signal } = options;
16671669
if (signal !== undefined) validateAbortSignal(signal, 'options.signal');
16681670
checkAborted(signal);
16691671
const result = await raceWithSignal(
@@ -1678,7 +1680,8 @@ async function fstat(handle, options = { bigint: false }) {
16781680
}
16791681

16801682
async function lstat(path, options = { bigint: false }) {
1681-
const signal = options?.signal;
1683+
validateObject(options, 'options');
1684+
const { signal } = options;
16821685
if (signal !== undefined) validateAbortSignal(signal, 'options.signal');
16831686
checkAborted(signal);
16841687
path = getValidatedPath(path);
@@ -1698,7 +1701,8 @@ async function lstat(path, options = { bigint: false }) {
16981701
}
16991702

17001703
async function stat(path, options = { bigint: false, throwIfNoEntry: true }) {
1701-
const signal = options?.signal;
1704+
validateObject(options, 'options');
1705+
const { signal } = options;
17021706
if (signal !== undefined) validateAbortSignal(signal, 'options.signal');
17031707
checkAborted(signal);
17041708
const result = await raceWithSignal(

0 commit comments

Comments
 (0)