/src/node/src/node_binding.h
Line | Count | Source |
1 | | #ifndef SRC_NODE_BINDING_H_ |
2 | | #define SRC_NODE_BINDING_H_ |
3 | | |
4 | | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
5 | | |
6 | | #if defined(__POSIX__) |
7 | | #include <dlfcn.h> |
8 | | #endif |
9 | | |
10 | | #include "node.h" |
11 | | #define NAPI_EXPERIMENTAL |
12 | | #include "node_api.h" |
13 | | #include "uv.h" |
14 | | |
15 | | enum { |
16 | | NM_F_BUILTIN = 1 << 0, // Unused. |
17 | | NM_F_LINKED = 1 << 1, |
18 | | NM_F_INTERNAL = 1 << 2, |
19 | | NM_F_DELETEME = 1 << 3, |
20 | | }; |
21 | | |
22 | | // Make sure our internal values match the public API's values. |
23 | | static_assert(static_cast<int>(NM_F_LINKED) == |
24 | | static_cast<int>(node::ModuleFlags::kLinked), |
25 | | "NM_F_LINKED != node::ModuleFlags::kLinked"); |
26 | | |
27 | | #if NODE_HAVE_I18N_SUPPORT |
28 | 2.78M | #define NODE_BUILTIN_ICU_BINDINGS(V) V(icu) |
29 | | #else |
30 | | #define NODE_BUILTIN_ICU_BINDINGS(V) |
31 | | #endif |
32 | | |
33 | | #if HAVE_OPENSSL && NODE_OPENSSL_HAS_QUIC |
34 | 2.65M | #define NODE_BUILTIN_QUIC_BINDINGS(V) V(quic) |
35 | | #else |
36 | | #define NODE_BUILTIN_QUIC_BINDINGS(V) |
37 | | #endif |
38 | | |
39 | | #define NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) \ |
40 | 4.56M | V(async_wrap) \ |
41 | 4.56M | V(blob) \ |
42 | 4.31M | V(builtins) \ |
43 | 4.18M | V(contextify) \ |
44 | 4.06M | V(encoding_binding) \ |
45 | 3.93M | V(fs) \ |
46 | 3.80M | V(fs_dir) \ |
47 | 3.80M | V(messaging) \ |
48 | 3.67M | V(mksnapshot) \ |
49 | 3.55M | V(modules) \ |
50 | 3.42M | V(module_wrap) \ |
51 | 3.29M | V(performance) \ |
52 | 3.16M | V(process_methods) \ |
53 | 3.04M | V(timers) \ |
54 | 2.91M | V(url) \ |
55 | 2.78M | V(worker) \ |
56 | 2.65M | NODE_BUILTIN_ICU_BINDINGS(V) \ |
57 | 2.53M | NODE_BUILTIN_QUIC_BINDINGS(V) |
58 | | |
59 | | #define NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, priv, flags) \ |
60 | | static node::node_module _module = { \ |
61 | | NODE_MODULE_VERSION, \ |
62 | | flags, \ |
63 | | nullptr, \ |
64 | | __FILE__, \ |
65 | | nullptr, \ |
66 | | (node::addon_context_register_func)(regfunc), \ |
67 | | NODE_STRINGIFY(modname), \ |
68 | | priv, \ |
69 | | nullptr}; \ |
70 | 7.99M | void _register_##modname() { node_module_register(&_module); } Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
_register_process_methods() Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
_register_string_decoder() Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
_register_encoding_binding() Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
_register_fs_event_wrap() Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
_register_internal_only_v8() Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
Line | Count | Source | 70 | 126k | void _register_##modname() { node_module_register(&_module); } |
|
71 | | |
72 | | void napi_module_register_by_symbol( |
73 | | v8::Local<v8::Object> exports, |
74 | | v8::Local<v8::Value> module, |
75 | | v8::Local<v8::Context> context, |
76 | | napi_addon_register_func init, |
77 | | int32_t module_api_version = NODE_API_DEFAULT_MODULE_API_VERSION); |
78 | | |
79 | | node::addon_context_register_func get_node_api_context_register_func( |
80 | | node::Environment* node_env, |
81 | | const char* module_name, |
82 | | int32_t module_api_version); |
83 | | |
84 | | namespace node { |
85 | | |
86 | | // Define a node internal binding that may be loaded in a context of |
87 | | // a node::Environment. |
88 | | // If an internal binding needs initializing per-isolate templates, define |
89 | | // with NODE_BINDING_PER_ISOLATE_INIT too. |
90 | | #define NODE_BINDING_CONTEXT_AWARE_INTERNAL(modname, regfunc) \ |
91 | | NODE_BINDING_CONTEXT_AWARE_CPP(modname, regfunc, nullptr, NM_F_INTERNAL) |
92 | | |
93 | | // Define a per-isolate initialization function for a node internal binding. |
94 | | // The modname should be registered in the NODE_BINDINGS_WITH_PER_ISOLATE_INIT |
95 | | // list. |
96 | | #define NODE_BINDING_PER_ISOLATE_INIT(modname, per_isolate_func) \ |
97 | | void _register_isolate_##modname(node::IsolateData* isolate_data, \ |
98 | 2.29M | v8::Local<v8::ObjectTemplate> target) { \ |
99 | 2.29M | per_isolate_func(isolate_data, target); \ |
100 | 2.29M | } _register_isolate_async_wrap(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_module_wrap(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_blob(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_builtins(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_contextify(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_fs_dir(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_fs(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_icu(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_messaging(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_modules(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_performance(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_process_methods(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_mksnapshot(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_url(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_worker(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_timers(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_quic(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
_register_isolate_encoding_binding(node::IsolateData*, v8::Local<v8::ObjectTemplate>) Line | Count | Source | 98 | 127k | v8::Local<v8::ObjectTemplate> target) { \ | 99 | 127k | per_isolate_func(isolate_data, target); \ | 100 | 127k | } |
|
101 | | |
102 | | // Globals per process |
103 | | // This is set by node::Init() which is used by embedders |
104 | | extern bool node_is_initialized; |
105 | | |
106 | | namespace binding { |
107 | | |
108 | | class DLib { |
109 | | public: |
110 | | #ifdef __POSIX__ |
111 | | static const int kDefaultFlags = RTLD_LAZY; |
112 | | #else |
113 | | static const int kDefaultFlags = 0; |
114 | | #endif |
115 | | |
116 | | DLib(const char* filename, int flags); |
117 | | |
118 | | bool Open(); |
119 | | void Close(); |
120 | | void* GetSymbolAddress(const char* name); |
121 | | void SaveInGlobalHandleMap(node_module* mp); |
122 | | node_module* GetSavedModuleFromGlobalHandleMap(); |
123 | | |
124 | | const std::string filename_; |
125 | | const int flags_; |
126 | | std::string errmsg_; |
127 | | void* handle_; |
128 | | #ifndef __POSIX__ |
129 | | uv_lib_t lib_; |
130 | | #endif |
131 | | bool has_entry_in_global_handle_map_ = false; |
132 | | |
133 | | DLib(const DLib&) = delete; |
134 | | DLib& operator=(const DLib&) = delete; |
135 | | }; |
136 | | |
137 | | // Call _register<module_name> functions for all of |
138 | | // the built-in bindings. Because built-in bindings don't |
139 | | // use the __attribute__((constructor)). Need to |
140 | | // explicitly call the _register* functions. |
141 | | void RegisterBuiltinBindings(); |
142 | | // Create per-isolate templates for the internal bindings. |
143 | | void CreateInternalBindingTemplates(IsolateData* isolate_data); |
144 | | void GetInternalBinding(const v8::FunctionCallbackInfo<v8::Value>& args); |
145 | | void GetLinkedBinding(const v8::FunctionCallbackInfo<v8::Value>& args); |
146 | | void DLOpen(const v8::FunctionCallbackInfo<v8::Value>& args); |
147 | | |
148 | | } // namespace binding |
149 | | |
150 | | } // namespace node |
151 | | |
152 | | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
153 | | #endif // SRC_NODE_BINDING_H_ |