summaryrefslogtreecommitdiffstats
path: root/js/src/frontend
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2019-06-08 15:48:25 -0400
committerGaming4JC <g4jc@hyperbola.info>2019-07-18 22:38:17 -0400
commitb41de8683d8d28d08a6e2b79511610a268342a0e (patch)
tree82fa4225aaad95443ba9d82599d4d28582bfcdb6 /js/src/frontend
parent068916b59a847bede7c6c788e803442c1833fe67 (diff)
downloadUXP-b41de8683d8d28d08a6e2b79511610a268342a0e.tar
UXP-b41de8683d8d28d08a6e2b79511610a268342a0e.tar.gz
UXP-b41de8683d8d28d08a6e2b79511610a268342a0e.tar.lz
UXP-b41de8683d8d28d08a6e2b79511610a268342a0e.tar.xz
UXP-b41de8683d8d28d08a6e2b79511610a268342a0e.zip
1326454 - Rename TokenStream::getBracedUnicode to TokenStream::matchBracedUnicode and make its signature fallible.
Diffstat (limited to 'js/src/frontend')
-rw-r--r--js/src/frontend/TokenStream.cpp57
-rw-r--r--js/src/frontend/TokenStream.h5
2 files changed, 46 insertions, 16 deletions
diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp
index e8d622d38..abb7228eb 100644
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -821,6 +821,19 @@ TokenStream::error(unsigned errorNumber, ...)
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.
// 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
@@ -1869,32 +1882,47 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
bool
-TokenStream::getBracedUnicode(uint32_t* cp)
+TokenStream::matchBracedUnicode(bool* matched, uint32_t* cp)
{
+ if (peekChar() != '{') {
+ *matched = false;
+ return true;
+ }
+
consumeKnownChar('{');
+ uint32_t start = userbuf.offset();
+
bool first = true;
- int32_t c;
uint32_t code = 0;
- while (true) {
- c = getCharIgnoreEOL();
- if (c == EOF)
+ do {
+ int32_t c = getCharIgnoreEOL();
+ if (c == EOF) {
+ error(JSMSG_MALFORMED_ESCAPE, "Unicode");
return false;
+ }
if (c == '}') {
- if (first)
+ if (first) {
+ error(JSMSG_MALFORMED_ESCAPE, "Unicode");
return false;
+ }
break;
}
- if (!JS7_ISHEX(c))
+ if (!JS7_ISHEX(c)) {
+ error(JSMSG_MALFORMED_ESCAPE, "Unicode");
return false;
+ }
code = (code << 4) | JS7_UNHEX(c);
- if (code > unicode::NonBMPMax)
+ if (code > unicode::NonBMPMax) {
+ errorAt(start, JSMSG_UNICODE_OVERFLOW, "escape sequence");
return false;
+ }
first = false;
- }
+ } while (true);
+ *matched = true;
*cp = code;
return true;
}
@@ -1936,12 +1964,11 @@ TokenStream::getStringOrTemplateToken(int untilChar, Token** tp)
// Unicode character specification.
case 'u': {
- if (peekChar() == '{') {
- uint32_t code;
- if (!getBracedUnicode(&code)) {
- error(JSMSG_MALFORMED_ESCAPE, "Unicode");
- return false;
- }
+ bool matched;
+ uint32_t code;
+ if (!matchBracedUnicode(&matched, &code))
+ return false;
+ if (matched) {
MOZ_ASSERT(code <= unicode::NonBMPMax);
if (code < unicode::NonBMPMin) {
diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h
index 18e9cb3ca..19385b499 100644
--- a/js/src/frontend/TokenStream.h
+++ b/js/src/frontend/TokenStream.h
@@ -368,6 +368,9 @@ class MOZ_STACK_CLASS TokenStream
// Report the given error at the current offset.
void error(unsigned errorNumber, ...);
+ // Report the given error at the given offset.
+ void errorAt(uint32_t offset, unsigned errorNumber, ...);
+
// Warn at the current offset.
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 getBracedUnicode(uint32_t* code);
+ MOZ_MUST_USE bool matchBracedUnicode(bool* matched, uint32_t* code);
MOZ_MUST_USE bool getStringOrTemplateToken(int untilChar, Token** tp);
int32_t getChar();