You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
napi_get_property_names is documented to return "A napi_value representing an array of JavaScript values that represent the property names of the object". It's very unexpected that it would convert strings to numbers, since that doesn't match the output of Object.getOwnPropertyNames:
I am developing an extension with N-API via node-addon-api, and I have a function that takes arbitrary values. To ensure that it was complete, I have a unit test that passes in an object with string keys that have numbers in them:
consta={b: 123,"44": 56};myFunc(a);
Inside the implementation of myFunc, I have this code
auto ov = info[0].As<Napi::Object>();
Napi::Array props = ov.GetPropertyNames();
for (uint32_t i = 0; i < length; i++) {
if (key.IsString()) {
// OK
} else {
// Throw exception for non-string key
}
}
and I'm hitting the exception case!
in the lldb debugger, I print out the list:
> debug_json(props)
"[44,\"b\"]"
Looking at the source of Object::GetPropertyNames(), it just calls N-API napi_get_property_names(), which calls into V8 v8::Object::GetPropertyNames(), at which point it suggests to me that this is a V8 bug.
Version: v11.12.0
Platform: Darwin 2012MBP13.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
Subsystem: V8 / N-API
The text was updated successfully, but these errors were encountered:
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
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: #27524Fixes: #27496
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Summary
napi_get_property_names is documented to return "A napi_value representing an array of JavaScript values that represent the property names of the object". It's very unexpected that it would convert strings to numbers, since that doesn't match the output of
Object.getOwnPropertyNames
:napi_get_property_names()
output is[44,"b"]
Context
I am developing an extension with N-API via
node-addon-api
, and I have a function that takes arbitrary values. To ensure that it was complete, I have a unit test that passes in an object with string keys that have numbers in them:Inside the implementation of myFunc, I have this code
and I'm hitting the exception case!
in the lldb debugger, I print out the list:
Looking at the source of
Object::GetPropertyNames()
, it just calls N-APInapi_get_property_names()
, which calls into V8v8::Object::GetPropertyNames()
, at which point it suggests to me that this is a V8 bug.The text was updated successfully, but these errors were encountered: