1326454 - Introduce TokenStream::error that reports an error at the current offset.

This commit is contained in:
Gaming4JC 2019-06-08 15:37:06 -04:00 • committed by Roy Tam
commit c94ed16b4f
2 changed files with 30 additions and 10 deletions

View file

@ -554,8 +554,10 @@ TokenStream::advance(size_t position)
MOZ_MAKE_MEM_UNDEFINED(&cur->type, sizeof(cur->type)); MOZ_MAKE_MEM_UNDEFINED(&cur->type, sizeof(cur->type));
lookahead = 0; lookahead = 0;
if (flags.hitOOM) if (flags.hitOOM) {
return reportError(JSMSG_OUT_OF_MEMORY); error(JSMSG_OUT_OF_MEMORY);
return false;
}
return true; return true;
} }
@ -806,6 +808,19 @@ TokenStream::reportAsmJSError(uint32_t offset, unsigned errorNumber, ...)
va_end(args); va_end(args);
} }
void
TokenStream::error(unsigned errorNumber, ...)
{
va_list args;
va_start(args, errorNumber);
#ifdef DEBUG
bool result =
#endif
reportCompileErrorNumberVA(currentToken().pos.begin, JSREPORT_ERROR, errorNumber, args);
MOZ_ASSERT(!result, "reporting an error returned true?");
va_end(args);
}
// We have encountered a '\': check for a Unicode escape sequence after it. // We have encountered a '\': check for a Unicode escape sequence after it.
// Return the length of the escape sequence and the character code point (by // Return the length of the escape sequence and the character code point (by
// value) if we found a Unicode escape sequence. Otherwise, return 0. In both // value) if we found a Unicode escape sequence. Otherwise, return 0. In both
@ -1119,8 +1134,10 @@ TokenStream::checkForKeyword(const KeywordInfo* kw, TokenKind* ttp)
return true; return true;
} }
if (kw->tokentype == TOK_RESERVED) if (kw->tokentype == TOK_RESERVED) {
return reportError(JSMSG_RESERVED_ID, kw->chars); error(JSMSG_RESERVED_ID, kw->chars);
return false;
}
if (kw->tokentype == TOK_STRICT_RESERVED) if (kw->tokentype == TOK_STRICT_RESERVED)
return reportStrictModeError(JSMSG_RESERVED_ID, kw->chars); return reportStrictModeError(JSMSG_RESERVED_ID, kw->chars);
@ -1897,7 +1914,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
while ((c = getCharIgnoreEOL()) != untilChar) { while ((c = getCharIgnoreEOL()) != untilChar) {
if (c == EOF) { if (c == EOF) {
ungetCharIgnoreEOL(c); ungetCharIgnoreEOL(c);
reportError(JSMSG_UNTERMINATED_STRING); error(JSMSG_UNTERMINATED_STRING);
return false; return false;
} }
@ -1920,7 +1937,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
if (peekChar() == '{') { if (peekChar() == '{') {
uint32_t code; uint32_t code;
if (!getBracedUnicode(&code)) { if (!getBracedUnicode(&code)) {
reportError(JSMSG_MALFORMED_ESCAPE, "Unicode"); error(JSMSG_MALFORMED_ESCAPE, "Unicode");
return false; return false;
} }
@ -1945,7 +1962,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
c = (c << 4) + JS7_UNHEX(cp[3]); c = (c << 4) + JS7_UNHEX(cp[3]);
skipChars(4); skipChars(4);
} else { } else {
reportError(JSMSG_MALFORMED_ESCAPE, "Unicode"); error(JSMSG_MALFORMED_ESCAPE, "Unicode");
return false; return false;
} }
break; break;
@ -1958,7 +1975,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
c = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]); c = (JS7_UNHEX(cp[0]) << 4) + JS7_UNHEX(cp[1]);
skipChars(2); skipChars(2);
} else { } else {
reportError(JSMSG_MALFORMED_ESCAPE, "hexadecimal"); error(JSMSG_MALFORMED_ESCAPE, "hexadecimal");
return false; return false;
} }
break; break;
@ -1974,7 +1991,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
// Strict mode code allows only \0, then a non-digit. // Strict mode code allows only \0, then a non-digit.
if (val != 0 || JS7_ISDEC(c)) { if (val != 0 || JS7_ISDEC(c)) {
if (parsingTemplate) { if (parsingTemplate) {
reportError(JSMSG_DEPRECATED_OCTAL); error(JSMSG_DEPRECATED_OCTAL);
return false; return false;
} }
if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL)) if (!reportStrictModeError(JSMSG_DEPRECATED_OCTAL))
@ -2003,7 +2020,7 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
} else if (TokenBuf::isRawEOLChar(c)) { } else if (TokenBuf::isRawEOLChar(c)) {
if (!parsingTemplate) { if (!parsingTemplate) {
ungetCharIgnoreEOL(c); ungetCharIgnoreEOL(c);
reportError(JSMSG_UNTERMINATED_STRING); error(JSMSG_UNTERMINATED_STRING);
return false; return false;
} }
if (c == '\r') { if (c == '\r') {

View file

@ -366,6 +366,9 @@ class MOZ_STACK_CLASS TokenStream
bool reportErrorNoOffset(unsigned errorNumber, ...); bool reportErrorNoOffset(unsigned errorNumber, ...);
bool reportWarning(unsigned errorNumber, ...); bool reportWarning(unsigned errorNumber, ...);
// Report the given error at the current offset.
void error(unsigned errorNumber, ...);
static const uint32_t NoOffset = UINT32_MAX; static const uint32_t NoOffset = UINT32_MAX;
// General-purpose error reporters. You should avoid calling these // General-purpose error reporters. You should avoid calling these