0

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • @FelixKling: I think the "SpiderMonkey: " in the title was helpful to people seeing this question on the front page. The new title is rather vague without looking at the tags. And according to http://meta.stackexchange.com/a/10648/147015 tag-like prefixes are often considered good. – ThiefMaster May 05 '12 at 12:06
  • Mmh, sorry. I keep deleting these tag: things. I didn't even notice it was a question from you.... How about '... in SpiderMonkey' ? :) Glad you figured it out though! – Felix Kling May 05 '12 at 20:53
  • 2
    Sigh, i hate people downvoting questions without leaving a comment why. – ThiefMaster May 21 '12 at 08:31

1 Answers1

0

Looking at existing code which needs this behavior (the json encoder) helped.

JS_IdToValue is the function I was looking for.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636