Early error on '0' followed by '8' or '9' in numeric literals does not seem to be web-compatible

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Aug 5 11:13:24 PDT 2014

On Aug 5, 2014, at 8:38 AM, Mathias Bynens wrote:

> On 5 Aug 2014, at 17:19, Mark S. Miller <erights at google.com> wrote:
>> On Tue, Aug 5, 2014 at 8:17 AM, Mathias Bynens <mathias at qiwi.be> wrote:
>>> The literals under discussion (e.g. `08` and `09`) are not octal literals.
>> Strict mode should reject these even more vehemently! (Allen, can we have an early vehement error?)

I think we weren't clear enough in the ES5 spec.  The base-line grammar says that starting a decimal literal (other than a single '0') with a 'o' is not valid syntax.  You should expect to get a syntax error for 00, or 07, or 08, or0123456789, or 01234567, etc.  ES5 Annex B defines an extension that makes sequences of digits (excluding '8' or '9') legal syntax.  But section 7.8.3 says that that particular extension is not allowed in strict mode code.

The problem is that there is another extensions (that is not in ES5 Annex B) that allows and gives meaning for '0' followed by digit sequences that include the digits '8' and/or '9'.  I'm pretty sure that when drafting ES5 we thought the restriction in 7.8.3 was making making both of these extensions illegal in strict mode. Apparently most real world browsers didn't interpret things that way which is unfortunate.

> Now I’m confused again. That contradicts what Allen said earlier in this thread:
> On 5 Aug 2014, at 16:20, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> Regarding, leading 0 constants in strict mode. The long term plan is to eventually make them legal decimal constants.
> I stand by my earlier suggestion:
> 1. Accept decimal integer literals with leading `0`, even in strict mode.
> 2. Interpret the value of such literals as octal in case they consist of octal digits only. (Note: this is already in Annex B – see `LegacyOctalIntegerLiteral`.)
> Strict mode would accept `08` as it’s a zero-prefixed decimal literal but not `07` since that’s an octal literal.
> This matches what all browsers already do (except Firefox), and fulfills the long-term plan Allen was talking about.

I think this is more or less the strategy we should follow.

All browsers in all modes apparently interpret leading 0 numbers that contain the digits "8" or "9" as decimal literals.  We should make that part of the base language for ES6.

The ES6 base language should make leading 0 numbers containing only octal digits ("1"-"7") syntactically illegal.

Annex B can continue to define the meaning for  such leading 0 octal numbers.  And strict mode still makes that annex B extension illegal

Someday, when strict mode/modules is more dominant we can relax the restriction of leaning 0 numbers without "8" or "9" and make all leading 0 numbers decimal literals in strict mode.


More information about the es-discuss mailing list