summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorhimself65 <himself65@outlook.com>2019-10-17 14:13:57 +0800
committerRich Trott <rtrott@gmail.com>2020-01-11 18:50:28 -0800
commit6219f1fb447042106177efcb61e75b6e89bd0e03 (patch)
tree454853ffac3a0b01daf868fc38f4e048c9e4c3a0 /test
parent57351b628cae6167f03c0417a5e2334da574a743 (diff)
downloadnode-new-6219f1fb447042106177efcb61e75b6e89bd0e03.tar.gz
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 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')
-rw-r--r--test/js-native-api/test_object/test.js7
-rw-r--r--test/js-native-api/test_object/test_object.c30
2 files changed, 36 insertions, 1 deletions
diff --git a/test/js-native-api/test_object/test.js b/test/js-native-api/test_object/test.js
index 33ab49bb6f..2cd65af6b3 100644
--- a/test/js-native-api/test_object/test.js
+++ b/test/js-native-api/test_object/test.js
@@ -212,8 +212,10 @@ assert.strictEqual(newObject.test_string, 'test string');
inherited: 1
});
+ const fooSymbol = Symbol('foo');
+
object.normal = 2;
- object[Symbol('foo')] = 3;
+ object[fooSymbol] = 3;
Object.defineProperty(object, 'unenumerable', {
value: 4,
enumerable: false,
@@ -224,6 +226,9 @@ assert.strictEqual(newObject.test_string, 'test string');
assert.deepStrictEqual(test_object.GetPropertyNames(object),
['5', 'normal', 'inherited']);
+
+ assert.deepStrictEqual(test_object.GetSymbolNames(object),
+ [fooSymbol]);
}
// Verify that passing NULL to napi_set_property() results in the correct
diff --git a/test/js-native-api/test_object/test_object.c b/test/js-native-api/test_object/test_object.c
index db2d30c64a..bcb295197f 100644
--- a/test/js-native-api/test_object/test_object.c
+++ b/test/js-native-api/test_object/test_object.c
@@ -1,3 +1,5 @@
+#define NAPI_EXPERIMENTAL
+
#include <js_native_api.h>
#include "../common.h"
#include <string.h>
@@ -82,6 +84,33 @@ static napi_value GetPropertyNames(napi_env env, napi_callback_info info) {
return output;
}
+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 Set(napi_env env, napi_callback_info info) {
size_t argc = 3;
napi_value args[3];
@@ -449,6 +478,7 @@ napi_value Init(napi_env env, napi_value exports) {
DECLARE_NAPI_PROPERTY("Get", Get),
DECLARE_NAPI_PROPERTY("GetNamed", GetNamed),
DECLARE_NAPI_PROPERTY("GetPropertyNames", GetPropertyNames),
+ DECLARE_NAPI_PROPERTY("GetSymbolNames", GetSymbolNames),
DECLARE_NAPI_PROPERTY("Set", Set),
DECLARE_NAPI_PROPERTY("SetNamed", SetNamed),
DECLARE_NAPI_PROPERTY("Has", Has),