Subj : Re: -x when x == 0 treated as a double ? To : bubbfree From : Brendan Eich Date : Wed Jan 26 2005 08:48 am bubbfree@gmail.com wrote: > I have some unexpected behavior in SpiderMonkey (latest RC6). If I do > this: > > var x = 0; > myNativeFunction(-x); > > the jsval in argv[0] for my native handler is of type double. I would > have expected int. > > If I do: > > myNativeFunction(-0); > it gets passed as an int. > > Is this correct behavior? It's a bug, apparently, but I can't reproduce it with RC6 or trunk js shells: [~/src/phoenix/mozilla/js/src-RC6]$ gdb !$ gdb Linux_All_DBG.OBJ/js GNU gdb Red Hat Linux (6.1post-1.20040607.43rh) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1". (gdb) b its_item Breakpoint 1 at 0x804b967: file js.c, line 1662. (gdb) r Starting program: /home/brendan/src/phoenix/mozilla/js/src-RC6/Linux_All_DBG.OBJ/js js> it.item(-0) Breakpoint 1, its_item (cx=0xa02a028, obj=0xa02ba70, argc=1, argv=0xa0341bc, rval=0xfeead820) at js.c:1662 1662 *rval = OBJECT_TO_JSVAL(obj); (gdb) p/x argv[0] $1 = 0xa02bbaa (gdb) p *(double*)($-2) $2 = -0 So what OS make and version are you using, and what C compiler? /be P.S.: Argument conversion advice, you may already know this but I wanted to throw it out for the newgroup: In general it's best to use JS_ValueToNumber, JS_ValueToECMAInt32, or another conversion API (JS_ConvertArguments for _en masse_ conversion, or perhaps JS_ConvertValue) -- don't write tag-specific JSVAL_IS_* or JSVAL_TO_* macros when converting arguments. .