Subj : Re: Another JS question To : netscape.public.mozilla.jseng From : Issac Goldstand Date : Sun May 09 2004 01:51 am "Brendan Eich" wrote in message news:409A7DC5.8030109@meer.net... > Issac Goldstand wrote: > > > JSIDArray *jids=JS_Enumerate(cx,obj); > > for (int i=0;i< jids->length;i++) { > > if (JS_IdToValue(cx,jids->vector[i],&rval)) { > > ... examine and process rval ... > > You'd then call JS_GetUCProperty or JS_GetElement, depending on whether > JSVAL_IS_STRING(rval) -- if it is, call JS_GetStringChars and > JS_GetStringLength to gather the name and length parameters to > JS_GetUCProperty; else JSVAL_IS_INT(rval) and you can index into the > object using JSVAL_TO_INT(rval). Does that mean that the array of property IDs returned from JS_Enumerate will be jsvals which contain either the property name in a JS_String or the numeric element ID of the element? Is this always true? Can there be both in an object? (I'd imagine yes, as my own example proves) > > > } else { > > ... handle unexpected "holes" in JSIDArray > > No, if JS_IdToValue returns false (which can't happen in the current > codebase, btw), there was an error and you should propagate it. That > says to test if (!JS_IdToValue(...)) and return JS_FALSE, avoiding the > else clause. I would have thought to use the else to either plug an UNDEFINED value or spew some (hopefully) somewhat useful message to STDERR... Issac .