-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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 napi_get_own_property_names #28944
Conversation
@nodejs/n-api I feel like this approach kind of leads to questions like “what if we also want symbols/inherited properties/no indices/…”, and we might want to come up with something that has flexibility which is similar to the V8 API? |
e5c0692
to
2e62342
Compare
+1 to making it more flexible as long as the options supported are part of the standard and will be supported by all engines. |
@addaleax @mhdawson @nodejs/n-api Are we likely to land this? If not, I'd like to close it. If we're likely to land it, I'd like to nudge it forward. /ping @himself65! Or maybe reviewers can perhaps push fixup changes to the branch to get it where it needs to go and expedite things a bit? |
@Trott Yes, but @mhdawson’s comment need to be addressed and we do need somebody (e.g. @himself65) to figure out in what way we expose the other option flags, if we do so. |
I will push fixed changes later :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is good, but we really need to return napi_pending_exception
whenever there is the possibility that an exception has occurred on the JS side.
ffd2f2e
to
b505c1d
Compare
2564901
to
d596434
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, code-wise this LGTM, but I still feel like the API should expose flags similar to the ones we get from V8, otherwise this just begs for Yet Another Function That Does The Same Thing.
@himself65 can you please check whether other engines, such as JerryScript, have the facilities to retrieve property names as selectively as V8? That is, could the kind of flexibility that V8 provides (skipping/not skipping symbols, rendering as string/leaving as number) be implemented
if needed? |
@gabrielschulhof From a look at JerryScript’s API docs, the API only exposes a way to get enumerable properties. But I wouldn’t care too much for that here – any spec-compatible JS implementation needs to have a way to provide all properties, because it could always be implemented in terms of JS builtin functions. |
the js spec has operations that ask for a filtered subset of own properties, so I think it's reasonable that we can provide something similar here. Even if a napi wrapper has to do the work instead of the engine. |
@devsnek @addaleax sounds like we can safely expose the full flexibility provided by V8 because on other engines this same flexibility can be implemented by either filtering after then engine's native API returns, or calling a spec-compliant JS API if the native API is incapable of returning unfiltered results. Similarly, I guess we can use type coercion in post-processing to address the flexibility in the second parameter. @himself65 would you mind exposing the two parameters provided by V8? I suppose we'll have to add a Honestly, I'm not sure whether we shouldn't just go with typedef enum {
napi_key_own,
napi_key_all
} napi_key_collection_mode;
typedef enum {
napi_key_strings = 1,
napi_key_symbols = 1 << 1
} napi_key_types;
typedef enum {
napi_keep_numbers,
napi_numbers_to_strings
} napi_key_coercion;
napi_status napi_get_all_property_names(napi_env env,
napi_value object,
napi_key_collection_mode key_mode,
napi_key_types key_types,
napi_key_coercion key_coercion,
napi_value* result); and basically expose We can then re-implement |
Would filter |
@legendecas right, we need one more enum for one more flag to the method. |
I will open a new pull request about that later 🤔 |
ping @himself65 |
How to implement that? 🤔 |
@legendecas Fixed and this pr should after #30006 for now |
876d845
to
ad4a54a
Compare
9bf1126
to
d93c285
Compare
Co-Authored-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
IINM this PR is superseded by #30006, so I will close it. Please re-open if I am mistaken. |
fix #28942, and this pr should after #30006
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes