-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: make napi_get_property_names return strings #27524
Conversation
The documentation says that this method returns an array of strings. Currently, it does not do so for indices. Resolve that by telling V8 explicitly to convert to string. Fixes: nodejs#27496
auto maybe_propertynames = obj->GetPropertyNames(context); | ||
v8::MaybeLocal<v8::Array> maybe_propertynames = obj->GetPropertyNames( | ||
context, | ||
v8::KeyCollectionMode::kIncludePrototypes, |
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.
Should napi_get_property_names
return all property names including these on prototypes? Or kOwnOnly
is just fine.
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.
I think that would have been a good idea when this API was originally conceived, but it would be a breaking change to switch this over, and we generally don’t do that for N-API.
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.
I think it's a good idea to add another napi_get_own_propery_names
. I can do that if others agree.
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.
@BridgeAR I think that’s a good idea. I think we’d also maybe want to include non-enumerable properties/symbols, because there doesn’t currently appear to be a way to get those (maybe as an option, similar to the way in which the V8 API leaves us the choice).
auto maybe_propertynames = obj->GetPropertyNames(context); | ||
v8::MaybeLocal<v8::Array> maybe_propertynames = obj->GetPropertyNames( | ||
context, | ||
v8::KeyCollectionMode::kIncludePrototypes, |
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.
I think it's a good idea to add another napi_get_own_propery_names
. I can do that if others agree.
Landed in 5c08481. |
The documentation says that this method returns an array of strings. Currently, it does not do so for indices. Resolve that by telling V8 explicitly to convert to string. PR-URL: #27524 Fixes: #27496 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The documentation says that this method returns an array of strings. Currently, it does not do so for indices. Resolve that by telling V8 explicitly to convert to string. PR-URL: #27524 Fixes: #27496 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
The documentation says that this method returns an array of strings.
Currently, it does not do so for indices. Resolve that by telling
V8 explicitly to convert to string.
Fixes: #27496
/cc @nodejs/n-api
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes