summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-06-13 14:01:33 -0400
committerGabriel Schulhof <gabriel.schulhof@intel.com>2018-07-03 18:34:50 -0400
commit602da6492f278c1345f7f2d82014d9248254476b (patch)
tree41e76b28acea565ed3d5ee04096d8d15919afc23 /src
parenta15ea5d7ca1cf0f48ce1f2be62b1cd446a50b06d (diff)
downloadandroid-node-v8-602da6492f278c1345f7f2d82014d9248254476b.tar.gz
android-node-v8-602da6492f278c1345f7f2d82014d9248254476b.tar.bz2
android-node-v8-602da6492f278c1345f7f2d82014d9248254476b.zip
src: add context-aware init macro and doc
Introduces macros `NODE_MODULE_INITIALIZER` which expands to the name of the special symbol that process.dlopen() will look for to initialize an addon, and `NODE_MODULE_INIT()` which creates the boilerplate for a context-aware module which can be loaded multiple times via the special symbol mechanism. Additionally, provides an example of using the new macro to construct an addon which stores per-addon-instance data in a heap-allocated structure that gets passed to each binding, rather than in a collection of global static variables. Re: https://github.com/nodejs/node/issues/21291#issuecomment-396729727 PR-URL: https://github.com/nodejs/node/pull/21318 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/node.h b/src/node.h
index b551c8bb09..ed2c074b92 100644
--- a/src/node.h
+++ b/src/node.h
@@ -579,6 +579,28 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
*/
#define NODE_MODULE_DECL /* nothing */
+#define NODE_MODULE_INITIALIZER_BASE node_register_module_v
+
+#define NODE_MODULE_INITIALIZER_X(base, version) \
+ NODE_MODULE_INITIALIZER_X_HELPER(base, version)
+
+#define NODE_MODULE_INITIALIZER_X_HELPER(base, version) base##version
+
+#define NODE_MODULE_INITIALIZER \
+ NODE_MODULE_INITIALIZER_X(NODE_MODULE_INITIALIZER_BASE, \
+ NODE_MODULE_VERSION)
+
+#define NODE_MODULE_INIT() \
+ extern "C" NODE_MODULE_EXPORT void \
+ NODE_MODULE_INITIALIZER(v8::Local<v8::Object> exports, \
+ v8::Local<v8::Value> module, \
+ v8::Local<v8::Context> context); \
+ NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, \
+ NODE_MODULE_INITIALIZER) \
+ void NODE_MODULE_INITIALIZER(v8::Local<v8::Object> exports, \
+ v8::Local<v8::Value> module, \
+ v8::Local<v8::Context> context)
+
/* Called after the event loop exits but before the VM is disposed.
* Callbacks are run in reverse order of registration, i.e. newest first.
*/