Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2018-04-21 05:57:33 +0300
committerMyles Borins <mylesborins@google.com>2018-05-04 18:47:53 +0300
commitcd83df386bc0c567bda9a00ed297467b6046d785 (patch)
treed6fdf5592ecca37006d1849595d84cb3ea3c4910 /test/addons-napi/1_hello_world
parent4289402aa3a7b02554aa0ebcb70af40447083fc8 (diff)
n-api: initialize a module via a special symbol
Much like regular modules, N-API modules can also benefit from having a special symbol which they can expose. Fixes: https://github.com/nodejs/node/issues/19845 PR-URL: https://github.com/nodejs/node/pull/20161 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/addons-napi/1_hello_world')
-rw-r--r--test/addons-napi/1_hello_world/binding.c4
-rw-r--r--test/addons-napi/1_hello_world/test.js11
2 files changed, 10 insertions, 5 deletions
diff --git a/test/addons-napi/1_hello_world/binding.c b/test/addons-napi/1_hello_world/binding.c
index 27d49079966..6efc14ee66e 100644
--- a/test/addons-napi/1_hello_world/binding.c
+++ b/test/addons-napi/1_hello_world/binding.c
@@ -10,10 +10,8 @@ napi_value Method(napi_env env, napi_callback_info info) {
return world;
}
-napi_value Init(napi_env env, napi_value exports) {
+NAPI_MODULE_INIT() {
napi_property_descriptor desc = DECLARE_NAPI_PROPERTY("hello", Method);
NAPI_CALL(env, napi_define_properties(env, exports, 1, &desc));
return exports;
}
-
-NAPI_MODULE(NODE_GYP_MODULE_NAME, Init)
diff --git a/test/addons-napi/1_hello_world/test.js b/test/addons-napi/1_hello_world/test.js
index c975c48a733..d1d67d34f68 100644
--- a/test/addons-napi/1_hello_world/test.js
+++ b/test/addons-napi/1_hello_world/test.js
@@ -1,6 +1,13 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
-const addon = require(`./build/${common.buildType}/binding`);
+const bindingPath = require.resolve(`./build/${common.buildType}/binding`);
+const binding = require(bindingPath);
+assert.strictEqual(binding.hello(), 'world');
+console.log('binding.hello() =', binding.hello());
-assert.strictEqual(addon.hello(), 'world');
+// Test multiple loading of the same module.
+delete require.cache[bindingPath];
+const rebinding = require(bindingPath);
+assert.strictEqual(rebinding.hello(), 'world');
+assert.notStrictEqual(binding.hello, rebinding.hello);