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