Summary: | Math Javascript Bug on Safari 5 (webkit 533.16) under "32bit" mode | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Darth <priyajeet.hora> | ||||
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | RESOLVED FIXED | ||||||
Severity: | Critical | CC: | ap, barraclough, noel.gordon, oliver, priyajeet.hora | ||||
Priority: | P1 | Keywords: | InRadar | ||||
Version: | 528+ (Nightly build) | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
Attachments: |
|
Description
Darth
2010-06-09 10:00:45 PDT
Actually changing it to 30 bits as mentioned above has other multiplication/subtraction issues, so it is not a fix. Additional information from the author - After some further investigation, there appears to be a bug in Safari's JS engine. The following code/URL demonstrates the problem: javascript:var a=new Array();a[0]=Math.pow(10,8);alert((a[0]>>27)|0); If you inspect the code, you can easily prove to yourself that the correct value for the alert is "0", which is what you get on most browsers. On Safari for Windows 32-bit, I get "100000000". Given the subtlety of this bug and the fact that I don't really understand its root cause, I don't think it makes sense to try to make a workaround in JSBN since it is not clear where else this bug might manifest itself. One of us should file a bug report with Apple for this. Tom Changed the title to mention its a general problem and not in particular with the library mentioned. Typing javascript:alert((Math.pow(10,8)>>27 | 0)) in the browser address bar shows. (In reply to comment #4) > Changed the title to mention its a general problem and not in particular with the library mentioned. > Typing javascript:alert((Math.pow(10,8)>>27 | 0)) in the browser address bar shows. I'll look at this tonight, i suspect it's my fault. Slightly simplified: javascript:g=100000000.1;alert((g >> 27 | 0)) I would guess is that we're assuming any integer result is in a specific register when we get to the | but in the double case we're not actually doing that. Turning a build with my fix now. (In reply to comment #1) > Actually changing it to 30 bits as mentioned above has other multiplication/subtraction issues, so it is not a fix. Also it was papering over the issue -- basically the issue is that a right shift of a value that is internally stored as a double fails to correctly set the integer flag on the internal value at the end of the shift. A few work arounds are possible but it depends on exactly what's happening. If the issue is specifically an expression of the form a >> n | 0 My question is what range of values do you expect a to have? (a | 0) >> n Should produce the desired result (if my understanding of what you're trying to do is correct) Created attachment 58442 [details]
Patch
Committed r60990: <http://trac.webkit.org/changeset/60990> *** Bug 40355 has been marked as a duplicate of this bug. *** *** Bug 40306 has been marked as a duplicate of this bug. *** |