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:
authorhimself65 <himself65@outlook.com>2019-10-17 09:13:57 +0300
committerBeth Griggs <Bethany.Griggs@uk.ibm.com>2020-03-02 14:05:58 +0300
commitecbb331be0bda5c63f72fe575b3684f00c7164db (patch)
tree6bbb051b168d4c4384b2ba1873eeeceb6f41beab /test/addons-napi/test_object
parent9bd1317764064db9a753212520fe87ac1be69c3e (diff)
n-api: add napi_get_all_property_names
Co-Authored-By: Gabriel Schulhof <gabriel.schulhof@intel.com> PR-URL: https://github.com/nodejs/node/pull/30006 Backport-PR-URL: https://github.com/nodejs/node/pull/31384 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/addons-napi/test_object')
-rw-r--r--test/addons-napi/test_object/test.js4
-rw-r--r--test/addons-napi/test_object/test_object.c29
2 files changed, 33 insertions, 0 deletions
diff --git a/test/addons-napi/test_object/test.js b/test/addons-napi/test_object/test.js
index 8e44a1b5ed6..e86a610547d 100644
--- a/test/addons-napi/test_object/test.js
+++ b/test/addons-napi/test_object/test.js
@@ -5,6 +5,7 @@ const assert = require('assert');
// Testing api calls for objects
const test_object = require(`./build/${common.buildType}/test_object`);
+const fooSymbol = Symbol('foo');
const object = {
hello: 'world',
@@ -16,6 +17,8 @@ const object = {
}
};
+object[fooSymbol] = 3;
+
assert.strictEqual(test_object.Get(object, 'hello'), 'world');
assert.deepStrictEqual(test_object.Get(object, 'array'),
[ 1, 94, 'str', 12.321, { test: 'obj in arr' } ]);
@@ -25,6 +28,7 @@ assert.deepStrictEqual(test_object.Get(object, 'newObject'),
assert(test_object.Has(object, 'hello'));
assert(test_object.Has(object, 'array'));
assert(test_object.Has(object, 'newObject'));
+assert.deepStrictEqual(test_object.GetSymbolNames(object), [fooSymbol]);
const newObject = test_object.New();
assert(test_object.Has(newObject, 'test_number'));
diff --git a/test/addons-napi/test_object/test_object.c b/test/addons-napi/test_object/test_object.c
index 046f71fa414..dbf840cb09c 100644
--- a/test/addons-napi/test_object/test_object.c
+++ b/test/addons-napi/test_object/test_object.c
@@ -1,3 +1,4 @@
+#define NAPI_EXPERIMENTAL
#include <node_api.h>
#include "../common.h"
#include <string.h>
@@ -193,6 +194,33 @@ static napi_value Inflate(napi_env env, napi_callback_info info) {
return obj;
}
+static napi_value GetSymbolNames(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_ASSERT(env, argc >= 1, "Wrong number of arguments");
+
+ napi_valuetype value_type0;
+ NAPI_CALL(env, napi_typeof(env, args[0], &value_type0));
+
+ NAPI_ASSERT(env,
+ value_type0 == napi_object,
+ "Wrong type of arguments. Expects an object as first argument.");
+
+ napi_value output;
+ NAPI_CALL(env,
+ napi_get_all_property_names(
+ env,
+ args[0],
+ napi_key_include_prototypes,
+ napi_key_skip_strings,
+ napi_key_numbers_to_strings,
+ &output));
+
+ return output;
+}
+
static napi_value Wrap(napi_env env, napi_callback_info info) {
size_t argc = 1;
napi_value arg;
@@ -220,6 +248,7 @@ static napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor descriptors[] = {
DECLARE_NAPI_PROPERTY("Get", Get),
DECLARE_NAPI_PROPERTY("Set", Set),
+ DECLARE_NAPI_PROPERTY("GetSymbolNames", GetSymbolNames),
DECLARE_NAPI_PROPERTY("Has", Has),
DECLARE_NAPI_PROPERTY("HasOwn", HasOwn),
DECLARE_NAPI_PROPERTY("Delete", Delete),