Bug 1642268 - Check deprecated octal literal when entering strict mode after ASI. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D77672
This commit is contained in:
Tooru Fujisawa 2020-06-12 07:41:37 +00:00
Родитель 22ac309175
Коммит 48d16d133b
4 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -3718,10 +3718,10 @@ bool GeneralParser<ParseHandler, Unit>::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<ParseHandler, Unit>::statementList(YieldHandling yieldHandling) {
bool canHaveDirectives = pc_->atBodyLevel();
if (canHaveDirectives) {
anyChars.clearSawOctalEscape();
anyChars.clearSawDeprecatedOctal();
}
bool canHaveHashbangComment = pc_->atTopLevel();

Просмотреть файл

@ -2925,6 +2925,7 @@ MOZ_MUST_USE bool TokenStreamSpecific<Unit, AnyCharsAccess>::getTokenInternal(
if (!strictModeError(JSMSG_DEPRECATED_OCTAL)) {
return badToken();
}
anyCharsAccess().flags.sawDeprecatedOctal = true;
radix = 8;
// one past the '0'
@ -3603,7 +3604,7 @@ bool TokenStreamSpecific<Unit, AnyCharsAccess>::getStringOrTemplateToken(
if (!strictModeError(JSMSG_DEPRECATED_OCTAL)) {
return false;
}
anyChars.flags.sawOctalEscape = true;
anyChars.flags.sawDeprecatedOctal = true;
}
if (IsAsciiOctal(unit)) {

Просмотреть файл

@ -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 <typename Unit>
@ -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;

Просмотреть файл

@ -0,0 +1,4 @@
// |jit-test| error: SyntaxError
"use strict"
010