-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Description
Is your feature request related to a problem? Please describe.
Yes. The need is to only examine properties owned by the object, not properties found on Object.prototype. The C++ API in use before N-API had a GetOwnPropertyNames() method. That appears to be missing from N-API.
Describe the solution you'd like
Ideally, a method like this:
napi_status napi_get_own_property_names(napi_env env,
napi_value object,
napi_value* result);Describe alternatives you've considered
(1) call napi_get_property_names() and then call napi_has_own_property() on each entry as you iterate through the provided array. If you need to allocate memory for each entry, however, you either need to iterate through the array twice (once to get the number of owned properties and once to do stuff with the array) or you need to over-allocate memory.
(2) call "Object.getOwnPropertyNames()" directly. This requires calling napi_get_global(), napi_get_named_property() twice (once to get "Object" and the second to get "getOwnPropertyNames") and then call napi_call_function() -- which is a lot of calls to do one common operation.