# HG changeset patch # User Sankha Narayan Guria # Date 1391022887 -19800 # Node ID 962870d8075eb00eff511616583c906a68fe895a # Parent 9e06d42c2a6ad84eb6b701105b544cf031fad0b9 Bug 957513 - DecimalIntegerLiteral cannot be 0 directly followed by 8 or 9; r=jorendorff diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -1385,30 +1385,26 @@ TokenStream::getTokenInternal(Modifier m goto error; } numStart = userbuf.addressOfNextRawChar() - 1; // one past the '0o' while ('0' <= c && c <= '7') c = getCharIgnoreEOL(); } else if (JS7_ISDEC(c)) { radix = 8; numStart = userbuf.addressOfNextRawChar() - 1; // one past the '0' + + // Octal integer literals are not permitted in strict mode code. + if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL)) + goto error; + while (JS7_ISDEC(c)) { - // Octal integer literals are not permitted in strict mode code. - if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL)) - goto error; - - // Outside strict mode, we permit 08 and 09 as decimal numbers, - // which makes our behaviour a superset of the ECMA numeric - // grammar. We might not always be so permissive, so we warn - // about it. + // Even in sloppy mode, 08 or 09 is a syntax error. if (c >= '8') { - if (!reportWarning(JSMSG_BAD_OCTAL, c == '8' ? "08" : "09")) { + if (!reportError(JSMSG_BAD_OCTAL, c == '8' ? "8" : "9")) goto error; - } - goto decimal; // use the decimal scanner for the rest of the number } c = getCharIgnoreEOL(); } } else { // '0' not followed by 'x', 'X' or a digit; scan as a decimal number. numStart = userbuf.addressOfNextRawChar() - 1; goto decimal; } diff --git a/js/src/jit-test/tests/parser/parseOctal.js b/js/src/jit-test/tests/parser/parseOctal.js new file mode 100644 --- /dev/null +++ b/js/src/jit-test/tests/parser/parseOctal.js @@ -0,0 +1,8 @@ +load(libdir + 'asserts.js'); + +for (var code of ["08", "09", "01238", "01239", "08e+1"]) { + assertThrowsInstanceOf(() => Function(code), SyntaxError); + assertThrowsInstanceOf(() => eval(code), SyntaxError); +} + +var ok = [0.8, 0.08, 0e8]; diff --git a/js/src/js.msg b/js/src/js.msg --- a/js/src/js.msg +++ b/js/src/js.msg @@ -190,17 +190,17 @@ MSG_DEF(JSMSG_MISSING_EXPONENT, 13 MSG_DEF(JSMSG_OUT_OF_MEMORY, 137, 0, JSEXN_ERR, "out of memory") MSG_DEF(JSMSG_UNTERMINATED_STRING, 138, 0, JSEXN_SYNTAXERR, "unterminated string literal") MSG_DEF(JSMSG_TOO_MANY_PARENS, 139, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression") MSG_DEF(JSMSG_UNTERMINATED_COMMENT, 140, 0, JSEXN_SYNTAXERR, "unterminated comment") MSG_DEF(JSMSG_UNTERMINATED_REGEXP, 141, 0, JSEXN_SYNTAXERR, "unterminated regular expression literal") MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 142, 0, JSEXN_TYPEERR, "bad cloned function scope chain") MSG_DEF(JSMSG_MISSING_OCTAL_DIGITS, 143, 0, JSEXN_SYNTAXERR, "missing octal digits after '0o'") MSG_DEF(JSMSG_ILLEGAL_CHARACTER, 144, 0, JSEXN_SYNTAXERR, "illegal character") -MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "{0} is not a legal ECMA-262 octal constant") +MSG_DEF(JSMSG_BAD_OCTAL, 145, 1, JSEXN_SYNTAXERR, "numbers starting with 0 followed by a digit are octals and can't contain {0}") MSG_DEF(JSMSG_RESULTING_STRING_TOO_LARGE, 146, 0, JSEXN_RANGEERR, "repeat count must be less than infinity and not overflow maximum string size") MSG_DEF(JSMSG_UNCAUGHT_EXCEPTION, 147, 1, JSEXN_INTERNALERR, "uncaught exception: {0}") MSG_DEF(JSMSG_INVALID_BACKREF, 148, 0, JSEXN_SYNTAXERR, "non-octal digit in an escape sequence that doesn't match a back-reference") MSG_DEF(JSMSG_BAD_BACKREF, 149, 0, JSEXN_SYNTAXERR, "back-reference exceeds number of capturing parentheses") MSG_DEF(JSMSG_PRECISION_RANGE, 150, 1, JSEXN_RANGEERR, "precision {0} out of range") MSG_DEF(JSMSG_BAD_GETTER_OR_SETTER, 151, 1, JSEXN_TYPEERR, "invalid {0} usage") MSG_DEF(JSMSG_BAD_ARRAY_LENGTH, 152, 0, JSEXN_RANGEERR, "invalid array length") MSG_DEF(JSMSG_CANT_DESCRIBE_PROPS, 153, 1, JSEXN_TYPEERR, "can't describe non-native properties of class {0}")