n-api: add method to get own property names #28942
Labels
feature request
Issues that request new features to be added to Node.js.
node-api
Issues and PRs related to the Node-API.
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:
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.
The text was updated successfully, but these errors were encountered: