Bug 24156
| Summary: | Unary + conversion to number fails for negative hexadecimal (-0xff) 0x | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Jorge <jorgechamorro> |
| Component: | JavaScriptCore | Assignee: | Cameron Zwarich (cpst) <zwarich> |
| Status: | RESOLVED INVALID | ||
| Severity: | Normal | CC: | barraclough, jorgechamorro, zwarich |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | All | ||
| OS: | All | ||
| URL: | http://groups.google.com/group/comp.lang.javascript/msg/8f8fcfdc42ee3960 | ||
Jorge
See:
javascript:s= "0x12";alert((+s)+ ","+ parseInt(s,16)); //-> 18,18
but:
javascript:s= "-0x12";alert((+s)+ ","+ parseInt(s,16)); //-> NaN,-18
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Cameron Zwarich (cpst)
This works as expected. See section 9.3.1 of the ECMA spec:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
The ToNumber operation (which is used by the unary plus operator) only handles negative signs for decimal numbers, not hex or octal. It might be a bit strange, but it's the spec.
Jorge
(In reply to comment #1)
>
> The ToNumber operation (which is used by the unary plus operator) only handles
> negative signs for decimal numbers, not hex or octal. It might be a bit
> strange, but it's the spec.
FF, Opera and Chrome handle them fine, and that might be perceived as "better". Better than the spec -if you want- but better, after all. Now, what's the best browser ? Not Safari when it comes to hex string conversion to number... IMO, in this case better is better than the spec. Safari is doing it to/in-spec, but worse.
Cameron Zwarich (cpst)
If it's a potential compatibility issue down the road, then it probably makes sense to match Firefox on this.
Gavin Barraclough
This was a bug in other browsers, and fixed in the latest FireFox. Behaves correctly.