Subj : Re: GetProperty To : netscape.public.mozilla.jseng From : "Jochen Stier" Date : Wed Feb 11 2004 08:33 am >Cool -- I am ex-SGI ('85-'92), glad to hear of an >OpenInventor/SpiderMonkey combo. He, nice! Then you know what I am up to. I am using the coin3d implementation, tho. It is the same Api but different authors... >You should instead return JS_NewNumberValue(iContext, lValue, vp). That is exactly what I needed to know. Thxs Cheers Jochen "Brendan Eich" wrote in message news:40298952.6040309@meer.net... > Brendan Eich wrote: > > >> JSBool ScrSFVec3f::JSGetProperty(JSContext* iContext, JSObject* iObject, > >> jsval id, jsval *vp) > >> { > >> if (JSVAL_IS_INT (id)) > >> { > >> SoSFVec3f* lVector = (SoSFVec3f*) JS_GetPrivate(iContext, > >> iObject); > >> > >> static double lValue; > >> lValue = lVector->getValue()[JSVAL_TO_INT(id)]; > >> *vp = DOUBLE_TO_JSVAL(&lValue); > >> } > >> return JS_TRUE; > >> } > >> > >> > >> Now, my question is if the Javascript engine makes a copy of the > >> double, or does it come back to the memory location of lValue > >> whenever it needs to read the value of the double. This is important > >> for the following javascript > > > > > > It's important for the above example too -- you're returning the > > address of a stack temporary that goes out of scope as soon as > > ScrSFVec3f::JSGetProperty returns! > > > > Be careful with pointers (addresses) in C ;-). > > > And I should be careful with my skimming of your code! Sorry, I missed > the "static" storage class on double lValue (need my eyes examined). > > But my final point stands. You can't take any old jsdouble address and > tag it as a jsval and store it in a property or other place known to the > GC. Only GC-allocated jsdoubles can be so tagged. Hope this is all > clear now. > > /be .