Subj : Re: Class width SpiderMonkey To : Jan Herling From : Brendan Eich Date : Thu Nov 06 2003 10:15 am Jan Herling wrote: >Here is the important part of my Spidermonkey-Class: > >JSBool ClassASetValue(JSContext *cx, JSObject *obj, double value) >{ > jsval val; > JS_NewDoubleValue(cx, (jsdouble) value, &val); > JS_SetProperty(cx, obj, "a", &val); > .... >} > > >JSBool ClassAGetValue(JSContext *cx, JSObject *obj, float *value) >{ > jsval val; > jsdouble jsd; > ....... > JS_GetProperty(cx, obj, "a", &val); > jsd = *JSVAL_TO_DOUBLE(val); ("or") >JS_ValueToNumber(cx, val, &jsd); (makes no differents - allways >breaks down here if : "ca.a = 1" ) > *value = (float) jsd; > ....... >} > >I think this is a problem with the conversion from JSVAL to DOUBLE. >Is this a well known problem or bug? >Or did I make a big mistake? > > You made a mistake. Two, actually: 1. In ClassASetValue, use JS_NewNumberValue, not JS_NewDoubleValue. Let the engine optimize 0 and 1 storage. 2. You cannot assume that JSVAL_IS_DOUBLE(val) before calling JSVAL_TO_DOUBLE. Use JS_ValueToNumber. If you still have problems after fixing these, please send or post complete code and say exactly how it fails. /be .