diff options
author | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-11-17 12:34:54 -0800 |
---|---|---|
committer | Gabriel Schulhof <gabriel.schulhof@intel.com> | 2018-12-04 13:58:17 -0800 |
commit | 938e11882b96e19b443477571455088baaa054d8 (patch) | |
tree | eb828a60957a2881995ba9a83f44a32a18fbff16 /test/js-native-api/4_object_factory | |
parent | 83ee137c4565112177f22f2c735b266b22262220 (diff) | |
download | android-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.gz android-node-v8-938e11882b96e19b443477571455088baaa054d8.tar.bz2 android-node-v8-938e11882b96e19b443477571455088baaa054d8.zip |
test: partition N-API tests
Partition test/addons-napi into test/js-native-api and test/node-api to
isolate the Node.js-agnostic portion of the N-API tests from the
Node.js-specific portion.
PR-URL: https://github.com/nodejs/node/pull/24557
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'test/js-native-api/4_object_factory')
-rw-r--r-- | test/js-native-api/4_object_factory/binding.c | 23 | ||||
-rw-r--r-- | test/js-native-api/4_object_factory/binding.gyp | 11 | ||||
-rw-r--r-- | test/js-native-api/4_object_factory/test.js | 8 |
3 files changed, 42 insertions, 0 deletions
diff --git a/test/js-native-api/4_object_factory/binding.c b/test/js-native-api/4_object_factory/binding.c new file mode 100644 index 0000000000..5e1403a892 --- /dev/null +++ b/test/js-native-api/4_object_factory/binding.c @@ -0,0 +1,23 @@ +#include <js_native_api.h> +#include "../common.h" + +static napi_value CreateObject(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value args[1]; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, NULL, NULL)); + + napi_value obj; + NAPI_CALL(env, napi_create_object(env, &obj)); + + NAPI_CALL(env, napi_set_named_property(env, obj, "msg", args[0])); + + return obj; +} + +EXTERN_C_START +napi_value Init(napi_env env, napi_value exports) { + NAPI_CALL(env, + napi_create_function(env, "exports", -1, CreateObject, NULL, &exports)); + return exports; +} +EXTERN_C_END diff --git a/test/js-native-api/4_object_factory/binding.gyp b/test/js-native-api/4_object_factory/binding.gyp new file mode 100644 index 0000000000..2a144bab42 --- /dev/null +++ b/test/js-native-api/4_object_factory/binding.gyp @@ -0,0 +1,11 @@ +{ + "targets": [ + { + "target_name": "binding", + "sources": [ + "../entry_point.c", + "binding.c" + ] + } + ] +} diff --git a/test/js-native-api/4_object_factory/test.js b/test/js-native-api/4_object_factory/test.js new file mode 100644 index 0000000000..15313c1547 --- /dev/null +++ b/test/js-native-api/4_object_factory/test.js @@ -0,0 +1,8 @@ +'use strict'; +const common = require('../../common'); +const assert = require('assert'); +const addon = require(`./build/${common.buildType}/binding`); + +const obj1 = addon('hello'); +const obj2 = addon('world'); +assert.strictEqual(`${obj1.msg} ${obj2.msg}`, 'hello world'); |