Issue #1240 - Part 4 - Implement parser support for BigInt literals. https://bugzilla.mozilla.org/show_bug.cgi?id=1505849 Partially based on https://bugzilla.mozilla.org/show_bug.cgi?id=1456568 Un-result-ified the BigInt XDR code, so we can enable it. https://bugzilla.mozilla.org/show_bug.cgi?id=1419094 Uninitialised memory read with BigInt right-shift https://bugzilla.mozilla.org/show_bug.cgi?id=1679003

This commit is contained in:
Brian Smith 2023-07-18 20:23:02 -05:00 committed by roytam1
commit dc23241afb
27 changed files with 394 additions and 80 deletions

View file

@ -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,16 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
}
if (isBigInt) {
size_t length = userbuf.addressOfNextRawChar() - numStart - 1;
tokenbuf.clear();
if(!tokenbuf.reserve(length))
goto error;
tokenbuf.infallibleAppend(numStart, length);
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.
@ -1777,6 +1792,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 +1815,16 @@ TokenStream::getTokenInternal(TokenKind* ttp, Modifier modifier)
}
}
if (isBigInt) {
size_t length = userbuf.addressOfNextRawChar() - numStart - 1;
tokenbuf.clear();
if(!tokenbuf.reserve(length))
goto error;
tokenbuf.infallibleAppend(numStart, length);
tp->type = TOK_BIGINT;
goto out;
}
double dval;
const char16_t* dummy;
if (!GetPrefixInteger(cx, numStart, userbuf.addressOfNextRawChar(), radix,