File tree Expand file tree Collapse file tree 3 files changed +54
-7
lines changed Expand file tree Collapse file tree 3 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -6736,6 +6736,26 @@ provided by the operating system's underlying directory mechanisms.
6736
6736
Entries added or removed while iterating over the directory might not be
6737
6737
included in the iteration results.
6738
6738
6739
+ #### ` dir[Symbol .asyncDispose ]()`
6740
+
6741
+ <!-- YAML
6742
+ added: REPLACEME
6743
+ -->
6744
+
6745
+ > Stability: 1 - Experimental
6746
+
6747
+ An alias for ` dir .close ()` .
6748
+
6749
+ #### ` dir[Symbol .Dispose ]()`
6750
+
6751
+ <!-- YAML
6752
+ added: REPLACEME
6753
+ -->
6754
+
6755
+ > Stability: 1 - Experimental
6756
+
6757
+ An alias for ` dir .closeSync ()` .
6758
+
6739
6759
### Class: ` fs .Dirent `
6740
6760
6741
6761
<!-- 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
+ SymbolAsyncDispose,
9
10
SymbolAsyncIterator,
11
+ SymbolDispose,
10
12
} = primordials ;
11
13
12
14
const pathModule = require ( 'path' ) ;
@@ -293,12 +295,27 @@ class Dir {
293
295
}
294
296
}
295
297
296
- ObjectDefineProperty ( Dir . prototype , SymbolAsyncIterator , {
297
- __proto__ : null ,
298
- value : Dir . prototype . entries ,
298
+ const nonEnumerableDescriptor = {
299
299
enumerable : false ,
300
300
writable : true ,
301
301
configurable : true ,
302
+ } ;
303
+ ObjectDefineProperties ( Dir . prototype , {
304
+ [ SymbolDispose ] : {
305
+ __proto__ : null ,
306
+ ...nonEnumerableDescriptor ,
307
+ value : Dir . prototype . closeSync ,
308
+ } ,
309
+ [ SymbolAsyncDispose ] : {
310
+ __proto__ : null ,
311
+ ...nonEnumerableDescriptor ,
312
+ value : Dir . prototype . close ,
313
+ } ,
314
+ [ SymbolAsyncIterator ] : {
315
+ __proto__ : null ,
316
+ ...nonEnumerableDescriptor ,
317
+ value : Dir . prototype . entries ,
318
+ } ,
302
319
} ) ;
303
320
304
321
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