summaryrefslogtreecommitdiff
path: root/js/src/frontend/TokenStream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/frontend/TokenStream.cpp')
-rw-r--r--js/src/frontend/TokenStream.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp
index a201e42a52..b11c7df584 100644
--- a/js/src/frontend/TokenStream.cpp
+++ b/js/src/frontend/TokenStream.cpp
@@ -1382,6 +1382,7 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
const char16_t* identStart;
NameVisibility identVisibility;
bool hadUnicodeEscape;
+ bool isBigInt = false;
// Check if in the middle of a template string. Have to get this out of
// the way first.
@@ -1619,6 +1620,10 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
} while (true);
}
+ if (c == 'n') {
+ isBigInt = true;
+ c = getCharIgnoreEOL();
+ }
ungetCharIgnoreEOL(c);
if (c != EOF) {
@@ -1638,6 +1643,19 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
}
+ if (isBigInt) {
+ size_t length = userbuf.addressOfNextRawChar() - numStart - 1;
+ tokenbuf.clear();
+ if(!tokenbuf.reserve(length > 0 ? length : 1))
+ goto error;
+ if(length > 0)
+ tokenbuf.infallibleAppend(numStart, length);
+ else
+ tokenbuf.infallibleAppend("0", 1);
+ tp->type = TOK_BIGINT;
+ goto out;
+ }
+
// Unlike identifiers and strings, numbers cannot contain escaped
// chars, so we don't need to use tokenbuf. Instead we can just
// convert the char16_t characters in userbuf to the numeric value.
@@ -1677,7 +1695,7 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
//
if (c1kind == BasePrefix) {
tp = newToken(-1);
- int radix;
+ int radix = 10;
c = getCharIgnoreEOL();
if (c == 'x' || c == 'X') {
radix = 16;
@@ -1777,6 +1795,10 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
hasExp = false;
goto decimal_rest;
}
+ if (c == 'n') {
+ isBigInt = true;
+ c = getCharIgnoreEOL();
+ }
ungetCharIgnoreEOL(c);
if (c != EOF) {
@@ -1796,6 +1818,28 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
}
+ if (isBigInt) {
+ size_t length = userbuf.addressOfNextRawChar() - numStart - 1;
+ tokenbuf.clear();
+ if(!tokenbuf.reserve(radix == 10 ? length : (length + 2)))
+ goto error;
+ switch(radix)
+ {
+ case 2:
+ tokenbuf.infallibleAppend("0b", 2);
+ break;
+ case 8:
+ tokenbuf.infallibleAppend("0o", 2);
+ break;
+ case 16:
+ tokenbuf.infallibleAppend("0x", 2);
+ break;
+ }
+ tokenbuf.infallibleAppend(numStart, length);
+ tp->type = TOK_BIGINT;
+ goto out;
+ }
+
double dval;
const char16_t* dummy;
if (!GetPrefixInteger(cx, numStart, userbuf.addressOfNextRawChar(), radix,