Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api: add method to get own property names #28942

Closed
anthony-tuininga opened this issue Aug 2, 2019 · 3 comments
Closed

n-api: add method to get own property names #28942

anthony-tuininga opened this issue Aug 2, 2019 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js. node-api Issues and PRs related to the Node-API.

Comments

@anthony-tuininga
Copy link
Contributor

anthony-tuininga commented Aug 2, 2019

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.

@devsnek devsnek added feature request Issues that request new features to be added to Node.js. node-api Issues and PRs related to the Node-API. labels Aug 2, 2019
@devsnek
Copy link
Member

devsnek commented Aug 2, 2019

@nodejs/n-api

@himself65
Copy link
Member

I'm working on this

@gabrielschulhof
Copy link
Contributor

With #30006 having landed, we now have this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. node-api Issues and PRs related to the Node-API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants