Skip to content

Commit

Permalink
src: rename internal module declaration as internal bindings
Browse files Browse the repository at this point in the history
This is a continuation of the name reification on the internal bindings.

Renames NODE_MODULE_CONTEXT_AWARE_INTERNAL and
NODE_MODULE_EXTERNAL_REFERENCE to NODE_BINDING_CONTEXT_AWARE_INTERNAL
and NODE_BINDING_EXTERNAL_REFERENCE respectively.

PR-URL: #45551
Refs: #44036
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
legendecas authored and targos committed Dec 12, 2022
1 parent 23ff505 commit 818028c
Show file tree
Hide file tree
Showing 64 changed files with 188 additions and 184 deletions.
8 changes: 4 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ void Initialize(Local<Object> target,
SetConstructorFunction(context, target, "ChannelWrap", channel_wrap);
}

// Run the `Initialize` function when loading this module through
// Run the `Initialize` function when loading this binding through
// `internalBinding('cares_wrap')` in Node.js's built-in JavaScript code:
NODE_MODULE_CONTEXT_AWARE_INTERNAL(cares_wrap, Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(cares_wrap, Initialize)
```
If the C++ binding is loaded during bootstrap, it needs to be registered
Expand All @@ -438,10 +438,10 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace util
} // namespace node
// The first argument passed to `NODE_MODULE_EXTERNAL_REFERENCE`,
// The first argument passed to `NODE_BINDING_EXTERNAL_REFERENCE`,
// which is `util` here, needs to be added to the
// `EXTERNAL_REFERENCE_BINDING_LIST_BASE` list in node_external_reference.h
NODE_MODULE_EXTERNAL_REFERENCE(util, node::util::RegisterExternalReferences)
NODE_BINDING_EXTERNAL_REFERENCE(util, node::util::RegisterExternalReferences)
```

Otherwise, you might see an error message like this when building the
Expand Down
6 changes: 3 additions & 3 deletions src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,6 @@ Local<Object> AsyncWrap::GetOwner(Environment* env, Local<Object> obj) {

} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(async_wrap, node::AsyncWrap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(async_wrap,
node::AsyncWrap::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(async_wrap, node::AsyncWrap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(async_wrap,
node::AsyncWrap::RegisterExternalReferences)
6 changes: 3 additions & 3 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace cares_wrap
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(cares_wrap, node::cares_wrap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(cares_wrap,
node::cares_wrap::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(cares_wrap, node::cares_wrap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(cares_wrap,
node::cares_wrap::RegisterExternalReferences)
4 changes: 2 additions & 2 deletions src/crypto/crypto_tls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,6 @@ void TLSWrap::RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace crypto
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(tls_wrap, node::crypto::TLSWrap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(
NODE_BINDING_CONTEXT_AWARE_INTERNAL(tls_wrap, node::crypto::TLSWrap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(
tls_wrap, node::crypto::TLSWrap::RegisterExternalReferences)
7 changes: 4 additions & 3 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ void FSEventWrap::OnEvent(uv_fs_event_t* handle, const char* filename,
} // anonymous namespace
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(fs_event_wrap, node::FSEventWrap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(fs_event_wrap,
node::FSEventWrap::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_event_wrap,
node::FSEventWrap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(fs_event_wrap,
node::FSEventWrap::RegisterExternalReferences)
4 changes: 2 additions & 2 deletions src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@ void HandleWrap::RegisterExternalReferences(

} // namespace node

NODE_MODULE_EXTERNAL_REFERENCE(handle_wrap,
node::HandleWrap::RegisterExternalReferences)
NODE_BINDING_EXTERNAL_REFERENCE(handle_wrap,
node::HandleWrap::RegisterExternalReferences)
6 changes: 3 additions & 3 deletions src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace heap
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(heap_utils, node::heap::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(heap_utils,
node::heap::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(heap_utils, node::heap::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(heap_utils,
node::heap::RegisterExternalReferences)
7 changes: 3 additions & 4 deletions src/inspector_js_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace inspector
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(inspector,
node::inspector::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(inspector,
node::inspector::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(inspector, node::inspector::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(inspector,
node::inspector::RegisterExternalReferences)
6 changes: 3 additions & 3 deletions src/inspector_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace profiler
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(profiler, node::profiler::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(profiler,
node::profiler::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(profiler, node::profiler::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(profiler,
node::profiler::RegisterExternalReferences)
2 changes: 1 addition & 1 deletion src/js_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ void JSStream::Initialize(Local<Object> target,

} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(js_stream, node::JSStream::Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(js_stream, node::JSStream::Initialize)
2 changes: 1 addition & 1 deletion src/js_udp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,4 @@ void JSUDPWrap::Initialize(Local<Object> target,

} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(js_udp_wrap, node::JSUDPWrap::Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(js_udp_wrap, node::JSUDPWrap::Initialize)
4 changes: 2 additions & 2 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -814,5 +814,5 @@ void ModuleWrap::Initialize(Local<Object> target,
} // namespace loader
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(module_wrap,
node::loader::ModuleWrap::Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(module_wrap,
node::loader::ModuleWrap::Initialize)
6 changes: 3 additions & 3 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ static ExitCode InitializeNodeWithArgsInternal(
// Initialize node_start_time to get relative uptime.
per_process::node_start_time = uv_hrtime();

// Register built-in modules
binding::RegisterBuiltinModules();
// Register built-in bindings
binding::RegisterBuiltinBindings();

// Make inherited handles noninheritable.
if (!(flags & ProcessInitializationFlags::kEnableStdioInheritance) &&
Expand Down Expand Up @@ -1254,5 +1254,5 @@ int Stop(Environment* env) {
#if !HAVE_INSPECTOR
void Initialize() {}

NODE_MODULE_CONTEXT_AWARE_INTERNAL(inspector, Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(inspector, Initialize)
#endif // !HAVE_INSPECTOR
71 changes: 35 additions & 36 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@
#include <string>

#if HAVE_OPENSSL
#define NODE_BUILTIN_OPENSSL_MODULES(V) V(crypto) V(tls_wrap)
#define NODE_BUILTIN_OPENSSL_BINDINGS(V) V(crypto) V(tls_wrap)
#else
#define NODE_BUILTIN_OPENSSL_MODULES(V)
#define NODE_BUILTIN_OPENSSL_BINDINGS(V)
#endif

#if NODE_HAVE_I18N_SUPPORT
#define NODE_BUILTIN_ICU_MODULES(V) V(icu)
#define NODE_BUILTIN_ICU_BINDINGS(V) V(icu)
#else
#define NODE_BUILTIN_ICU_MODULES(V)
#define NODE_BUILTIN_ICU_BINDINGS(V)
#endif

#if HAVE_INSPECTOR
#define NODE_BUILTIN_PROFILER_MODULES(V) V(profiler)
#define NODE_BUILTIN_PROFILER_BINDINGS(V) V(profiler)
#else
#define NODE_BUILTIN_PROFILER_MODULES(V)
#define NODE_BUILTIN_PROFILER_BINDINGS(V)
#endif

// A list of built-in modules. In order to do module registration
// in node::Init(), need to add built-in modules in the following list.
// Then in binding::RegisterBuiltinModules(), it calls modules' registration
// function. This helps the built-in modules are loaded properly when
// A list of built-in bindings. In order to do binding registration
// in node::Init(), need to add built-in bindings in the following list.
// Then in binding::RegisterBuiltinBindings(), it calls bindings' registration
// function. This helps the built-in bindings are loaded properly when
// node is built as static library. No need to depend on the
// __attribute__((constructor)) like mechanism in GCC.
#define NODE_BUILTIN_STANDARD_MODULES(V) \
#define NODE_BUILTIN_STANDARD_BINDINGS(V) \
V(async_wrap) \
V(blob) \
V(block_list) \
Expand Down Expand Up @@ -86,20 +86,20 @@
V(worker) \
V(zlib)

#define NODE_BUILTIN_MODULES(V) \
NODE_BUILTIN_STANDARD_MODULES(V) \
NODE_BUILTIN_OPENSSL_MODULES(V) \
NODE_BUILTIN_ICU_MODULES(V) \
NODE_BUILTIN_PROFILER_MODULES(V)
#define NODE_BUILTIN_BINDINGS(V) \
NODE_BUILTIN_STANDARD_BINDINGS(V) \
NODE_BUILTIN_OPENSSL_BINDINGS(V) \
NODE_BUILTIN_ICU_BINDINGS(V) \
NODE_BUILTIN_PROFILER_BINDINGS(V)

// This is used to load built-in modules. Instead of using
// This is used to load built-in bindings. Instead of using
// __attribute__((constructor)), we call the _register_<modname>
// function for each built-in modules explicitly in
// binding::RegisterBuiltinModules(). This is only forward declaration.
// The definitions are in each module's implementation when calling
// the NODE_MODULE_CONTEXT_AWARE_INTERNAL.
// function for each built-in bindings explicitly in
// binding::RegisterBuiltinBindings(). This is only forward declaration.
// The definitions are in each binding's implementation when calling
// the NODE_BINDING_CONTEXT_AWARE_INTERNAL.
#define V(modname) void _register_##modname();
NODE_BUILTIN_MODULES(V)
NODE_BUILTIN_BINDINGS(V)
#undef V

#ifdef _AIX
Expand Down Expand Up @@ -552,9 +552,9 @@ inline struct node_module* FindModule(struct node_module* list,
return mp;
}

static Local<Object> InitModule(Environment* env,
node_module* mod,
Local<String> module) {
static Local<Object> InitInternalBinding(Environment* env,
node_module* mod,
Local<String> module) {
// Internal bindings don't have a "module" object, only exports.
Local<Function> ctor = env->binding_data_ctor_template()
->GetFunction(env->context())
Expand All @@ -578,7 +578,7 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {

node_module* mod = FindModule(modlist_internal, *module_v, NM_F_INTERNAL);
if (mod != nullptr) {
exports = InitModule(env, mod, module);
exports = InitInternalBinding(env, mod, module);
env->internal_bindings.insert(mod);
} else if (!strcmp(*module_v, "constants")) {
exports = Object::New(env->isolate());
Expand All @@ -595,7 +595,7 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
builtins::BuiltinLoader::GetConfigString(env->isolate()))
.FromJust());
} else {
return THROW_ERR_INVALID_MODULE(env, "No such module: %s", *module_v);
return THROW_ERR_INVALID_MODULE(env, "No such binding: %s", *module_v);
}

args.GetReturnValue().Set(exports);
Expand Down Expand Up @@ -626,7 +626,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {

if (mod == nullptr) {
return THROW_ERR_INVALID_MODULE(
env, "No such module was linked: %s", *module_name_v);
env, "No such binding was linked: %s", *module_name_v);
}

Local<Object> module = Object::New(env->isolate());
Expand All @@ -642,8 +642,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
mod->nm_register_func(exports, module, mod->nm_priv);
} else {
return THROW_ERR_INVALID_MODULE(
env,
"Linked moduled has no declared entry point.");
env, "Linked binding has no declared entry point.");
}

auto effective_exports =
Expand All @@ -652,11 +651,11 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(effective_exports);
}

// Call built-in modules' _register_<module name> function to
// do module registration explicitly.
void RegisterBuiltinModules() {
// Call built-in bindings' _register_<module name> function to
// do binding registration explicitly.
void RegisterBuiltinBindings() {
#define V(modname) _register_##modname();
NODE_BUILTIN_MODULES(V)
NODE_BUILTIN_BINDINGS(V)
#undef V
}

Expand All @@ -668,5 +667,5 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace binding
} // namespace node

NODE_MODULE_EXTERNAL_REFERENCE(binding,
node::binding::RegisterExternalReferences)
NODE_BINDING_EXTERNAL_REFERENCE(binding,
node::binding::RegisterExternalReferences)
10 changes: 5 additions & 5 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static_assert(static_cast<int>(NM_F_LINKED) ==
static_cast<int>(node::ModuleFlags::kLinked),
"NM_F_LINKED != node::ModuleFlags::kLinked");

#define NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \
#define NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \
static node::node_module _module = { \
NODE_MODULE_VERSION, \
flags, \
Expand All @@ -44,8 +44,8 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports,

namespace node {

#define NODE_MODULE_CONTEXT_AWARE_INTERNAL(modname, regfunc) \
NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL)
#define NODE_BINDING_CONTEXT_AWARE_INTERNAL(modname, regfunc) \
NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL)

// Globals per process
// This is set by node::Init() which is used by embedders
Expand Down Expand Up @@ -83,10 +83,10 @@ class DLib {
};

// Call _register<module_name> functions for all of
// the built-in modules. Because built-in modules don't
// the built-in bindings. Because built-in bindings don't
// use the __attribute__((constructor)). Need to
// explicitly call the _register* functions.
void RegisterBuiltinModules();
void RegisterBuiltinBindings();
void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args);
void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
4 changes: 2 additions & 2 deletions src/node_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,5 @@ void Blob::RegisterExternalReferences(ExternalReferenceRegistry* registry) {

} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(blob, node::Blob::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(blob, node::Blob::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(blob, node::Blob::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(blob, node::Blob::RegisterExternalReferences)
5 changes: 3 additions & 2 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1426,5 +1426,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace Buffer
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(buffer, node::Buffer::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(buffer, node::Buffer::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(buffer, node::Buffer::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(buffer,
node::Buffer::RegisterExternalReferences)
6 changes: 3 additions & 3 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void BuiltinLoader::RegisterExternalReferences(
} // namespace builtins
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(builtins,
node::builtins::BuiltinLoader::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(
NODE_BINDING_CONTEXT_AWARE_INTERNAL(builtins,
node::builtins::BuiltinLoader::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(
builtins, node::builtins::BuiltinLoader::RegisterExternalReferences)
2 changes: 1 addition & 1 deletion src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ static void Initialize(Local<Object> target,

} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(config, node::Initialize)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(config, node::Initialize)
6 changes: 3 additions & 3 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace contextify
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(contextify, node::contextify::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(contextify,
node::contextify::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(contextify, node::contextify::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(contextify,
node::contextify::RegisterExternalReferences)
6 changes: 3 additions & 3 deletions src/node_credentials.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,6 @@ static void Initialize(Local<Object> target,
} // namespace credentials
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(credentials, node::credentials::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(credentials,
node::credentials::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(credentials, node::credentials::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(credentials,
node::credentials::RegisterExternalReferences)
5 changes: 3 additions & 2 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
} // namespace crypto
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(crypto, node::crypto::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(crypto, node::crypto::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(crypto,
node::crypto::RegisterExternalReferences)
5 changes: 3 additions & 2 deletions src/node_dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {

} // end namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(fs_dir, node::fs_dir::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(fs_dir, node::fs_dir::RegisterExternalReferences)
NODE_BINDING_CONTEXT_AWARE_INTERNAL(fs_dir, node::fs_dir::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(fs_dir,
node::fs_dir::RegisterExternalReferences)
Loading

0 comments on commit 818028c

Please sign in to comment.