asm-js / validator

A reference validator for asm.js.
Apache License 2.0
1.78k stars 148 forks source link

There are technically no negative numeric literals in ECMAScript. #67

Closed cscott closed 10 years ago

cscott commented 11 years ago

The official ECMAScript grammar parses negative literals as applications of unary minus to a non-negative numeric literal. The ECMAScript grammar (see section 7.8.3 of ECMA-262 5th edition) does not allow a leading + or - sign for a numeric literal.

Currently the spidermonkey asm.js parser accepts "-5" as a numeric literal, as well as "-(5)", but rejects "+5" (and rejects "+(5)" as well).

To be rigorously correct, either you need to introduce a new AsmJSNumericLiteral production which allows the leading -, or add a note to section 4 indicating that all uses of NumericLiteral are intended to also match a leading minus, followed by an optionally-parenthesized NumericLiteral.

jruderman commented 11 years ago

Is (-(0xfeedbeef)) an invalid out-of-range integer literal, or is it an asm unary minus operation applied to an int (which happens to be an unsigned)?

cscott commented 11 years ago

https://bugzilla.mozilla.org/show_bug.cgi?id=886285 is related. We need to be careful about how we define negative integer literals. Both @jruderman's example from the comment above, and his example in bug 886285 (negative zero) need to be handled carefully.

ghost commented 10 years ago

The spec handles negative numbers by explicitly handling the negative sign for NumericLiterals wherever they may occur.