diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index a0883c52b434..ae1b9ec8115f 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -3718,10 +3718,10 @@ bool GeneralParser::maybeParseDirective( // had "use strict"; pc_->sc()->setExplicitUseStrict(); if (!pc_->sc()->strict()) { - // We keep track of the one possible strict violation that could - // occur in the directive prologue -- octal escapes -- and + // We keep track of the possible strict violations that could occur in + // the directive prologue -- deprecated octal syntax -- and // complain now. - if (anyChars.sawOctalEscape()) { + if (anyChars.sawDeprecatedOctal()) { error(JSMSG_DEPRECATED_OCTAL); return false; } @@ -3751,7 +3751,7 @@ GeneralParser::statementList(YieldHandling yieldHandling) { bool canHaveDirectives = pc_->atBodyLevel(); if (canHaveDirectives) { - anyChars.clearSawOctalEscape(); + anyChars.clearSawDeprecatedOctal(); } bool canHaveHashbangComment = pc_->atTopLevel(); diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index bf818096f59e..fc1d434c372f 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -2925,6 +2925,7 @@ MOZ_MUST_USE bool TokenStreamSpecific::getTokenInternal( if (!strictModeError(JSMSG_DEPRECATED_OCTAL)) { return badToken(); } + anyCharsAccess().flags.sawDeprecatedOctal = true; radix = 8; // one past the '0' @@ -3603,7 +3604,7 @@ bool TokenStreamSpecific::getStringOrTemplateToken( if (!strictModeError(JSMSG_DEPRECATED_OCTAL)) { return false; } - anyChars.flags.sawOctalEscape = true; + anyChars.flags.sawDeprecatedOctal = true; } if (IsAsciiOctal(unit)) { diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 6033bd7af5eb..2f95fceb1949 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -234,13 +234,20 @@ extern const char* ReservedWordToCharZ(PropertyName* str); extern const char* ReservedWordToCharZ(TokenKind tt); struct TokenStreamFlags { - bool isEOF : 1; // Hit end of file. - bool isDirtyLine : 1; // Non-whitespace since start of line. - bool sawOctalEscape : 1; // Saw an octal character escape. - bool hadError : 1; // Hit a syntax error, at start or during a - // token. + // Hit end of file. + bool isEOF : 1; + // Non-whitespace since start of line. + bool isDirtyLine : 1; + // Saw an octal character escape or a 0-prefixed octal literal. + bool sawDeprecatedOctal : 1; + // Hit a syntax error, at start or during a token. + bool hadError : 1; - TokenStreamFlags() : isEOF(), isDirtyLine(), sawOctalEscape(), hadError() {} + TokenStreamFlags() + : isEOF(false), + isDirtyLine(false), + sawDeprecatedOctal(false), + hadError(false) {} }; template @@ -753,9 +760,9 @@ class TokenStreamAnyChars : public TokenStreamShared { // Flag methods. bool isEOF() const { return flags.isEOF; } - bool sawOctalEscape() const { return flags.sawOctalEscape; } + bool sawDeprecatedOctal() const { return flags.sawDeprecatedOctal; } bool hadError() const { return flags.hadError; } - void clearSawOctalEscape() { flags.sawOctalEscape = false; } + void clearSawDeprecatedOctal() { flags.sawDeprecatedOctal = false; } bool hasInvalidTemplateEscape() const { return invalidTemplateEscapeType != InvalidEscapeType::None; diff --git a/js/src/jit-test/tests/parser/strict-with-asi-and-deprecated-octal.js b/js/src/jit-test/tests/parser/strict-with-asi-and-deprecated-octal.js new file mode 100644 index 000000000000..cb09ac584959 --- /dev/null +++ b/js/src/jit-test/tests/parser/strict-with-asi-and-deprecated-octal.js @@ -0,0 +1,4 @@ +// |jit-test| error: SyntaxError +"use strict" +010 +