File tree 3 files changed +54
-7
lines changed
3 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -6740,6 +6740,26 @@ provided by the operating system's underlying directory mechanisms.
6740
6740
Entries added or removed while iterating over the directory might not be
6741
6741
included in the iteration results.
6742
6742
6743
+ #### ` dir[Symbol .asyncDispose ]()`
6744
+
6745
+ <!-- YAML
6746
+ added: REPLACEME
6747
+ -->
6748
+
6749
+ > Stability: 1 - Experimental
6750
+
6751
+ An alias for ` dir .close ()` .
6752
+
6753
+ #### ` dir[Symbol .Dispose ]()`
6754
+
6755
+ <!-- YAML
6756
+ added: REPLACEME
6757
+ -->
6758
+
6759
+ > Stability: 1 - Experimental
6760
+
6761
+ An alias for ` dir .closeSync ()` .
6762
+
6743
6763
### Class: ` fs .Dirent `
6744
6764
6745
6765
<!-- 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