File tree Expand file tree Collapse file tree 3 files changed +56
-7
lines changed Expand file tree Collapse file tree 3 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -6728,6 +6728,26 @@ provided by the operating system's underlying directory mechanisms.
6728
6728
Entries added or removed while iterating over the directory might not be
6729
6729
included in the iteration results.
6730
6730
6731
+ #### ` dir[Symbol .asyncDispose ]()`
6732
+
6733
+ <!-- YAML
6734
+ added: REPLACEME
6735
+ -->
6736
+
6737
+ > Stability: 1 - Experimental
6738
+
6739
+ An alias for ` dir .close ()` .
6740
+
6741
+ #### ` dir[Symbol .Dispose ]()`
6742
+
6743
+ <!-- YAML
6744
+ added: REPLACEME
6745
+ -->
6746
+
6747
+ > Stability: 1 - Experimental
6748
+
6749
+ An alias for ` dir .closeSync ()` .
6750
+
6731
6751
### Class: ` fs .Dirent `
6732
6752
6733
6753
<!-- YAML
Original file line number Diff line number Diff line change 4
4
ArrayPrototypePush,
5
5
ArrayPrototypeShift,
6
6
FunctionPrototypeBind,
7
- ObjectDefineProperty ,
7
+ ObjectDefineProperties ,
8
8
PromiseReject,
9
9
SymbolAsyncIterator,
10
10
} = primordials ;
@@ -31,6 +31,10 @@ const {
31
31
validateFunction,
32
32
validateUint32,
33
33
} = require ( 'internal/validators' ) ;
34
+ const {
35
+ SymbolAsyncDispose,
36
+ SymbolDispose,
37
+ } = internalUtil ;
34
38
35
39
class Dir {
36
40
#handle;
@@ -293,12 +297,27 @@ class Dir {
293
297
}
294
298
}
295
299
296
- ObjectDefineProperty ( Dir . prototype , SymbolAsyncIterator , {
297
- __proto__ : null ,
298
- value : Dir . prototype . entries ,
300
+ const nonEnumerableDescriptor = {
299
301
enumerable : false ,
300
302
writable : true ,
301
303
configurable : true ,
304
+ } ;
305
+ ObjectDefineProperties ( Dir . prototype , {
306
+ [ SymbolDispose ] : {
307
+ __proto__ : null ,
308
+ ...nonEnumerableDescriptor ,
309
+ value : Dir . prototype . closeSync ,
310
+ } ,
311
+ [ SymbolAsyncDispose ] : {
312
+ __proto__ : null ,
313
+ ...nonEnumerableDescriptor ,
314
+ value : Dir . prototype . close ,
315
+ } ,
316
+ [ SymbolAsyncIterator ] : {
317
+ __proto__ : null ,
318
+ ...nonEnumerableDescriptor ,
319
+ value : Dir . prototype . entries ,
320
+ } ,
302
321
} ) ;
303
322
304
323
function opendir ( path , options , callback ) {
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const common = require ( '../common' ) ;
4
- const { promises : fs } = require ( 'fs' ) ;
4
+ const assert = require ( 'assert' ) ;
5
+ const { opendirSync, promises : fs } = require ( 'fs' ) ;
5
6
6
- async function doOpen ( ) {
7
+ async function explicitCall ( ) {
7
8
const fh = await fs . open ( __filename ) ;
8
9
fh . on ( 'close' , common . mustCall ( ) ) ;
9
10
await fh [ Symbol . asyncDispose ] ( ) ;
11
+
12
+ const dh = await fs . opendir ( __dirname ) ;
13
+ await dh [ Symbol . asyncDispose ] ( ) ;
14
+ await assert . rejects ( dh . read ( ) , { code : 'ERR_DIR_CLOSED' } ) ;
15
+
16
+ const dhSync = opendirSync ( __dirname ) ;
17
+ dhSync [ Symbol . dispose ] ( ) ;
18
+ assert . throws ( ( ) => dhSync . readSync ( ) , { code : 'ERR_DIR_CLOSED' } ) ;
10
19
}
11
20
12
- doOpen ( ) . then ( common . mustCall ( ) ) ;
21
+ explicitCall ( ) . then ( common . mustCall ( ) ) ;
22
+ // TODO(aduh95): add test for implicit calls, with `await using` syntax.
You can’t perform that action at this time.
0 commit comments