fs: make `Dir` disposers idempotent · nodejs/node@96c78d7 · GitHub
Skip to content

Commit 96c78d7

Browse files
Renegade334RafaelGSS
authored andcommitted
fs: make Dir disposers idempotent
PR-URL: #58692 Refs: #58206 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent fa6854f commit 96c78d7

3 files changed

Lines changed: 21 additions & 24 deletions

File tree

doc/api/fs.md

Lines changed: 4 additions & 3 deletions

lib/internal/fs/dir.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const {
2424

2525
const { FSReqCallback } = binding;
2626
const {
27-
assignFunctionName,
2827
promisify,
2928
} = require('internal/util');
3029
const {
@@ -296,31 +295,24 @@ class Dir {
296295
await this.#closePromisified();
297296
}
298297
}
298+
299+
[SymbolDispose]() {
300+
if (this.#closed) return;
301+
this.closeSync();
302+
}
303+
304+
async [SymbolAsyncDispose]() {
305+
if (this.#closed) return;
306+
await this.#closePromisified();
307+
}
299308
}
300309

301-
const nonEnumerableDescriptor = {
302-
enumerable: false,
303-
writable: true,
304-
configurable: true,
305-
};
306310
ObjectDefineProperties(Dir.prototype, {
307-
[SymbolDispose]: {
308-
__proto__: null,
309-
...nonEnumerableDescriptor,
310-
value: assignFunctionName(SymbolDispose, function() {
311-
this.closeSync();
312-
}),
313-
},
314-
[SymbolAsyncDispose]: {
315-
__proto__: null,
316-
...nonEnumerableDescriptor,
317-
value: assignFunctionName(SymbolAsyncDispose, function() {
318-
this.close();
319-
}),
320-
},
321311
[SymbolAsyncIterator]: {
322312
__proto__: null,
323-
...nonEnumerableDescriptor,
313+
enumerable: false,
314+
writable: true,
315+
configurable: true,
324316
value: Dir.prototype.entries,
325317
},
326318
});

test/parallel/test-fs-promises-file-handle-dispose.js

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)