node/test/parallel/test-fs-filehandle.js
James M Snell 2bb7667475 fs: move FileHandle close on GC to EOL
Automatically closing a FileHandle on garbage collection
has been deprecated for some time now. We've said that
it will eventually be removed and become and error.

PR-URL: https://github.com/nodejs/node/pull/58536
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2025-06-25 17:00:25 +01:00

28 lines
856 B
JavaScript

// Flags: --expose-gc --no-warnings --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const { internalBinding } = require('internal/test/binding');
const fs = internalBinding('fs');
const { stringToFlags } = require('internal/fs/utils');
// Verifies that the FileHandle object is garbage collected and that an
// error is thrown if it is not closed.
process.on('uncaughtException', common.mustCall((err) => {
assert.strictEqual(err.code, 'ERR_INVALID_STATE');
assert.match(err.message, /^A FileHandle object was closed during/);
}));
{
const ctx = {};
fs.openFileHandle(path.toNamespacedPath(__filename),
stringToFlags('r'), 0o666, undefined, ctx);
assert.strictEqual(ctx.errno, undefined);
}
globalThis.gc();
setTimeout(() => {}, 10);