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 22common.expectWarning({ 23 'internal/test/binding': [ 24 'These APIs are for internal testing only. Do not use them.' 25 ], 26 'Warning': [ 27 `Closing file descriptor ${fdnum} on garbage collection` 28 ] 29}); 30 31global.gc(); 32 33setTimeout(() => {}, 10); 34