mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-19 13:47:31 +09:00
1326454 - Rename TokenStream::getBracedUnicode to TokenStream::matchBracedUnicode and make its signature fallible.
This commit is contained in:
parent
cd2bccf4c0
commit
3d4f7e67fc
5 changed files with 51 additions and 21 deletions
|
|
@ -821,6 +821,19 @@ TokenStream::error(unsigned errorNumber, ...)
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TokenStream::errorAt(uint32_t offset, unsigned errorNumber, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
va_start(args, errorNumber);
|
||||||
|
#ifdef DEBUG
|
||||||
|
bool result =
|
||||||
|
#endif
|
||||||
|
reportCompileErrorNumberVA(offset, 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
|
||||||
|
|
@ -1869,32 +1882,47 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
TokenStream::getBracedUnicode(uint32_t* cp)
|
TokenStream::matchBracedUnicode(bool* matched, uint32_t* cp)
|
||||||
{
|
{
|
||||||
|
if (peekChar() != '{') {
|
||||||
|
*matched = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
consumeKnownChar('{');
|
consumeKnownChar('{');
|
||||||
|
|
||||||
|
uint32_t start = userbuf.offset();
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
int32_t c;
|
|
||||||
uint32_t code = 0;
|
uint32_t code = 0;
|
||||||
while (true) {
|
do {
|
||||||
c = getCharIgnoreEOL();
|
int32_t c = getCharIgnoreEOL();
|
||||||
if (c == EOF)
|
if (c == EOF) {
|
||||||
|
error(JSMSG_MALFORMED_ESCAPE, "Unicode");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
if (c == '}') {
|
if (c == '}') {
|
||||||
if (first)
|
if (first) {
|
||||||
|
error(JSMSG_MALFORMED_ESCAPE, "Unicode");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JS7_ISHEX(c))
|
if (!JS7_ISHEX(c)) {
|
||||||
|
error(JSMSG_MALFORMED_ESCAPE, "Unicode");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
code = (code << 4) | JS7_UNHEX(c);
|
code = (code << 4) | JS7_UNHEX(c);
|
||||||
if (code > unicode::NonBMPMax)
|
if (code > unicode::NonBMPMax) {
|
||||||
|
errorAt(start, JSMSG_UNICODE_OVERFLOW, "escape sequence");
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
first = false;
|
first = false;
|
||||||
}
|
} while (true);
|
||||||
|
|
||||||
|
*matched = true;
|
||||||
*cp = code;
|
*cp = code;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -1936,12 +1964,11 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
|
||||||
|
|
||||||
// Unicode character specification.
|
// Unicode character specification.
|
||||||
case 'u': {
|
case 'u': {
|
||||||
if (peekChar() == '{') {
|
bool matched;
|
||||||
uint32_t code;
|
uint32_t code;
|
||||||
if (!getBracedUnicode(&code)) {
|
if (!matchBracedUnicode(&matched, &code))
|
||||||
error(JSMSG_MALFORMED_ESCAPE, "Unicode");
|
return false;
|
||||||
return false;
|
if (matched) {
|
||||||
}
|
|
||||||
|
|
||||||
MOZ_ASSERT(code <= unicode::NonBMPMax);
|
MOZ_ASSERT(code <= unicode::NonBMPMax);
|
||||||
if (code < unicode::NonBMPMin) {
|
if (code < unicode::NonBMPMin) {
|
||||||
|
|
|
||||||
|
|
@ -368,6 +368,9 @@ class MOZ_STACK_CLASS TokenStream
|
||||||
// Report the given error at the current offset.
|
// Report the given error at the current offset.
|
||||||
void error(unsigned errorNumber, ...);
|
void error(unsigned errorNumber, ...);
|
||||||
|
|
||||||
|
// Report the given error at the given offset.
|
||||||
|
void errorAt(uint32_t offset, unsigned errorNumber, ...);
|
||||||
|
|
||||||
// Warn at the current offset.
|
// Warn at the current offset.
|
||||||
MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
|
MOZ_MUST_USE bool warning(unsigned errorNumber, ...);
|
||||||
|
|
||||||
|
|
@ -952,7 +955,7 @@ class MOZ_STACK_CLASS TokenStream
|
||||||
|
|
||||||
MOZ_MUST_USE bool getTokenInternal(TokenKind* ttp, Modifier modifier);
|
MOZ_MUST_USE bool getTokenInternal(TokenKind* ttp, Modifier modifier);
|
||||||
|
|
||||||
MOZ_MUST_USE bool getBracedUnicode(uint32_t* code);
|
MOZ_MUST_USE bool matchBracedUnicode(bool* matched, uint32_t* code);
|
||||||
MOZ_MUST_USE bool getStringOrTemplateToken(int untilChar, Token** tp);
|
MOZ_MUST_USE bool getStringOrTemplateToken(int untilChar, Token** tp);
|
||||||
|
|
||||||
int32_t getChar();
|
int32_t getChar();
|
||||||
|
|
|
||||||
|
|
@ -243,10 +243,10 @@ RegExpParser<CharT>::RegExpParser(frontend::TokenStream& ts, LifoAlloc* alloc,
|
||||||
|
|
||||||
template <typename CharT>
|
template <typename CharT>
|
||||||
RegExpTree*
|
RegExpTree*
|
||||||
RegExpParser<CharT>::ReportError(unsigned errorNumber)
|
RegExpParser<CharT>::ReportError(unsigned errorNumber, const char* param /* = nullptr */)
|
||||||
{
|
{
|
||||||
gc::AutoSuppressGC suppressGC(ts.context());
|
gc::AutoSuppressGC suppressGC(ts.context());
|
||||||
ts.reportError(errorNumber);
|
ts.reportError(errorNumber, param);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -350,7 +350,7 @@ RegExpParser<CharT>::ParseBracedHexEscape(widechar* value)
|
||||||
}
|
}
|
||||||
code = (code << 4) | d;
|
code = (code << 4) | d;
|
||||||
if (code > unicode::NonBMPMax) {
|
if (code > unicode::NonBMPMax) {
|
||||||
ReportError(JSMSG_UNICODE_OVERFLOW);
|
ReportError(JSMSG_UNICODE_OVERFLOW, "regular expression");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Advance();
|
Advance();
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ class RegExpParser
|
||||||
bool ParseBackReferenceIndex(int* index_out);
|
bool ParseBackReferenceIndex(int* index_out);
|
||||||
|
|
||||||
bool ParseClassAtom(char16_t* char_class, widechar *value);
|
bool ParseClassAtom(char16_t* char_class, widechar *value);
|
||||||
RegExpTree* ReportError(unsigned errorNumber);
|
RegExpTree* ReportError(unsigned errorNumber, const char* param = nullptr);
|
||||||
void Advance();
|
void Advance();
|
||||||
void Advance(int dist) {
|
void Advance(int dist) {
|
||||||
next_pos_ += dist - 1;
|
next_pos_ += dist - 1;
|
||||||
|
|
|
||||||
|
|
@ -502,7 +502,7 @@ MSG_DEF(JSMSG_RANGE_WITH_CLASS_ESCAPE, 0, JSEXN_SYNTAXERR, "character class esca
|
||||||
MSG_DEF(JSMSG_RAW_BRACE_IN_REGEP, 0, JSEXN_SYNTAXERR, "raw brace is not allowed in regular expression with unicode flag")
|
MSG_DEF(JSMSG_RAW_BRACE_IN_REGEP, 0, JSEXN_SYNTAXERR, "raw brace is not allowed in regular expression with unicode flag")
|
||||||
MSG_DEF(JSMSG_RAW_BRACKET_IN_REGEP, 0, JSEXN_SYNTAXERR, "raw bracket is not allowed in regular expression with unicode flag")
|
MSG_DEF(JSMSG_RAW_BRACKET_IN_REGEP, 0, JSEXN_SYNTAXERR, "raw bracket is not allowed in regular expression with unicode flag")
|
||||||
MSG_DEF(JSMSG_TOO_MANY_PARENS, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression")
|
MSG_DEF(JSMSG_TOO_MANY_PARENS, 0, JSEXN_INTERNALERR, "too many parentheses in regular expression")
|
||||||
MSG_DEF(JSMSG_UNICODE_OVERFLOW, 0, JSEXN_SYNTAXERR, "unicode codepoint should not be greater than 0x10FFFF in regular expression")
|
MSG_DEF(JSMSG_UNICODE_OVERFLOW, 1, JSEXN_SYNTAXERR, "Unicode codepoint must not be greater than 0x10FFFF in {0}")
|
||||||
MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression")
|
MSG_DEF(JSMSG_UNMATCHED_RIGHT_PAREN, 0, JSEXN_SYNTAXERR, "unmatched ) in regular expression")
|
||||||
MSG_DEF(JSMSG_UNTERM_CLASS, 0, JSEXN_SYNTAXERR, "unterminated character class")
|
MSG_DEF(JSMSG_UNTERM_CLASS, 0, JSEXN_SYNTAXERR, "unterminated character class")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue