Closed Bug 126159 Opened 23 years ago Closed 23 years ago

Integer not always converted to integer correctly

Categories

(Core :: JavaScript Engine, defect)

x86
Windows ME
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: shd, Assigned: khanson)

Details

Attachments

(1 file)

I use the SpiderMonkey engine in a project of my own. I have found that some values specified as integers, although stored correctly, are incorrectly converted by JS_ValueToInt32 (and possibly others as well). JavaScript: const WHITE=0xFFFFFF; CallCFunction (WHITE); C: #define WHITE 0xFFFFFF int i; JS_ValueToInt32 (cx, *vp, &b); if (i == WHITE) { printf ("OK!"); } else { printf ("0x%08X", i); } Output: 0x01000000 Perhaps JS_ValueToInt32 should first check JSVAL_IS_INT. That would also eliminate the conversion to double and other operations, thereby increasing performance.
The &b is a typo and should be &i, obviously.
cc'ing Brendan on this one -
Assignee: rogerl → khanson
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: Integer not always converted to integer correctly. → Integer not always converted to integer correctly
JS_ValueToInt32 is an old API entry point, deprecated in favor of JS_ValueToECMAInt32. If you can use the latter, please do so. I agree that js_ValueToInt32 in jsnum.c should have an early out for int-tagged jsvals, patch coming up. I trust doing so will not break anyone using this old API -- it is an incompatible change, however! Presumably, anyone using it was not counting on the buggy behavior Steven reports. /be
Attached patch proposed fixSplinter Review
Let's try for 0.9.9, this is an easy one. /be
Comment on attachment 70133 [details] [diff] [review] proposed fix r=shaver. (If jband finds something I missed in _this_ one, I'm hanging up my spurs.)
Attachment #70133 - Flags: review+
Comment on attachment 70133 [details] [diff] [review] proposed fix sr=jband
Attachment #70133 - Flags: superreview+
Fixed.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Marking Verified -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: