From 3d668262a09ef031003babc14eff9e5d4ac81698 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 29 Nov 2018 00:46:45 +0800 Subject: src: move C++ binding/addon related code into node_binding{.h, .cc} This patch: - Moves the C++ binding/addon related code out of node_internals.h/node.cc and into dedicated files node_binding.h/node_binding.cc, and only puts the code resued by other files into the header. - Introduce a node::binding namespace so that code exposed to other files can be easily recognized. PR-URL: https://github.com/nodejs/node/pull/24701 Reviewed-By: Ben Noordhuis Reviewed-By: Richard Lau --- src/node_binding.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/node_binding.h (limited to 'src/node_binding.h') diff --git a/src/node_binding.h b/src/node_binding.h new file mode 100644 index 0000000000..743c82accd --- /dev/null +++ b/src/node_binding.h @@ -0,0 +1,64 @@ +#ifndef SRC_NODE_BINDING_H_ +#define SRC_NODE_BINDING_H_ + +#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS + +#include "node.h" +#include "node_api.h" +#include "uv.h" +#include "v8.h" + +enum { + NM_F_BUILTIN = 1 << 0, + NM_F_LINKED = 1 << 1, + NM_F_INTERNAL = 1 << 2, +}; + +#define NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \ + static node::node_module _module = { \ + NODE_MODULE_VERSION, \ + flags, \ + nullptr, \ + __FILE__, \ + nullptr, \ + (node::addon_context_register_func)(regfunc), \ + NODE_STRINGIFY(modname), \ + priv, \ + nullptr}; \ + 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 exports, + v8::Local module, + v8::Local context, + napi_addon_register_func init); + +namespace node { + +#define NODE_MODULE_CONTEXT_AWARE_INTERNAL(modname, regfunc) \ + NODE_MODULE_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL) + +// Globals per process +// This is set by node::Init() which is used by embedders +extern bool node_is_initialized; + +namespace binding { + +// Call _register functions for all of +// the built-in modules. Because built-in modules don't +// use the __attribute__((constructor)). Need to +// explicitly call the _register* functions. +void RegisterBuiltinModules(); +void GetBinding(const v8::FunctionCallbackInfo& args); +void GetInternalBinding(const v8::FunctionCallbackInfo& args); +void GetLinkedBinding(const v8::FunctionCallbackInfo& args); +void DLOpen(const v8::FunctionCallbackInfo& args); + +} // namespace binding + +} // namespace node + +#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS +#endif // SRC_NODE_BINDING_H_ -- cgit v1.2.3