Rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32)...
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 03:15:02 +0000 (03:15 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Aug 2019 03:15:02 +0000 (03:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200675

Reviewed by Darin Adler.

Source/JavaScriptCore:

* yarr/YarrParser.h:
(JSC::Yarr::Parser::tryConsumeGroupName):
(JSC::Yarr::Parser::tryConsumeUnicodePropertyExpression):
Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).

Source/WebCore:

* bindings/js/JSDOMConvertStrings.cpp:
(WebCore::stringToUSVString):
* css/CSSMarkup.cpp:
(WebCore::serializeCharacter):
(WebCore::serializeIdentifier):
(WebCore::serializeString):
* css/parser/CSSTokenizer.cpp:
(WebCore::CSSTokenizer::consumeStringTokenUntil):
(WebCore::CSSTokenizer::consumeUrlToken):
(WebCore::CSSTokenizer::consumeName):
* html/parser/HTMLEntityParser.cpp:
(WebCore::HTMLEntityParser::consumeNamedEntity):
* platform/mock/mediasource/MockBox.cpp:
(WebCore::MockBox::peekType):
(WebCore::MockTrackBox::MockTrackBox):
* rendering/RenderText.cpp:
(WebCore::capitalize):
* xml/parser/CharacterReferenceParserInlines.h:
(WebCore::consumeCharacterReference):
Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).

Source/WTF:

When we switch StringBuilder::append(...) to be based on the StringConcatenate/makeString flexibleAppend
implementation, if we don't change anything, the behavior of StringBuilder::append(UChar32) will go from
appending a character to appending a stringified number.

To work around this, we can rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32)
and update all the call sites.

* wtf/text/StringBuilder.h:
(WTF::StringBuilder::appendCharacter):
Renamed StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::decodeFromFilename):
Update for new name.

Tools:

* TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
(TestWebKitAPI::TEST):
Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248659 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/yarr/YarrParser.h
Source/WTF/ChangeLog
Source/WTF/wtf/FileSystem.cpp
Source/WTF/wtf/text/StringBuilder.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMConvertStrings.cpp
Source/WebCore/css/CSSMarkup.cpp
Source/WebCore/css/parser/CSSTokenizer.cpp
Source/WebCore/html/parser/HTMLEntityParser.cpp
Source/WebCore/platform/mock/mediasource/MockBox.cpp
Source/WebCore/rendering/RenderText.cpp
Source/WebCore/xml/parser/CharacterReferenceParserInlines.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/StringBuilder.cpp

index 0c5d372..e46cda2 100644 (file)
@@ -1,3 +1,15 @@
+2019-08-13  Sam Weinig  <weinig@apple.com>
+
+        Rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32) to avoid accidental change in behavior when replacing append with flexibleAppend
+        https://bugs.webkit.org/show_bug.cgi?id=200675
+
+        Reviewed by Darin Adler.
+
+        * yarr/YarrParser.h:
+        (JSC::Yarr::Parser::tryConsumeGroupName):
+        (JSC::Yarr::Parser::tryConsumeUnicodePropertyExpression):
+        Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).
+
 2019-08-13  Mark Lam  <mark.lam@apple.com>
 
         Add phase, block, and node numbers to left margin of DFG graph dumps.
index 55106bb..918b307 100644 (file)
@@ -1033,7 +1033,7 @@ private:
 
         if (isIdentifierStart(ch)) {
             StringBuilder identifierBuilder;
-            identifierBuilder.append(ch);
+            identifierBuilder.appendCharacter(ch);
 
             while (!atEndOfPattern()) {
                 ch = tryConsumeIdentifierCharacter();
@@ -1043,7 +1043,7 @@ private:
                 if (!isIdentifierPart(ch))
                     break;
 
-                identifierBuilder.append(ch);
+                identifierBuilder.appendCharacter(ch);
             }
         }
 
@@ -1064,7 +1064,7 @@ private:
         bool foundEquals = false;
         unsigned errors = 0;
 
-        expressionBuilder.append(consume());
+        expressionBuilder.appendCharacter(consume());
 
         while (!atEndOfPattern()) {
             int ch = peek();
@@ -1099,7 +1099,7 @@ private:
             } else if (!isUnicodePropertyValueExpressionChar(ch))
                 errors++;
             else
-                expressionBuilder.append(ch);
+                expressionBuilder.appendCharacter(ch);
         }
 
         m_errorCode = ErrorCode::InvalidUnicodePropertyExpression;
index 421e7ce..1b8ddec 100644 (file)
@@ -1,3 +1,25 @@
+2019-08-13  Sam Weinig  <weinig@apple.com>
+
+        Rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32) to avoid accidental change in behavior when replacing append with flexibleAppend
+        https://bugs.webkit.org/show_bug.cgi?id=200675
+
+        Reviewed by Darin Adler.
+
+        When we switch StringBuilder::append(...) to be based on the StringConcatenate/makeString flexibleAppend 
+        implementation, if we don't change anything, the behavior of StringBuilder::append(UChar32) will go from 
+        appending a character to appending a stringified number.
+
+        To work around this, we can rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32) 
+        and update all the call sites.
+
+        * wtf/text/StringBuilder.h:
+        (WTF::StringBuilder::appendCharacter):
+        Renamed StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).
+
+        * wtf/FileSystem.cpp:
+        (WTF::FileSystemImpl::decodeFromFilename):
+        Update for new name.
+
 2019-08-13  Yusuke Suzuki  <ysuzuki@apple.com>
 
         Unreviewed, build fix for Windows
index 8fdf640..603cf12 100644 (file)
@@ -182,7 +182,8 @@ String decodeFromFilename(const String& inputString)
         if (!isASCIIHexDigit(inputString[i + 5]))
             return { };
 
-        result.append(toASCIIHexValue(inputString[i + 2], inputString[i + 3]) << 8 | toASCIIHexValue(inputString[i + 4], inputString[i + 5]));
+        UChar hexDigit = toASCIIHexValue(inputString[i + 2], inputString[i + 3]) << 8 | toASCIIHexValue(inputString[i + 4], inputString[i + 5]);
+        result.append(hexDigit);
         i += 5;
     }
 
index d620440..64b50a1 100644 (file)
@@ -162,6 +162,7 @@ public:
             appendCharacters(characters, strlen(characters));
     }
 
+    void appendCharacter(UChar) = delete;
     void append(UChar c)
     {
         if (hasOverflowed())
@@ -183,6 +184,7 @@ public:
         appendCharacters(&c, 1);
     }
 
+    void appendCharacter(LChar) = delete;
     void append(LChar c)
     {
         if (hasOverflowed())
@@ -198,12 +200,13 @@ public:
             appendCharacters(&c, 1);
     }
 
+    void appendCharacter(char) = delete;
     void append(char c)
     {
         append(static_cast<LChar>(c));
     }
 
-    void append(UChar32 c)
+    void appendCharacter(UChar32 c)
     {
         if (U_IS_BMP(c)) {
             append(static_cast<UChar>(c));
index 1625171..192d5e8 100644 (file)
@@ -1,3 +1,31 @@
+2019-08-13  Sam Weinig  <weinig@apple.com>
+
+        Rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32) to avoid accidental change in behavior when replacing append with flexibleAppend
+        https://bugs.webkit.org/show_bug.cgi?id=200675
+
+        Reviewed by Darin Adler.
+
+        * bindings/js/JSDOMConvertStrings.cpp:
+        (WebCore::stringToUSVString):
+        * css/CSSMarkup.cpp:
+        (WebCore::serializeCharacter):
+        (WebCore::serializeIdentifier):
+        (WebCore::serializeString):
+        * css/parser/CSSTokenizer.cpp:
+        (WebCore::CSSTokenizer::consumeStringTokenUntil):
+        (WebCore::CSSTokenizer::consumeUrlToken):
+        (WebCore::CSSTokenizer::consumeName):
+        * html/parser/HTMLEntityParser.cpp:
+        (WebCore::HTMLEntityParser::consumeNamedEntity):
+        * platform/mock/mediasource/MockBox.cpp:
+        (WebCore::MockBox::peekType):
+        (WebCore::MockTrackBox::MockTrackBox):
+        * rendering/RenderText.cpp:
+        (WebCore::capitalize):
+        * xml/parser/CharacterReferenceParserInlines.h:
+        (WebCore::consumeCharacterReference):
+        Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).
+
 2019-08-13  Saam Barati  <sbarati@apple.com>
 
         [WHLSL] Make lexing faster
index 1ca1ce3..187f3d3 100644 (file)
@@ -89,7 +89,7 @@ static inline String stringToUSVString(String&& string)
         if (U_IS_SURROGATE(codePoint))
             result.append(replacementCharacter);
         else
-            result.append(codePoint);
+            result.appendCharacter(codePoint);
     }
     return result.toString();
 }
index 51a52da..3887715 100644 (file)
@@ -30,6 +30,7 @@
 #include "CSSParserIdioms.h"
 #include <wtf/HexNumber.h>
 #include <wtf/text/StringBuilder.h>
+#include <wtf/unicode/CharacterNames.h>
 
 namespace WebCore {
 
@@ -72,7 +73,7 @@ static bool isCSSTokenizerIdentifier(const String& string)
 static void serializeCharacter(UChar32 c, StringBuilder& appendTo)
 {
     appendTo.append('\\');
-    appendTo.append(c);
+    appendTo.appendCharacter(c);
 }
 
 static void serializeCharacterAsCodePoint(UChar32 c, StringBuilder& appendTo)
@@ -98,13 +99,13 @@ void serializeIdentifier(const String& identifier, StringBuilder& appendTo, bool
         index += U16_LENGTH(c);
 
         if (!c)
-            appendTo.append(0xfffd);
+            appendTo.append(replacementCharacter);
         else if (c <= 0x1f || c == 0x7f || (0x30 <= c && c <= 0x39 && (isFirst || (isSecond && isFirstCharHyphen))))
             serializeCharacterAsCodePoint(c, appendTo);
         else if (c == 0x2d && isFirst && index == identifier.length())
             serializeCharacter(c, appendTo);
         else if (0x80 <= c || c == 0x2d || c == 0x5f || (0x30 <= c && c <= 0x39) || (0x41 <= c && c <= 0x5a) || (0x61 <= c && c <= 0x7a))
-            appendTo.append(c);
+            appendTo.appendCharacter(c);
         else
             serializeCharacter(c, appendTo);
 
@@ -131,7 +132,7 @@ void serializeString(const String& string, StringBuilder& appendTo)
         else if (c == 0x22 || c == 0x5c)
             serializeCharacter(c, appendTo);
         else
-            appendTo.append(c);
+            appendTo.appendCharacter(c);
     }
 
     appendTo.append('"');
index 1f1a23e..82931bf 100644 (file)
@@ -617,7 +617,7 @@ CSSParserToken CSSTokenizer::consumeStringTokenUntil(UChar endingCodePoint)
             if (isNewLine(m_input.peekWithoutReplacement(0)))
                 consumeSingleWhitespaceIfNext(); // This handles \r\n for us
             else
-                output.append(consumeEscape());
+                output.appendCharacter(consumeEscape());
         } else
             output.append(cc);
     }
@@ -695,7 +695,7 @@ CSSParserToken CSSTokenizer::consumeUrlToken()
 
         if (cc == '\\') {
             if (twoCharsAreValidEscape(cc, m_input.peekWithoutReplacement(0))) {
-                result.append(consumeEscape());
+                result.appendCharacter(consumeEscape());
                 continue;
             }
             break;
@@ -787,7 +787,7 @@ StringView CSSTokenizer::consumeName()
             continue;
         }
         if (twoCharsAreValidEscape(cc, m_input.peekWithoutReplacement(0))) {
-            result.append(consumeEscape());
+            result.appendCharacter(consumeEscape());
             continue;
         }
         reconsume(cc);
index 98503d9..a89fc60 100644 (file)
@@ -99,9 +99,9 @@ public:
         if (entitySearch.mostRecentMatch()->lastCharacter() == ';'
             || !additionalAllowedCharacter
             || !(isASCIIAlphanumeric(cc) || cc == '=')) {
-            decodedEntity.append(entitySearch.mostRecentMatch()->firstValue);
+            decodedEntity.appendCharacter(entitySearch.mostRecentMatch()->firstValue);
             if (entitySearch.mostRecentMatch()->secondValue)
-                decodedEntity.append(entitySearch.mostRecentMatch()->secondValue);
+                decodedEntity.appendCharacter(entitySearch.mostRecentMatch()->secondValue);
             return true;
         }
         unconsumeCharacters(source, consumedCharacters);
index 100912b..7ad7084 100644 (file)
@@ -51,7 +51,7 @@ String MockBox::peekType(ArrayBuffer* data)
     StringBuilder builder;
     auto array = JSC::Int8Array::create(data, 0, 4);
     for (int i = 0; i < 4; ++i)
-        builder.append(array->item(i));
+        builder.append(static_cast<char>(array->item(i)));
     return builder.toString();
 }
 
@@ -72,7 +72,7 @@ MockTrackBox::MockTrackBox(ArrayBuffer* data)
     StringBuilder builder;
     auto array = JSC::Int8Array::create(data, 12, 4);
     for (int i = 0; i < 4; ++i)
-        builder.append(array->item(i));
+        builder.append(static_cast<char>(array->item(i)));
     m_codec = builder.toString();
 
     m_kind = static_cast<TrackKind>(view->get<uint8_t>(16, true));
index 68c3a15..aad0c14 100644 (file)
@@ -171,7 +171,7 @@ String capitalize(const String& string, UChar previousCharacter)
     int32_t endOfWord;
     for (endOfWord = ubrk_next(breakIterator); endOfWord != UBRK_DONE; startOfWord = endOfWord, endOfWord = ubrk_next(breakIterator)) {
         if (startOfWord) // Do not append the first character, since it's the previous character, not from this string.
-            result.append(u_totitle(stringImpl[startOfWord - 1]));
+            result.appendCharacter(u_totitle(stringImpl[startOfWord - 1]));
         for (int i = startOfWord + 1; i < endOfWord; i++)
             result.append(stringImpl[i - 1]);
     }
index f08c927..0a465fb 100644 (file)
@@ -111,11 +111,11 @@ bool consumeCharacterReference(SegmentedString& source, StringBuilder& decodedCh
             }
             if (character == ';') {
                 source.advancePastNonNewline();
-                decodedCharacter.append(ParserFunctions::legalEntityFor(overflow ? 0 : result));
+                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
                 return true;
             }
             if (ParserFunctions::acceptMalformed()) {
-                decodedCharacter.append(ParserFunctions::legalEntityFor(overflow ? 0 : result));
+                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
                 return true;
             }
             unconsumeCharacters(source, consumedCharacters);
@@ -130,11 +130,11 @@ bool consumeCharacterReference(SegmentedString& source, StringBuilder& decodedCh
             }
             if (character == ';') {
                 source.advancePastNonNewline();
-                decodedCharacter.append(ParserFunctions::legalEntityFor(overflow ? 0 : result));
+                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
                 return true;
             }
             if (ParserFunctions::acceptMalformed()) {
-                decodedCharacter.append(ParserFunctions::legalEntityFor(overflow ? 0 : result));
+                decodedCharacter.appendCharacter(ParserFunctions::legalEntityFor(overflow ? 0 : result));
                 return true;
             }
             unconsumeCharacters(source, consumedCharacters);
index cb63535..17cda1a 100644 (file)
@@ -1,3 +1,14 @@
+2019-08-13  Sam Weinig  <weinig@apple.com>
+
+        Rename StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32) to avoid accidental change in behavior when replacing append with flexibleAppend
+        https://bugs.webkit.org/show_bug.cgi?id=200675
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WTF/StringBuilder.cpp:
+        (TestWebKitAPI::TEST):
+        Update for rename from StringBuilder::append(UChar32) to StringBuilder::appendCharacter(UChar32).
+
 2019-08-13  Zhifei Fang  <zhifei_fang@apple.com>
 
         [results.webkit.org Timeline] Performance improvement - Skip render offscreen canvas
index 4a6ea38..0c4dc0a 100644 (file)
@@ -93,9 +93,9 @@ TEST(StringBuilderTest, Append)
     // Test appending UChar32 characters to StringBuilder.
     StringBuilder builderForUChar32Append;
     UChar32 frakturAChar = 0x1D504;
-    builderForUChar32Append.append(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
+    builderForUChar32Append.appendCharacter(frakturAChar); // The fraktur A is not in the BMP, so it's two UTF-16 code units long.
     ASSERT_EQ(2U, builderForUChar32Append.length());
-    builderForUChar32Append.append(static_cast<UChar32>('A'));
+    builderForUChar32Append.appendCharacter(static_cast<UChar32>('A'));
     ASSERT_EQ(3U, builderForUChar32Append.length());
     const UChar resultArray[] = { U16_LEAD(frakturAChar), U16_TRAIL(frakturAChar), 'A' };
     expectBuilderContent(String(resultArray, WTF_ARRAY_LENGTH(resultArray)), builderForUChar32Append);