fs: make process.binding('fs') internal
Refs: https://github.com/nodejs/node/issues/22160 PR-URL: https://github.com/nodejs/node/pull/22478 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
This commit is contained in:
parent
9bce68663b
commit
1e23e3ceb3
@ -42,7 +42,7 @@ const {
|
|||||||
const { _extend } = require('util');
|
const { _extend } = require('util');
|
||||||
const pathModule = require('path');
|
const pathModule = require('path');
|
||||||
const { isArrayBufferView } = require('internal/util/types');
|
const { isArrayBufferView } = require('internal/util/types');
|
||||||
const binding = process.binding('fs');
|
const binding = internalBinding('fs');
|
||||||
const { Buffer, kMaxLength } = require('buffer');
|
const { Buffer, kMaxLength } = require('buffer');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
const {
|
const {
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
'constants',
|
'constants',
|
||||||
'contextify',
|
'contextify',
|
||||||
'crypto',
|
'crypto',
|
||||||
|
'fs',
|
||||||
'fs_event_wrap',
|
'fs_event_wrap',
|
||||||
'http_parser',
|
'http_parser',
|
||||||
'icu',
|
'icu',
|
||||||
|
@ -7,7 +7,7 @@ const {
|
|||||||
S_IFMT,
|
S_IFMT,
|
||||||
S_IFREG
|
S_IFREG
|
||||||
} = internalBinding('constants').fs;
|
} = internalBinding('constants').fs;
|
||||||
const binding = process.binding('fs');
|
const binding = internalBinding('fs');
|
||||||
const { Buffer, kMaxLength } = require('buffer');
|
const { Buffer, kMaxLength } = require('buffer');
|
||||||
const {
|
const {
|
||||||
ERR_FS_FILE_TOO_LARGE,
|
ERR_FS_FILE_TOO_LARGE,
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { Buffer } = require('buffer');
|
const { Buffer } = require('buffer');
|
||||||
const { FSReqCallback, close, read } = process.binding('fs');
|
|
||||||
|
const { FSReqCallback, close, read } = internalBinding('fs');
|
||||||
|
|
||||||
const kReadFileBufferLength = 8 * 1024;
|
const kReadFileBufferLength = 8 * 1024;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
const {
|
const {
|
||||||
FSReqCallback,
|
FSReqCallback,
|
||||||
writeBuffers
|
writeBuffers
|
||||||
} = process.binding('fs');
|
} = internalBinding('fs');
|
||||||
const {
|
const {
|
||||||
ERR_INVALID_ARG_TYPE,
|
ERR_INVALID_ARG_TYPE,
|
||||||
ERR_OUT_OF_RANGE
|
ERR_OUT_OF_RANGE
|
||||||
|
@ -4,7 +4,7 @@ const errors = require('internal/errors');
|
|||||||
const {
|
const {
|
||||||
kFsStatsFieldsNumber,
|
kFsStatsFieldsNumber,
|
||||||
StatWatcher: _StatWatcher
|
StatWatcher: _StatWatcher
|
||||||
} = process.binding('fs');
|
} = internalBinding('fs');
|
||||||
const { FSEvent } = internalBinding('fs_event_wrap');
|
const { FSEvent } = internalBinding('fs_event_wrap');
|
||||||
const { UV_ENOSPC } = internalBinding('uv');
|
const { UV_ENOSPC } = internalBinding('uv');
|
||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
|
@ -118,7 +118,7 @@ const {
|
|||||||
} = require('internal/timers');
|
} = require('internal/timers');
|
||||||
const { isArrayBufferView } = require('internal/util/types');
|
const { isArrayBufferView } = require('internal/util/types');
|
||||||
|
|
||||||
const { FileHandle } = process.binding('fs');
|
const { FileHandle } = internalBinding('fs');
|
||||||
const binding = internalBinding('http2');
|
const binding = internalBinding('http2');
|
||||||
const {
|
const {
|
||||||
ShutdownWrap,
|
ShutdownWrap,
|
||||||
|
@ -33,7 +33,7 @@ const { URL } = require('url');
|
|||||||
const {
|
const {
|
||||||
internalModuleReadJSON,
|
internalModuleReadJSON,
|
||||||
internalModuleStat
|
internalModuleStat
|
||||||
} = process.binding('fs');
|
} = internalBinding('fs');
|
||||||
const { safeGetenv } = internalBinding('util');
|
const { safeGetenv } = internalBinding('util');
|
||||||
const {
|
const {
|
||||||
makeRequireFunction,
|
makeRequireFunction,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Buffer = require('buffer').Buffer;
|
const Buffer = require('buffer').Buffer;
|
||||||
const { writeBuffer } = process.binding('fs');
|
const { writeBuffer } = internalBinding('fs');
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
|
|
||||||
// IPv4 Segment
|
// IPv4 Segment
|
||||||
|
@ -2236,4 +2236,4 @@ void Initialize(Local<Object> target,
|
|||||||
|
|
||||||
} // end namespace node
|
} // end namespace node
|
||||||
|
|
||||||
NODE_BUILTIN_MODULE_CONTEXT_AWARE(fs, node::fs::Initialize)
|
NODE_MODULE_CONTEXT_AWARE_INTERNAL(fs, node::fs::Initialize)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
// Copyright Joyent, Inc. and other Node contributors.
|
// Copyright Joyent, Inc. and other Node contributors.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
@ -26,6 +27,7 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const { inspect } = require('util');
|
const { inspect } = require('util');
|
||||||
|
const { internalBinding } = require('internal/test/binding');
|
||||||
const a = assert;
|
const a = assert;
|
||||||
|
|
||||||
// Disable colored output to prevent color codes from breaking assertion
|
// Disable colored output to prevent color codes from breaking assertion
|
||||||
@ -658,7 +660,7 @@ common.expectsError(
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Test caching.
|
// Test caching.
|
||||||
const fs = process.binding('fs');
|
const fs = internalBinding('fs');
|
||||||
const tmp = fs.close;
|
const tmp = fs.close;
|
||||||
fs.close = common.mustCall(tmp, 1);
|
fs.close = common.mustCall(tmp, 1);
|
||||||
function throwErr() {
|
function throwErr() {
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = process.binding('fs');
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const fs = internalBinding('fs');
|
||||||
const { stringToFlags } = require('internal/fs/utils');
|
const { stringToFlags } = require('internal/fs/utils');
|
||||||
|
|
||||||
// Verifies that the FileHandle object is garbage collected and that a
|
// Verifies that the FileHandle object is garbage collected and that a
|
||||||
@ -18,11 +19,17 @@ let fdnum;
|
|||||||
assert.strictEqual(ctx.errno, undefined);
|
assert.strictEqual(ctx.errno, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
common.expectWarning(
|
common.expectWarning({
|
||||||
'Warning',
|
'internal/test/binding': [
|
||||||
|
'These APIs are exposed only for testing ' +
|
||||||
|
'and are not tracked by any versioning system or deprecation process.',
|
||||||
|
common.noWarnCode
|
||||||
|
],
|
||||||
|
'Warning': [
|
||||||
`Closing file descriptor ${fdnum} on garbage collection`,
|
`Closing file descriptor ${fdnum} on garbage collection`,
|
||||||
common.noWarnCode
|
common.noWarnCode
|
||||||
);
|
]
|
||||||
|
});
|
||||||
|
|
||||||
gc(); // eslint-disable-line no-undef
|
gc(); // eslint-disable-line no-undef
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ fs.writeSync = function() {
|
|||||||
throw new Error('BAM');
|
throw new Error('BAM');
|
||||||
};
|
};
|
||||||
|
|
||||||
process.binding('fs').fstat = function(fd, bigint, _, ctx) {
|
internalBinding('fs').fstat = function(fd, bigint, _, ctx) {
|
||||||
ctx.errno = UV_EBADF;
|
ctx.errno = UV_EBADF;
|
||||||
ctx.syscall = 'fstat';
|
ctx.syscall = 'fstat';
|
||||||
};
|
};
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
require('../common');
|
||||||
const fixtures = require('../common/fixtures');
|
const fixtures = require('../common/fixtures');
|
||||||
const { internalModuleReadJSON } = process.binding('fs');
|
const { internalBinding } = require('internal/test/binding');
|
||||||
|
const { internalModuleReadJSON } = internalBinding('fs');
|
||||||
const { readFileSync } = require('fs');
|
const { readFileSync } = require('fs');
|
||||||
const { strictEqual } = require('assert');
|
const { strictEqual } = require('assert');
|
||||||
|
|
||||||
|
@ -16,3 +16,4 @@ assert(process.binding('url'));
|
|||||||
assert(process.binding('spawn_sync'));
|
assert(process.binding('spawn_sync'));
|
||||||
assert(process.binding('js_stream'));
|
assert(process.binding('js_stream'));
|
||||||
assert(process.binding('buffer'));
|
assert(process.binding('buffer'));
|
||||||
|
assert(process.binding('fs'));
|
||||||
|
@ -132,7 +132,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const binding = process.binding('fs');
|
const binding = internalBinding('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const FSReqCallback = binding.FSReqCallback;
|
const FSReqCallback = binding.FSReqCallback;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user