2018-01-21 18:21:25 +00:00
|
|
|
// Flags: --expose-gc --no-warnings --expose-internals
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2018-02-14 19:29:05 +00:00
|
|
|
const assert = require('assert');
|
2018-01-21 18:21:25 +00:00
|
|
|
const path = require('path');
|
2018-08-23 14:29:40 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
|
|
|
const fs = internalBinding('fs');
|
2018-05-03 18:40:48 +00:00
|
|
|
const { stringToFlags } = require('internal/fs/utils');
|
2018-01-21 18:21:25 +00:00
|
|
|
|
|
|
|
// Verifies that the FileHandle object is garbage collected and that a
|
|
|
|
// warning is emitted if it is not closed.
|
|
|
|
|
|
|
|
let fdnum;
|
|
|
|
{
|
2018-02-14 19:29:05 +00:00
|
|
|
const ctx = {};
|
2018-01-21 18:21:25 +00:00
|
|
|
fdnum = fs.openFileHandle(path.toNamespacedPath(__filename),
|
2018-02-14 19:29:05 +00:00
|
|
|
stringToFlags('r'), 0o666, undefined, ctx).fd;
|
|
|
|
assert.strictEqual(ctx.errno, undefined);
|
2018-01-21 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
2019-06-23 13:35:04 +00:00
|
|
|
const deprecationWarning =
|
|
|
|
'Closing a FileHandle object on garbage collection is deprecated. ' +
|
|
|
|
'Please close FileHandle objects explicitly using ' +
|
|
|
|
'FileHandle.prototype.close(). In the future, an error will be ' +
|
|
|
|
'thrown if a file descriptor is closed during garbage collection.';
|
|
|
|
|
2018-08-23 14:29:40 +00:00
|
|
|
common.expectWarning({
|
|
|
|
'internal/test/binding': [
|
2021-03-26 15:51:08 +00:00
|
|
|
'These APIs are for internal testing only. Do not use them.',
|
2018-08-23 14:29:40 +00:00
|
|
|
],
|
|
|
|
'Warning': [
|
2021-03-26 15:51:08 +00:00
|
|
|
`Closing file descriptor ${fdnum} on garbage collection`,
|
2019-06-23 13:35:04 +00:00
|
|
|
],
|
2020-02-07 15:07:02 +00:00
|
|
|
'DeprecationWarning': [[deprecationWarning, 'DEP0137']]
|
2018-08-23 14:29:40 +00:00
|
|
|
});
|
2018-01-21 18:21:25 +00:00
|
|
|
|
2018-12-13 13:36:42 +00:00
|
|
|
global.gc();
|
2018-01-21 18:21:25 +00:00
|
|
|
|
|
|
|
setTimeout(() => {}, 10);
|