From 2f902e38d089f23c8d52c0996de898095145c1cd Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Thu, 28 Jun 2018 20:14:27 -0700 Subject: [PATCH] Bug 1472066 - Specialize TokenStreamCharsBase::fillCharBufferWithTemplateStringContents for char16_t now that its alternative UTF-8 implementation will have to function a bit differently to write data into a char16_t charBuffer. r=arai --HG-- extra : rebase_source : 8c6e13e16777abc910aaf46d4654ae03e88f32fa --- js/src/frontend/TokenStream.h | 50 ++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index d43c9ef2b9bf..a0cdbd5aa7da 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -1193,28 +1193,8 @@ class TokenStreamCharsBase MOZ_ASSERT(next == unit, "must be consuming the correct unit"); } - MOZ_MUST_USE bool - fillCharBufferWithTemplateStringContents(const CharT* cur, const CharT* end) { - while (cur < end) { - // U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are - // interpreted literally inside template literal contents; only - // literal CRLF sequences are normalized to '\n'. See - // . - CharT ch = *cur; - if (ch == '\r') { - ch = '\n'; - if ((cur + 1 < end) && (*(cur + 1) == '\n')) - cur++; - } - - if (!charBuffer.append(ch)) - return false; - - cur++; - } - - return true; - } + MOZ_MUST_USE inline bool + fillCharBufferWithTemplateStringContents(const CharT* cur, const CharT* end); protected: /** Code units in the source code being tokenized. */ @@ -1229,6 +1209,32 @@ TokenStreamCharsBase::atomizeSourceChars(JSContext* cx, const char16_t return AtomizeChars(cx, chars, length); } +template<> +MOZ_MUST_USE inline bool +TokenStreamCharsBase::fillCharBufferWithTemplateStringContents(const char16_t* cur, + const char16_t* end) +{ + MOZ_ASSERT(charBuffer.length() == 0); + + while (cur < end) { + // U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are + // interpreted literally inside template literal contents; only + // literal CRLF sequences are normalized to '\n'. See + // . + char16_t ch = *cur++; + if (ch == '\r') { + ch = '\n'; + if (cur < end && *cur == '\n') + cur++; + } + + if (!charBuffer.append(ch)) + return false; + } + + return true; +} + /** A small class encapsulating computation of the start-offset of a Token. */ class TokenStart {