| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6769,8 +6769,8 @@ changes: | |||
| 6769 | 6769 | description: No longer experimental. | |
| 6770 | 6770 | --> | |
| 6771 | 6771 | ||
| 6772 | - Calls `dir.close()` and returns a promise that fulfills when the | ||
| 6773 | - dir is closed. | ||
| 6772 | + Calls `dir.close()` if the directory handle is open, and returns a promise that | ||
| 6773 | + fulfills when disposal is complete. | ||
| 6774 | 6774 | ||
| 6775 | 6775 | #### `dir[Symbol.dispose]()` | |
| 6776 | 6776 | ||
@@ -6782,7 +6782,8 @@ changes: | |||
| 6782 | 6782 | description: No longer experimental. | |
| 6783 | 6783 | --> | |
| 6784 | 6784 | ||
| 6785 | - Calls `dir.closeSync()` and returns `undefined`. | ||
| 6785 | + Calls `dir.closeSync()` if the directory handle is open, and returns | ||
| 6786 | + `undefined`. | ||
| 6786 | 6787 | ||
| 6787 | 6788 | ### Class: `fs.Dirent` | |
| 6788 | 6789 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ const { | |||
| 24 | 24 | ||
| 25 | 25 | const { FSReqCallback } = binding; | |
| 26 | 26 | const { | |
| 27 | - assignFunctionName, | ||
| 28 | 27 | promisify, | |
| 29 | 28 | } = require('internal/util'); | |
| 30 | 29 | const { | |
@@ -296,31 +295,24 @@ class Dir { | |||
| 296 | 295 | await this.#closePromisified(); | |
| 297 | 296 | } | |
| 298 | 297 | } | |
| 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 | + } | ||
| 299 | 308 | } | |
| 300 | 309 | ||
| 301 | - const nonEnumerableDescriptor = { | ||
| 302 | - enumerable: false, | ||
| 303 | - writable: true, | ||
| 304 | - configurable: true, | ||
| 305 | - }; | ||
| 306 | 310 | 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 | - }, | ||
| 321 | 311 | [SymbolAsyncIterator]: { | |
| 322 | 312 | __proto__: null, | |
| 323 | - ...nonEnumerableDescriptor, | ||
| 313 | + enumerable: false, | ||
| 314 | + writable: true, | ||
| 315 | + configurable: true, | ||
| 324 | 316 | value: Dir.prototype.entries, | |
| 325 | 317 | }, | |
| 326 | 318 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,14 @@ async function explicitCall() { | |||
| 11 | 11 | ||
| 12 | 12 | const dh = await fs.opendir(__dirname); | |
| 13 | 13 | await dh[Symbol.asyncDispose](); | |
| 14 | + // Repeat invocations should not reject | ||
| 15 | + await dh[Symbol.asyncDispose](); | ||
| 14 | 16 | await assert.rejects(dh.read(), { code: 'ERR_DIR_CLOSED' }); | |
| 15 | 17 | ||
| 16 | 18 | const dhSync = opendirSync(__dirname); | |
| 17 | 19 | dhSync[Symbol.dispose](); | |
| 20 | + // Repeat invocations should not throw | ||
| 21 | + dhSync[Symbol.dispose](); | ||
| 18 | 22 | assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' }); | |
| 19 | 23 | } | |
| 20 | 24 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments