Get property name by id
-
06-06-2021 - |
Question
I'm using this code to iterate over the properties passed to a native function:
JSObject *iter = JS_NewPropertyIterator(cx, jsargs);
jsid id;
while(JS_NextProperty(cx, iter, &id) && id != JSID_VOID) {
jsval vp;
if(!JS_GetPropertyById(cx, jsargs, id, &vp)) {
continue;
}
// ...
}
This works fine to get the value of the property, however, I need the name of that property, too.
I couldn't find any of the various property-related ...ById()
functions which give me the property name.
Solution
Looking at existing code which needs this behavior (the json encoder) helped.
JS_IdToValue
is the function I was looking for.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow