| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -780,7 +780,9 @@ void AddLinkedBinding(Environment* env, const node_module& mod) { | |||
| 780 | 780 | } | |
| 781 | 781 | ||
| 782 | 782 | void AddLinkedBinding(Environment* env, const napi_module& mod) { | |
| 783 | - AddLinkedBinding(env, napi_module_to_node_module(&mod)); | ||
| 783 | + node_module node_mod = napi_module_to_node_module(&mod); | ||
| 784 | + node_mod.nm_flags = NM_F_LINKED; | ||
| 785 | + AddLinkedBinding(env, node_mod); | ||
| 784 | 786 | } | |
| 785 | 787 | ||
| 786 | 788 | void AddLinkedBinding(Environment* env, | |
@@ -801,6 +803,32 @@ void AddLinkedBinding(Environment* env, | |||
| 801 | 803 | AddLinkedBinding(env, mod); | |
| 802 | 804 | } | |
| 803 | 805 | ||
| 806 | + void AddLinkedBinding(Environment* env, | ||
| 807 | + const char* name, | ||
| 808 | + napi_addon_register_func fn) { | ||
| 809 | + node_module mod = { | ||
| 810 | + -1, | ||
| 811 | + NM_F_LINKED, | ||
| 812 | + nullptr, // nm_dso_handle | ||
| 813 | + nullptr, // nm_filename | ||
| 814 | + nullptr, // nm_register_func | ||
| 815 | + [](v8::Local<v8::Object> exports, | ||
| 816 | + v8::Local<v8::Value> module, | ||
| 817 | + v8::Local<v8::Context> context, | ||
| 818 | + void* priv) { | ||
| 819 | + napi_module_register_by_symbol( | ||
| 820 | + exports, | ||
| 821 | + module, | ||
| 822 | + context, | ||
| 823 | + reinterpret_cast<napi_addon_register_func>(priv)); | ||
| 824 | + }, | ||
| 825 | + name, | ||
| 826 | + reinterpret_cast<void*>(fn), | ||
| 827 | + nullptr // nm_link | ||
| 828 | + }; | ||
| 829 | + AddLinkedBinding(env, mod); | ||
| 830 | + } | ||
| 831 | + | ||
| 804 | 832 | static std::atomic<uint64_t> next_thread_id{0}; | |
| 805 | 833 | ||
| 806 | 834 | ThreadId AllocateEnvironmentThreadId() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,9 @@ | |||
| 75 | 75 | #include "v8-platform.h" // NOLINT(build/include_order) | |
| 76 | 76 | #include "node_version.h" // NODE_MODULE_VERSION | |
| 77 | 77 | ||
| 78 | + #define NAPI_EXPERIMENTAL | ||
| 79 | + #include "node_api.h" | ||
| 80 | + | ||
| 78 | 81 | #include <functional> | |
| 79 | 82 | #include <memory> | |
| 80 | 83 | #include <ostream> | |
@@ -121,8 +124,6 @@ | |||
| 121 | 124 | // Forward-declare libuv loop | |
| 122 | 125 | struct uv_loop_s; | |
| 123 | 126 | ||
| 124 | - struct napi_module; | ||
| 125 | - | ||
| 126 | 127 | // Forward-declare these functions now to stop MSVS from becoming | |
| 127 | 128 | // terminally confused when it's done in node_internals.h | |
| 128 | 129 | namespace node { | |
@@ -1096,6 +1097,9 @@ NODE_EXTERN void AddLinkedBinding(Environment* env, | |||
| 1096 | 1097 | const char* name, | |
| 1097 | 1098 | addon_context_register_func fn, | |
| 1098 | 1099 | void* priv); | |
| 1100 | + NODE_EXTERN void AddLinkedBinding(Environment* env, | ||
| 1101 | + const char* name, | ||
| 1102 | + napi_addon_register_func fn); | ||
| 1099 | 1103 | ||
| 1100 | 1104 | /* Registers a callback with the passed-in Environment instance. The callback | |
| 1101 | 1105 | * is called after the event loop exits, but before the VM is disposed. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ struct uv_loop_s; // Forward declaration. | |||
| 31 | 31 | typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env, | |
| 32 | 32 | napi_value exports); | |
| 33 | 33 | ||
| 34 | + // Used by deprecated registration method napi_module_register. | ||
| 34 | 35 | typedef struct napi_module { | |
| 35 | 36 | int nm_version; | |
| 36 | 37 | unsigned int nm_flags; | |
@@ -43,70 +44,15 @@ typedef struct napi_module { | |||
| 43 | 44 | ||
| 44 | 45 | #define NAPI_MODULE_VERSION 1 | |
| 45 | 46 | ||
| 46 | - #if defined(_MSC_VER) | ||
| 47 | - #if defined(__cplusplus) | ||
| 48 | - #define NAPI_C_CTOR(fn) \ | ||
| 49 | - static void NAPI_CDECL fn(void); \ | ||
| 50 | - namespace { \ | ||
| 51 | - struct fn##_ { \ | ||
| 52 | - fn##_() { fn(); } \ | ||
| 53 | - } fn##_v_; \ | ||
| 54 | - } \ | ||
| 55 | - static void NAPI_CDECL fn(void) | ||
| 56 | - #else // !defined(__cplusplus) | ||
| 57 | - #pragma section(".CRT$XCU", read) | ||
| 58 | - // The NAPI_C_CTOR macro defines a function fn that is called during CRT | ||
| 59 | - // initialization. | ||
| 60 | - // C does not support dynamic initialization of static variables and this code | ||
| 61 | - // simulates C++ behavior. Exporting the function pointer prevents it from being | ||
| 62 | - // optimized. See for details: | ||
| 63 | - // https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-170 | ||
| 64 | - #define NAPI_C_CTOR(fn) \ | ||
| 65 | - static void NAPI_CDECL fn(void); \ | ||
| 66 | - __declspec(dllexport, allocate(".CRT$XCU")) void(NAPI_CDECL * fn##_)(void) = \ | ||
| 67 | - fn; \ | ||
| 68 | - static void NAPI_CDECL fn(void) | ||
| 69 | - #endif // defined(__cplusplus) | ||
| 70 | - #else | ||
| 71 | - #define NAPI_C_CTOR(fn) \ | ||
| 72 | - static void fn(void) __attribute__((constructor)); \ | ||
| 73 | - static void fn(void) | ||
| 74 | - #endif | ||
| 75 | - | ||
| 76 | - #define NAPI_MODULE_X(modname, regfunc, priv, flags) \ | ||
| 77 | - EXTERN_C_START \ | ||
| 78 | - static napi_module _module = { \ | ||
| 79 | - NAPI_MODULE_VERSION, \ | ||
| 80 | - flags, \ | ||
| 81 | - __FILE__, \ | ||
| 82 | - regfunc, \ | ||
| 83 | - #modname, \ | ||
| 84 | - priv, \ | ||
| 85 | - {0}, \ | ||
| 86 | - }; \ | ||
| 87 | - NAPI_C_CTOR(_register_##modname) { napi_module_register(&_module); } \ | ||
| 88 | - EXTERN_C_END | ||
| 89 | - | ||
| 90 | 47 | #define NAPI_MODULE_INITIALIZER_X(base, version) \ | |
| 91 | 48 | NAPI_MODULE_INITIALIZER_X_HELPER(base, version) | |
| 92 | 49 | #define NAPI_MODULE_INITIALIZER_X_HELPER(base, version) base##version | |
| 93 | 50 | ||
| 94 | 51 | #ifdef __wasm32__ | |
| 95 | - #define NAPI_WASM_INITIALIZER \ | ||
| 96 | - NAPI_MODULE_INITIALIZER_X(napi_register_wasm_v, NAPI_MODULE_VERSION) | ||
| 97 | - #define NAPI_MODULE(modname, regfunc) \ | ||
| 98 | - EXTERN_C_START \ | ||
| 99 | - NAPI_MODULE_EXPORT napi_value NAPI_WASM_INITIALIZER(napi_env env, \ | ||
| 100 | - napi_value exports) { \ | ||
| 101 | - return regfunc(env, exports); \ | ||
| 102 | - } \ | ||
| 103 | - EXTERN_C_END | ||
| 52 | + #define NAPI_MODULE_INITIALIZER_BASE napi_register_wasm_v | ||
| 104 | 53 | #else | |
| 105 | - #define NAPI_MODULE(modname, regfunc) \ | ||
| 106 | - NAPI_MODULE_X(modname, regfunc, NULL, 0) // NOLINT (readability/null_usage) | ||
| 107 | - #endif | ||
| 108 | - | ||
| 109 | 54 | #define NAPI_MODULE_INITIALIZER_BASE napi_register_module_v | |
| 55 | + #endif | ||
| 110 | 56 | ||
| 111 | 57 | #define NAPI_MODULE_INITIALIZER \ | |
| 112 | 58 | NAPI_MODULE_INITIALIZER_X(NAPI_MODULE_INITIALIZER_BASE, NAPI_MODULE_VERSION) | |
@@ -116,12 +62,24 @@ typedef struct napi_module { | |||
| 116 | 62 | NAPI_MODULE_EXPORT napi_value NAPI_MODULE_INITIALIZER(napi_env env, \ | |
| 117 | 63 | napi_value exports); \ | |
| 118 | 64 | EXTERN_C_END \ | |
| 119 | - NAPI_MODULE(NODE_GYP_MODULE_NAME, NAPI_MODULE_INITIALIZER) \ | ||
| 120 | 65 | napi_value NAPI_MODULE_INITIALIZER(napi_env env, napi_value exports) | |
| 121 | 66 | ||
| 67 | + #define NAPI_MODULE(modname, regfunc) \ | ||
| 68 | + NAPI_MODULE_INIT() { return regfunc(env, exports); } | ||
| 69 | + | ||
| 70 | + // Deprecated. Use NAPI_MODULE. | ||
| 71 | + #define NAPI_MODULE_X(modname, regfunc, priv, flags) \ | ||
| 72 | + NAPI_MODULE(modname, regfunc) | ||
| 73 | + | ||
| 122 | 74 | EXTERN_C_START | |
| 123 | 75 | ||
| 124 | - NAPI_EXTERN void NAPI_CDECL napi_module_register(napi_module* mod); | ||
| 76 | + // Deprecated. Replaced by symbol-based registration defined by NAPI_MODULE | ||
| 77 | + // and NAPI_MODULE_INIT macros. | ||
| 78 | + #if defined(__cplusplus) && __cplusplus >= 201402L | ||
| 79 | + [[deprecated]] | ||
| 80 | + #endif | ||
| 81 | + NAPI_EXTERN void NAPI_CDECL | ||
| 82 | + napi_module_register(napi_module* mod); | ||
| 125 | 83 | ||
| 126 | 84 | NAPI_EXTERN NAPI_NO_RETURN void NAPI_CDECL | |
| 127 | 85 | napi_fatal_error(const char* location, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments