From a31f2f7e5b04e0b3e129c46ab580e4f63e71d04e Mon Sep 17 00:00:00 2001 From: ishabi Date: Sun, 21 Dec 2025 15:21:32 +0100 Subject: [PATCH 1/2] test: add implicit test for fs dispose handling with using --- .../test-fs-promises-file-handle-dispose.js | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-promises-file-handle-dispose.js b/test/parallel/test-fs-promises-file-handle-dispose.js index 3e7ef3066a7c86..91b677fdec3c68 100644 --- a/test/parallel/test-fs-promises-file-handle-dispose.js +++ b/test/parallel/test-fs-promises-file-handle-dispose.js @@ -22,5 +22,26 @@ async function explicitCall() { assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' }); } +async function implicitCall() { + { + await using fh = await fs.open(__filename); + fh.on('close', common.mustCall()); + } + + let dh; + { + await using dirHandle = await fs.opendir(__dirname); + dh = dirHandle; + } + await assert.rejects(dh.read(), { code: 'ERR_DIR_CLOSED' }); + + let dhSync; + { + using dirHandleSync = opendirSync(__dirname); + dhSync = dirHandleSync; + } + assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' }); +} + explicitCall().then(common.mustCall()); -// TODO(aduh95): add test for implicit calls, with `await using` syntax. +implicitCall().then(common.mustCall()); From 1d85d2c5ab030a9fbcc7e0f10be5d2584a80d053 Mon Sep 17 00:00:00 2001 From: ishabi Date: Tue, 23 Dec 2025 19:25:52 +0100 Subject: [PATCH 2/2] test: ensure immediate disposal of filehandle --- test/parallel/test-fs-promises-file-handle-dispose.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/parallel/test-fs-promises-file-handle-dispose.js b/test/parallel/test-fs-promises-file-handle-dispose.js index 91b677fdec3c68..fa1eba0138f651 100644 --- a/test/parallel/test-fs-promises-file-handle-dispose.js +++ b/test/parallel/test-fs-promises-file-handle-dispose.js @@ -23,10 +23,13 @@ async function explicitCall() { } async function implicitCall() { + let fh; { - await using fh = await fs.open(__filename); + await using openHandle = await fs.open(__filename); + fh = openHandle; fh.on('close', common.mustCall()); } + assert.strictEqual(fh.fd, -1); let dh; {