mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

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>
28 lines
856 B
JavaScript
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);
|