1// Flags: --expose-gc --no-warnings --expose-internals 2'use strict'; 3 4const common = require('../common'); 5const assert = require('assert'); 6const path = require('path'); 7const { internalBinding } = require('internal/test/binding'); 8const fs = internalBinding('fs'); 9const { stringToFlags } = require('internal/fs/utils'); 10 11// Verifies that the FileHandle object is garbage collected and that a 12// warning is emitted if it is not closed. 13 14let fdnum; 15{ 16 const ctx = {}; 17 fdnum = fs.openFileHandle(path.toNamespacedPath(__filename), 18 stringToFlags('r'), 0o666, undefined, ctx).fd; 19 assert.strictEqual(ctx.errno, undefined); 20} 21 22const deprecationWarning = 23 'Closing a FileHandle object on garbage collection is deprecated. ' + 24 'Please close FileHandle objects explicitly using ' + 25 'FileHandle.prototype.close(). In the future, an error will be ' + 26 'thrown if a file descriptor is closed during garbage collection.'; 27 28common.expectWarning({ 29 'internal/test/binding': [ 30 'These APIs are for internal testing only. Do not use them.', 31 ], 32 'Warning': [ 33 `Closing file descriptor ${fdnum} on garbage collection`, 34 ], 35 'DeprecationWarning': [[deprecationWarning, 'DEP0137']] 36}); 37 38global.gc(); 39 40setTimeout(() => {}, 10); 41