Skip to content

Commit dd0381f

Browse files
Masashi Hiranoaddaleax
Masashi Hirano
authored andcommitted
fs: make process.binding('fs') internal
Refs: #22160 PR-URL: #22478 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Backport-PR-URL: #25446
1 parent d7d772b commit dd0381f

16 files changed

+32
-19
lines changed

lib/fs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const {
4141

4242
const pathModule = require('path');
4343
const { isArrayBufferView } = require('internal/util/types');
44-
const binding = process.binding('fs');
44+
const binding = internalBinding('fs');
4545
const { Buffer, kMaxLength } = require('buffer');
4646
const errors = require('internal/errors');
4747
const {

lib/internal/bootstrap/loaders.js

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
'constants',
8282
'contextify',
8383
'crypto',
84+
'fs',
8485
'fs_event_wrap',
8586
'http_parser',
8687
'icu',

lib/internal/fs/promises.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
S_IFMT,
88
S_IFREG
99
} = internalBinding('constants').fs;
10-
const binding = process.binding('fs');
10+
const binding = internalBinding('fs');
1111
const { Buffer, kMaxLength } = require('buffer');
1212
const {
1313
ERR_FS_FILE_TOO_LARGE,

lib/internal/fs/read_file_context.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
const { Buffer } = require('buffer');
4-
const { FSReqCallback, close, read } = process.binding('fs');
4+
5+
const { FSReqCallback, close, read } = internalBinding('fs');
56

67
const kReadFileBufferLength = 8 * 1024;
78

lib/internal/fs/streams.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const {
44
FSReqCallback,
55
writeBuffers
6-
} = process.binding('fs');
6+
} = internalBinding('fs');
77
const {
88
ERR_INVALID_ARG_TYPE,
99
ERR_OUT_OF_RANGE

lib/internal/fs/watchers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const errors = require('internal/errors');
44
const {
55
kFsStatsFieldsNumber,
66
StatWatcher: _StatWatcher
7-
} = process.binding('fs');
7+
} = internalBinding('fs');
88
const { FSEvent } = internalBinding('fs_event_wrap');
99
const { UV_ENOSPC } = internalBinding('uv');
1010
const { EventEmitter } = require('events');

lib/internal/http2/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const {
119119
} = require('internal/timers');
120120
const { isArrayBufferView } = require('internal/util/types');
121121

122-
const { FileHandle } = process.binding('fs');
122+
const { FileHandle } = internalBinding('fs');
123123
const binding = internalBinding('http2');
124124
const {
125125
ShutdownWrap,

lib/internal/modules/cjs/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const { URL } = require('url');
3333
const {
3434
internalModuleReadJSON,
3535
internalModuleStat
36-
} = process.binding('fs');
36+
} = internalBinding('fs');
3737
const { safeGetenv } = internalBinding('util');
3838
const {
3939
makeRequireFunction,

lib/internal/net.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const Buffer = require('buffer').Buffer;
4-
const { writeBuffer } = process.binding('fs');
4+
const { writeBuffer } = internalBinding('fs');
55
const errors = require('internal/errors');
66

77
// IPv4 Segment

src/node_file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2236,4 +2236,4 @@ void Initialize(Local<Object> target,
22362236

22372237
} // end namespace node
22382238

2239-
NODE_BUILTIN_MODULE_CONTEXT_AWARE(fs, node::fs::Initialize)
2239+
NODE_MODULE_CONTEXT_AWARE_INTERNAL(fs, node::fs::Initialize)

test/parallel/test-assert.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Flags: --expose-internals
12
// Copyright Joyent, Inc. and other Node contributors.
23
//
34
// Permission is hereby granted, free of charge, to any person obtaining a
@@ -24,6 +25,7 @@
2425
const common = require('../common');
2526
const assert = require('assert');
2627
const { inspect } = require('util');
28+
const { internalBinding } = require('internal/test/binding');
2729
const a = assert;
2830

2931
// Disable colored output to prevent color codes from breaking assertion
@@ -656,7 +658,7 @@ common.expectsError(
656658

657659
{
658660
// Test caching.
659-
const fs = process.binding('fs');
661+
const fs = internalBinding('fs');
660662
const tmp = fs.close;
661663
fs.close = common.mustCall(tmp, 1);
662664
function throwErr() {

test/parallel/test-fs-filehandle.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
const common = require('../common');
55
const assert = require('assert');
66
const path = require('path');
7-
const fs = process.binding('fs');
7+
const { internalBinding } = require('internal/test/binding');
8+
const fs = internalBinding('fs');
89
const { stringToFlags } = require('internal/fs/utils');
910

1011
// Verifies that the FileHandle object is garbage collected and that a
@@ -18,11 +19,16 @@ let fdnum;
1819
assert.strictEqual(ctx.errno, undefined);
1920
}
2021

21-
common.expectWarning(
22-
'Warning',
23-
`Closing file descriptor ${fdnum} on garbage collection`,
24-
common.noWarnCode
25-
);
22+
common.expectWarning({
23+
'internal/test/binding': [
24+
'These APIs are for internal testing only. Do not use them.',
25+
common.noWarnCode
26+
],
27+
'Warning': [
28+
`Closing file descriptor ${fdnum} on garbage collection`,
29+
common.noWarnCode
30+
]
31+
});
2632

2733
global.gc();
2834

test/parallel/test-fs-sync-fd-leak.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fs.writeSync = function() {
4242
throw new Error('BAM');
4343
};
4444

45-
process.binding('fs').fstat = function(fd, bigint, _, ctx) {
45+
internalBinding('fs').fstat = function(fd, bigint, _, ctx) {
4646
ctx.errno = UV_EBADF;
4747
ctx.syscall = 'fstat';
4848
};

test/parallel/test-module-binding.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Flags: --expose-internals
12
'use strict';
23
require('../common');
34
const fixtures = require('../common/fixtures');
4-
const { internalModuleReadJSON } = process.binding('fs');
5+
const { internalBinding } = require('internal/test/binding');
6+
const { internalModuleReadJSON } = internalBinding('fs');
57
const { readFileSync } = require('fs');
68
const { strictEqual } = require('assert');
79

test/parallel/test-process-binding-internalbinding-whitelist.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ assert(process.binding('url'));
1616
assert(process.binding('spawn_sync'));
1717
assert(process.binding('js_stream'));
1818
assert(process.binding('buffer'));
19+
assert(process.binding('fs'));

test/sequential/test-async-wrap-getasyncid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ if (common.hasCrypto) { // eslint-disable-line node-core/crypto-check
132132

133133

134134
{
135-
const binding = process.binding('fs');
135+
const binding = internalBinding('fs');
136136
const path = require('path');
137137

138138
const FSReqCallback = binding.FSReqCallback;

0 commit comments

Comments
 (0)