From 4851bb35f5ad19a9ab96f1ea681241efe4a38dbe Mon Sep 17 00:00:00 2001 From: himself65 Date: Thu, 17 Oct 2019 14:13:57 +0800 Subject: [PATCH 1/4] n-api: add napi_get_all_property_names Co-Authored-By: Gabriel Schulhof --- doc/api/n-api.md | 90 +++++++++++++++++++++++++++++++++++++++ src/js_native_api.h | 9 ++++ src/js_native_api_types.h | 21 +++++++++ src/js_native_api_v8.cc | 88 +++++++++++++++++++++++++++++++++----- src/js_native_api_v8.h | 11 +++++ 5 files changed, 208 insertions(+), 11 deletions(-) diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 4cb08b171d9d86..30e2c89334d97b 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -1656,6 +1656,65 @@ However, for better performance, it's better for the caller to make sure that the `napi_value` in question is of the JavaScript type expected by the API. ### Enum types +#### napi_key_collection_mode + + +> Stability: 1 - Experimental + +```C +typedef enum { + napi_key_include_prototypes, + napi_key_own_only +} napi_key_collection_mode; +``` + +Describes the `Keys/Properties` filter enums: + +`napi_key_conversion` limits the range of collected properties. +`napi_key_own_only` limits the collected properties to the given +Object only. `napi_key_include_prototypes` will include all keys +of the objects's prototype chain as well. + +#### napi_key_filter + + +> Stability: 1 - Experimental + +```C +typedef enum { + napi_key_all_properties = 0, + napi_key_writable = 1, + napi_key_enumerable = 1 << 1, + napi_key_configurable = 1 << 2, + napi_key_skip_strings = 1 << 3, + napi_key_skip_symbols = 1 << 4 +} napi_key_filter; +``` + +Property filter bits. They can be or'ed to build a composite filter. + +#### napi_key_conversion + + +> Stability: 1 - Experimental + +```C +typedef enum { + napi_key_keep_numbers, + napi_key_numbers_to_strings +} napi_key_conversion; +``` + +`napi_key_numbers_to_strings` will convert integer indices to +strings. `napi_key_keep_numbers` will return numbers for integer +indices. + #### napi_valuetype ```C @@ -3528,6 +3587,37 @@ This API returns the names of the enumerable properties of `object` as an array of strings. The properties of `object` whose key is a symbol will not be included. +#### napi_get_all_property_names + + +> Stability: 1 - Experimental + +```C +napi_get_all_property_names(napi_env env, + napi_value object, + napi_key_collection_mode key_mode, + napi_key_filter key_filter, + napi_key_conversion key_conversion, + napi_value* result); +``` + +* `[in] env`: The environment that the N-API call is invoked under. +* `[in] object`: The object from which to retrieve the properties. +* `[in] key_mode`: Whether to retrieve prototype properties as well. +* `[in] key_filter`: Which properties to retrieve +(enumerable/readable/writable). +* `[in] key_conversion`: Whether to convert numbered property keys to strings. +* `[out] result`: A `napi_value` representing an array of JavaScript values +that represent the property names of the object. [`napi_get_array_length`][] and +[`napi_get_element`][] can be used to iterate over `result`. + +Returns `napi_ok` if the API succeeded. + +This API returns an array containing the names of the available properties +of this object. + #### napi_set_property