Bug 1434429 - Change TokenStreamCharsBase::appendMultiUnitCodepointToTokenbuf to TokenStreamCharsBase::appendCodePointToTokenbuf so that the idea doesn't require knowledge of multi-unitness. r=arai

--HG--
extra : rebase_source : 40c6f1c1f6be86c9796cbe615e7ad1a332d9549c
This commit is contained in:
Jeff Walden 2018-01-29 12:35:11 -08:00
parent d2ef6ad9ca
commit a9b51a54a3
2 changed files with 18 additions and 26 deletions

View File

@ -1293,12 +1293,22 @@ IsTokenSane(Token* tp)
template<> template<>
MOZ_MUST_USE bool MOZ_MUST_USE bool
TokenStreamCharsBase<char16_t>::appendMultiUnitCodepointToTokenbuf(uint32_t codepoint) TokenStreamCharsBase<char16_t>::appendCodePointToTokenbuf(uint32_t codepoint)
{ {
char16_t lead, trail; char16_t units[2];
unicode::UTF16Encode(codepoint, &lead, &trail); unsigned numUnits;
unicode::UTF16Encode(codepoint, units, &numUnits);
return tokenbuf.append(lead) && tokenbuf.append(trail); MOZ_ASSERT(numUnits == 1 || numUnits == 2,
"UTF-16 code points are only encoded in one or two units");
if (!tokenbuf.append(units[0]))
return false;
if (numUnits == 1)
return true;
return tokenbuf.append(units[1]);
} }
template<class AnyCharsAccess> template<class AnyCharsAccess>
@ -1341,31 +1351,13 @@ TokenStreamSpecific<CharT, AnyCharsAccess>::putIdentInTokenbuf(const CharT* iden
if (codePoint) { if (codePoint) {
if (!unicode::IsIdentifierPart(codePoint)) if (!unicode::IsIdentifierPart(codePoint))
break; break;
} else if (!unicode::IsIdentifierPart(char16_t(c))) {
if (!appendMultiUnitCodepointToTokenbuf(codePoint))
return false;
continue;
}
if (!unicode::IsIdentifierPart(char16_t(c))) {
uint32_t qc; uint32_t qc;
if (c != '\\' || !matchUnicodeEscapeIdent(&qc)) if (c != '\\' || !matchUnicodeEscapeIdent(&qc))
break; break;
if (MOZ_UNLIKELY(unicode::IsSupplementary(qc))) {
char16_t lead, trail;
unicode::UTF16Encode(qc, &lead, &trail);
if (!tokenbuf.append(lead) || !tokenbuf.append(trail))
return false;
continue;
}
c = qc;
} }
if (!tokenbuf.append(c)) if (!appendCodePointToTokenbuf(codePoint))
return false; return false;
} }

View File

@ -948,7 +948,7 @@ class TokenStreamCharsBase
const CharT* ptr; const CharT* ptr;
}; };
MOZ_MUST_USE bool appendMultiUnitCodepointToTokenbuf(uint32_t codepoint); MOZ_MUST_USE bool appendCodePointToTokenbuf(uint32_t codepoint);
class MOZ_STACK_CLASS Position class MOZ_STACK_CLASS Position
{ {
@ -1158,7 +1158,7 @@ class MOZ_STACK_CLASS TokenStreamSpecific
using typename CharsSharedBase::TokenBuf; using typename CharsSharedBase::TokenBuf;
private: private:
using CharsSharedBase::appendMultiUnitCodepointToTokenbuf; using CharsSharedBase::appendCodePointToTokenbuf;
using CharsSharedBase::atomizeChars; using CharsSharedBase::atomizeChars;
using CharsSharedBase::copyTokenbufTo; using CharsSharedBase::copyTokenbufTo;
using GeneralCharsBase::getCharIgnoreEOL; using GeneralCharsBase::getCharIgnoreEOL;