Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion test/parallel/test-fs-promises-file-handle-dispose.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,29 @@ async function explicitCall() {
assert.throws(() => dhSync.readSync(), { code: 'ERR_DIR_CLOSED' });
}

async function implicitCall() {
let fh;
{
await using openHandle = await fs.open(__filename);
fh = openHandle;
fh.on('close', common.mustCall());
}
assert.strictEqual(fh.fd, -1);

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());
Loading