Skip to content

Commit 3cd134c

Browse files
committed
src,lib: remove dead process.binding() code
There are no non-internal builtin modules left, so this should be safe to remove to a large degree. PR-URL: #25829 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anto Aravinth <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 24d9e9c commit 3cd134c

File tree

7 files changed

+10
-54
lines changed

7 files changed

+10
-54
lines changed

lib/internal/bootstrap/cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { NativeModule } = require('internal/bootstrap/loaders');
99
const {
1010
getCodeCache, compileFunction
1111
} = internalBinding('native_module');
12-
const { hasTracing, hasInspector } = process.binding('config');
12+
const { hasTracing, hasInspector } = internalBinding('config');
1313

1414
// Modules with source code compiled in js2c that
1515
// cannot be compiled with the code cache.

lib/internal/bootstrap/loaders.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
// This file is compiled as if it's wrapped in a function with arguments
4343
// passed by node::RunBootstrapping()
44-
/* global process, getBinding, getLinkedBinding, getInternalBinding */
44+
/* global process, getLinkedBinding, getInternalBinding */
4545
/* global experimentalModules, exposeInternals, primordials */
4646

4747
const {
@@ -108,12 +108,8 @@ const internalBindingWhitelist = new SafeSet([
108108
if (internalBindingWhitelist.has(module)) {
109109
return internalBinding(module);
110110
}
111-
let mod = bindingObj[module];
112-
if (typeof mod !== 'object') {
113-
mod = bindingObj[module] = getBinding(module);
114-
moduleLoadList.push(`Binding ${module}`);
115-
}
116-
return mod;
111+
// eslint-disable-next-line no-restricted-syntax
112+
throw new Error(`No such module: ${module}`);
117113
};
118114

119115
process._linkedBinding = function _linkedBinding(module) {

lib/internal/crypto/diffiehellman.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const {
1919
DiffieHellmanGroup: _DiffieHellmanGroup,
2020
ECDH: _ECDH,
2121
ECDHConvertKey: _ECDHConvertKey
22-
} = process.binding('crypto');
22+
} = internalBinding('crypto');
2323
const {
2424
POINT_CONVERSION_COMPRESSED,
2525
POINT_CONVERSION_HYBRID,

lib/internal/crypto/hash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const {
44
Hash: _Hash,
55
Hmac: _Hmac
6-
} = process.binding('crypto');
6+
} = internalBinding('crypto');
77

88
const {
99
getDefaultEncoding,

src/node.cc

-4
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
269269
// Create binding loaders
270270
std::vector<Local<String>> loaders_params = {
271271
env->process_string(),
272-
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
273272
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
274273
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
275274
// --experimental-modules
@@ -279,9 +278,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
279278
env->primordials_string()};
280279
std::vector<Local<Value>> loaders_args = {
281280
process,
282-
env->NewFunctionTemplate(binding::GetBinding)
283-
->GetFunction(context)
284-
.ToLocalChecked(),
285281
env->NewFunctionTemplate(binding::GetLinkedBinding)
286282
->GetFunction(context)
287283
.ToLocalChecked(),

src/node_binding.cc

+3-33
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
// function for each built-in modules explicitly in
8585
// binding::RegisterBuiltinModules(). This is only forward declaration.
8686
// The definitions are in each module's implementation when calling
87-
// the NODE_BUILTIN_MODULE_CONTEXT_AWARE.
87+
// the NODE_MODULE_CONTEXT_AWARE_INTERNAL.
8888
#define V(modname) void _register_##modname();
8989
NODE_BUILTIN_MODULES(V)
9090
#undef V
@@ -101,7 +101,6 @@ using v8::String;
101101
using v8::Value;
102102

103103
// Globals per process
104-
static node_module* modlist_builtin;
105104
static node_module* modlist_internal;
106105
static node_module* modlist_linked;
107106
static node_module* modlist_addon;
@@ -114,10 +113,7 @@ bool node_is_initialized = false;
114113
extern "C" void node_module_register(void* m) {
115114
struct node_module* mp = reinterpret_cast<struct node_module*>(m);
116115

117-
if (mp->nm_flags & NM_F_BUILTIN) {
118-
mp->nm_link = modlist_builtin;
119-
modlist_builtin = mp;
120-
} else if (mp->nm_flags & NM_F_INTERNAL) {
116+
if (mp->nm_flags & NM_F_INTERNAL) {
121117
mp->nm_link = modlist_internal;
122118
modlist_internal = mp;
123119
} else if (!node_is_initialized) {
@@ -295,11 +291,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
295291
env->ThrowError(errmsg);
296292
return false;
297293
}
298-
if (mp->nm_flags & NM_F_BUILTIN) {
299-
dlib->Close();
300-
env->ThrowError("Built-in module self-registered.");
301-
return false;
302-
}
294+
CHECK_EQ(mp->nm_flags & NM_F_BUILTIN, 0);
303295

304296
mp->nm_dso_handle = dlib->handle_;
305297
mp->nm_link = modlist_addon;
@@ -335,9 +327,6 @@ inline struct node_module* FindModule(struct node_module* list,
335327
return mp;
336328
}
337329

338-
node_module* get_builtin_module(const char* name) {
339-
return FindModule(modlist_builtin, name, NM_F_BUILTIN);
340-
}
341330
node_module* get_internal_module(const char* name) {
342331
return FindModule(modlist_internal, name, NM_F_INTERNAL);
343332
}
@@ -363,25 +352,6 @@ static void ThrowIfNoSuchModule(Environment* env, const char* module_v) {
363352
env->ThrowError(errmsg);
364353
}
365354

366-
void GetBinding(const FunctionCallbackInfo<Value>& args) {
367-
Environment* env = Environment::GetCurrent(args);
368-
369-
CHECK(args[0]->IsString());
370-
371-
Local<String> module = args[0].As<String>();
372-
node::Utf8Value module_v(env->isolate(), module);
373-
374-
node_module* mod = get_builtin_module(*module_v);
375-
Local<Object> exports;
376-
if (mod != nullptr) {
377-
exports = InitModule(env, mod, module);
378-
} else {
379-
return ThrowIfNoSuchModule(env, *module_v);
380-
}
381-
382-
args.GetReturnValue().Set(exports);
383-
}
384-
385355
void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
386356
Environment* env = Environment::GetCurrent(args);
387357

src/node_binding.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "v8.h"
1616

1717
enum {
18-
NM_F_BUILTIN = 1 << 0,
18+
NM_F_BUILTIN = 1 << 0, // Unused.
1919
NM_F_LINKED = 1 << 1,
2020
NM_F_INTERNAL = 1 << 2,
2121
};
@@ -33,9 +33,6 @@ enum {
3333
nullptr}; \
3434
void _register_##modname() { node_module_register(&_module); }
3535

36-
#define NODE_BUILTIN_MODULE_CONTEXT_AWARE(modname, regfunc) \
37-
NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_BUILTIN)
38-
3936
void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
4037
v8::Local<v8::Value> module,
4138
v8::Local<v8::Context> context,
@@ -83,7 +80,6 @@ class DLib {
8380
// use the __attribute__((constructor)). Need to
8481
// explicitly call the _register* functions.
8582
void RegisterBuiltinModules();
86-
void GetBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
8783
void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
8884
void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
8985
void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -92,7 +88,5 @@ void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args);
9288

9389
} // namespace node
9490

95-
#include "node_binding.h"
96-
9791
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
9892
#endif // SRC_NODE_BINDING_H_

0 commit comments

Comments
 (0)