diff options
Diffstat (limited to 'test/addons-napi/1_hello_world')
-rw-r--r-- | test/addons-napi/1_hello_world/binding.c | 22 | ||||
-rw-r--r-- | test/addons-napi/1_hello_world/binding.gyp | 8 | ||||
-rw-r--r-- | test/addons-napi/1_hello_world/test.js | 6 |
3 files changed, 36 insertions, 0 deletions
diff --git a/test/addons-napi/1_hello_world/binding.c b/test/addons-napi/1_hello_world/binding.c new file mode 100644 index 00000000000..882508b9548 --- /dev/null +++ b/test/addons-napi/1_hello_world/binding.c @@ -0,0 +1,22 @@ +#include <node_api.h> + +void Method(napi_env env, napi_callback_info info) { + napi_status status; + napi_value world; + status = napi_create_string_utf8(env, "world", -1, &world); + if (status != napi_ok) return; + status = napi_set_return_value(env, info, world); + if (status != napi_ok) return; +} + +#define DECLARE_NAPI_METHOD(name, func) \ + { name, func, 0, 0, 0, napi_default, 0 } + +void Init(napi_env env, napi_value exports, napi_value module, void* priv) { + napi_status status; + napi_property_descriptor desc = DECLARE_NAPI_METHOD("hello", Method); + status = napi_define_properties(env, exports, 1, &desc); + if (status != napi_ok) return; +} + +NAPI_MODULE(addon, Init) diff --git a/test/addons-napi/1_hello_world/binding.gyp b/test/addons-napi/1_hello_world/binding.gyp new file mode 100644 index 00000000000..62381d5e54f --- /dev/null +++ b/test/addons-napi/1_hello_world/binding.gyp @@ -0,0 +1,8 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ "binding.c" ] + } + ] +} diff --git a/test/addons-napi/1_hello_world/test.js b/test/addons-napi/1_hello_world/test.js new file mode 100644 index 00000000000..c975c48a733 --- /dev/null +++ b/test/addons-napi/1_hello_world/test.js @@ -0,0 +1,6 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); + +assert.strictEqual(addon.hello(), 'world'); |