summaryrefslogtreecommitdiff
path: root/test
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 /test
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 'test')
-rw-r--r--test/addons/hello-world/binding.cc13
1 files changed, 6 insertions, 7 deletions
diff --git a/test/addons/hello-world/binding.cc b/test/addons/hello-world/binding.cc
index e267a3b2a7..341b58f9a6 100644
--- a/test/addons/hello-world/binding.cc
+++ b/test/addons/hello-world/binding.cc
@@ -6,13 +6,12 @@ void Method(const v8::FunctionCallbackInfo<v8::Value>& args) {
args.GetReturnValue().Set(v8::String::NewFromUtf8(isolate, "world"));
}
-#define CONCAT(a, b) CONCAT_HELPER(a, b)
-#define CONCAT_HELPER(a, b) a##b
-#define INITIALIZER CONCAT(node_register_module_v, NODE_MODULE_VERSION)
-
-extern "C" NODE_MODULE_EXPORT void INITIALIZER(v8::Local<v8::Object> exports,
- v8::Local<v8::Value> module,
- v8::Local<v8::Context> context) {
+// Not using the full NODE_MODULE_INIT() macro here because we want to test the
+// addon loader's reaction to the FakeInit() entry point below.
+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_SET_METHOD(exports, "hello", Method);
}