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: https://github.com/nodejs/node/pull/25829
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
Anna Henningsen 2019-01-30 21:07:11 +01:00
parent cca897ef5d
commit 270ffb0fa7
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
7 changed files with 10 additions and 54 deletions

View File

@ -9,7 +9,7 @@ const { NativeModule } = require('internal/bootstrap/loaders');
const { const {
getCodeCache, compileFunction getCodeCache, compileFunction
} = internalBinding('native_module'); } = internalBinding('native_module');
const { hasTracing, hasInspector } = process.binding('config'); const { hasTracing, hasInspector } = internalBinding('config');
// Modules with source code compiled in js2c that // Modules with source code compiled in js2c that
// cannot be compiled with the code cache. // cannot be compiled with the code cache.

View File

@ -41,7 +41,7 @@
// This file is compiled as if it's wrapped in a function with arguments // This file is compiled as if it's wrapped in a function with arguments
// passed by node::RunBootstrapping() // passed by node::RunBootstrapping()
/* global process, getBinding, getLinkedBinding, getInternalBinding */ /* global process, getLinkedBinding, getInternalBinding */
/* global experimentalModules, exposeInternals, primordials */ /* global experimentalModules, exposeInternals, primordials */
const { const {
@ -108,12 +108,8 @@ const internalBindingWhitelist = new SafeSet([
if (internalBindingWhitelist.has(module)) { if (internalBindingWhitelist.has(module)) {
return internalBinding(module); return internalBinding(module);
} }
let mod = bindingObj[module]; // eslint-disable-next-line no-restricted-syntax
if (typeof mod !== 'object') { throw new Error(`No such module: ${module}`);
mod = bindingObj[module] = getBinding(module);
moduleLoadList.push(`Binding ${module}`);
}
return mod;
}; };
process._linkedBinding = function _linkedBinding(module) { process._linkedBinding = function _linkedBinding(module) {

View File

@ -19,7 +19,7 @@ const {
DiffieHellmanGroup: _DiffieHellmanGroup, DiffieHellmanGroup: _DiffieHellmanGroup,
ECDH: _ECDH, ECDH: _ECDH,
ECDHConvertKey: _ECDHConvertKey ECDHConvertKey: _ECDHConvertKey
} = process.binding('crypto'); } = internalBinding('crypto');
const { const {
POINT_CONVERSION_COMPRESSED, POINT_CONVERSION_COMPRESSED,
POINT_CONVERSION_HYBRID, POINT_CONVERSION_HYBRID,

View File

@ -3,7 +3,7 @@
const { const {
Hash: _Hash, Hash: _Hash,
Hmac: _Hmac Hmac: _Hmac
} = process.binding('crypto'); } = internalBinding('crypto');
const { const {
getDefaultEncoding, getDefaultEncoding,

View File

@ -282,7 +282,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
// Create binding loaders // Create binding loaders
std::vector<Local<String>> loaders_params = { std::vector<Local<String>> loaders_params = {
env->process_string(), env->process_string(),
FIXED_ONE_BYTE_STRING(isolate, "getBinding"),
FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"), FIXED_ONE_BYTE_STRING(isolate, "getLinkedBinding"),
FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"), FIXED_ONE_BYTE_STRING(isolate, "getInternalBinding"),
// --experimental-modules // --experimental-modules
@ -292,9 +291,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
env->primordials_string()}; env->primordials_string()};
std::vector<Local<Value>> loaders_args = { std::vector<Local<Value>> loaders_args = {
process, process,
env->NewFunctionTemplate(binding::GetBinding)
->GetFunction(context)
.ToLocalChecked(),
env->NewFunctionTemplate(binding::GetLinkedBinding) env->NewFunctionTemplate(binding::GetLinkedBinding)
->GetFunction(context) ->GetFunction(context)
.ToLocalChecked(), .ToLocalChecked(),

View File

@ -84,7 +84,7 @@
// function for each built-in modules explicitly in // function for each built-in modules explicitly in
// binding::RegisterBuiltinModules(). This is only forward declaration. // binding::RegisterBuiltinModules(). This is only forward declaration.
// The definitions are in each module's implementation when calling // The definitions are in each module's implementation when calling
// the NODE_BUILTIN_MODULE_CONTEXT_AWARE. // the NODE_MODULE_CONTEXT_AWARE_INTERNAL.
#define V(modname) void _register_##modname(); #define V(modname) void _register_##modname();
NODE_BUILTIN_MODULES(V) NODE_BUILTIN_MODULES(V)
#undef V #undef V
@ -101,7 +101,6 @@ using v8::String;
using v8::Value; using v8::Value;
// Globals per process // Globals per process
static node_module* modlist_builtin;
static node_module* modlist_internal; static node_module* modlist_internal;
static node_module* modlist_linked; static node_module* modlist_linked;
static node_module* modlist_addon; static node_module* modlist_addon;
@ -114,10 +113,7 @@ bool node_is_initialized = false;
extern "C" void node_module_register(void* m) { extern "C" void node_module_register(void* m) {
struct node_module* mp = reinterpret_cast<struct node_module*>(m); struct node_module* mp = reinterpret_cast<struct node_module*>(m);
if (mp->nm_flags & NM_F_BUILTIN) { if (mp->nm_flags & NM_F_INTERNAL) {
mp->nm_link = modlist_builtin;
modlist_builtin = mp;
} else if (mp->nm_flags & NM_F_INTERNAL) {
mp->nm_link = modlist_internal; mp->nm_link = modlist_internal;
modlist_internal = mp; modlist_internal = mp;
} else if (!node_is_initialized) { } else if (!node_is_initialized) {
@ -295,11 +291,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
env->ThrowError(errmsg); env->ThrowError(errmsg);
return false; return false;
} }
if (mp->nm_flags & NM_F_BUILTIN) { CHECK_EQ(mp->nm_flags & NM_F_BUILTIN, 0);
dlib->Close();
env->ThrowError("Built-in module self-registered.");
return false;
}
mp->nm_dso_handle = dlib->handle_; mp->nm_dso_handle = dlib->handle_;
mp->nm_link = modlist_addon; mp->nm_link = modlist_addon;
@ -335,9 +327,6 @@ inline struct node_module* FindModule(struct node_module* list,
return mp; return mp;
} }
node_module* get_builtin_module(const char* name) {
return FindModule(modlist_builtin, name, NM_F_BUILTIN);
}
node_module* get_internal_module(const char* name) { node_module* get_internal_module(const char* name) {
return FindModule(modlist_internal, name, NM_F_INTERNAL); return FindModule(modlist_internal, name, NM_F_INTERNAL);
} }
@ -363,25 +352,6 @@ static void ThrowIfNoSuchModule(Environment* env, const char* module_v) {
env->ThrowError(errmsg); env->ThrowError(errmsg);
} }
void GetBinding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK(args[0]->IsString());
Local<String> module = args[0].As<String>();
node::Utf8Value module_v(env->isolate(), module);
node_module* mod = get_builtin_module(*module_v);
Local<Object> exports;
if (mod != nullptr) {
exports = InitModule(env, mod, module);
} else {
return ThrowIfNoSuchModule(env, *module_v);
}
args.GetReturnValue().Set(exports);
}
void GetInternalBinding(const FunctionCallbackInfo<Value>& args) { void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args); Environment* env = Environment::GetCurrent(args);

View File

@ -15,7 +15,7 @@
#include "v8.h" #include "v8.h"
enum { enum {
NM_F_BUILTIN = 1 << 0, NM_F_BUILTIN = 1 << 0, // Unused.
NM_F_LINKED = 1 << 1, NM_F_LINKED = 1 << 1,
NM_F_INTERNAL = 1 << 2, NM_F_INTERNAL = 1 << 2,
}; };
@ -33,9 +33,6 @@ enum {
nullptr}; \ nullptr}; \
void _register_##modname() { node_module_register(&_module); } void _register_##modname() { node_module_register(&_module); }
#define NODE_BUILTIN_MODULE_CONTEXT_AWARE(modname, regfunc) \
NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_BUILTIN)
void napi_module_register_by_symbol(v8::Local<v8::Object> exports, void napi_module_register_by_symbol(v8::Local<v8::Object> exports,
v8::Local<v8::Value> module, v8::Local<v8::Value> module,
v8::Local<v8::Context> context, v8::Local<v8::Context> context,
@ -83,7 +80,6 @@ class DLib {
// use the __attribute__((constructor)). Need to // use the __attribute__((constructor)). Need to
// explicitly call the _register* functions. // explicitly call the _register* functions.
void RegisterBuiltinModules(); void RegisterBuiltinModules();
void GetBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args); void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args); void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args); void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args);
@ -92,7 +88,5 @@ void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args);
} // namespace node } // namespace node
#include "node_binding.h"
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_NODE_BINDING_H_ #endif // SRC_NODE_BINDING_H_