Title: [289493] trunk/Source/WebCore
Revision
289493
Author
[email protected]
Date
2022-02-09 11:39:13 -0800 (Wed, 09 Feb 2022)

Log Message

Register strings in CSSTokenizer created from preprocessing
https://bugs.webkit.org/show_bug.cgi?id=236309

Patch by Gabriel Nava Marino <[email protected]> on 2022-02-09
Reviewed by Michael Saboff.

Register strings in CSSTokenizer created from preprocessing. This will align with
what is currently done for strings with escapes in CSSTokenizer::consumeName().

* css/parser/CSSTokenizer.cpp:
(WebCore::CSSTokenizer::preprocessString):
(WebCore::CSSTokenizer::tryCreate):
(WebCore::CSSTokenizer::CSSTokenizer):
(WebCore::preprocessString): Deleted.
* css/parser/CSSTokenizer.h:
* css/parser/CSSTokenizerInputStream.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289492 => 289493)


--- trunk/Source/WebCore/ChangeLog	2022-02-09 19:35:24 UTC (rev 289492)
+++ trunk/Source/WebCore/ChangeLog	2022-02-09 19:39:13 UTC (rev 289493)
@@ -1,3 +1,21 @@
+2022-02-09  Gabriel Nava Marino  <[email protected]>
+
+        Register strings in CSSTokenizer created from preprocessing
+        https://bugs.webkit.org/show_bug.cgi?id=236309
+
+        Reviewed by Michael Saboff.
+
+        Register strings in CSSTokenizer created from preprocessing. This will align with
+        what is currently done for strings with escapes in CSSTokenizer::consumeName().
+
+        * css/parser/CSSTokenizer.cpp:
+        (WebCore::CSSTokenizer::preprocessString):
+        (WebCore::CSSTokenizer::tryCreate):
+        (WebCore::CSSTokenizer::CSSTokenizer):
+        (WebCore::preprocessString): Deleted.
+        * css/parser/CSSTokenizer.h:
+        * css/parser/CSSTokenizerInputStream.h:
+
 2022-02-09  Kimmo Kinnunen  <[email protected]>
 
         DisplayListRecorder implementations are not able to obtain extra information out of source ImageBuffers

Modified: trunk/Source/WebCore/css/parser/CSSTokenizer.cpp (289492 => 289493)


--- trunk/Source/WebCore/css/parser/CSSTokenizer.cpp	2022-02-09 19:35:24 UTC (rev 289492)
+++ trunk/Source/WebCore/css/parser/CSSTokenizer.cpp	2022-02-09 19:39:13 UTC (rev 289493)
@@ -43,12 +43,16 @@
 namespace WebCore {
 
 // https://drafts.csswg.org/css-syntax/#input-preprocessing
-static String preprocessString(String string)
+String CSSTokenizer::preprocessString(String string)
 {
     // We don't replace '\r' and '\f' with '\n' as the specification suggests, instead
     // we treat them all the same in the isNewLine function below.
+    StringImpl* oldImpl = string.impl();
     string.replace('\0', replacementCharacter);
-    return replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string));
+    String replaced = replaceUnpairedSurrogatesWithReplacementCharacter(WTFMove(string));
+    if (replaced.impl() != oldImpl)
+        registerString(replaced);
+    return replaced;
 }
 
 std::unique_ptr<CSSTokenizer> CSSTokenizer::tryCreate(const String& string)
@@ -55,7 +59,7 @@
 {
     bool success = true;
     // We can't use makeUnique here because it does not have access to this private constructor.
-    auto tokenizer = std::unique_ptr<CSSTokenizer>(new CSSTokenizer(preprocessString(string), nullptr, &success));
+    auto tokenizer = std::unique_ptr<CSSTokenizer>(new CSSTokenizer(string, nullptr, &success));
     if (UNLIKELY(!success))
         return nullptr;
     return tokenizer;
@@ -65,7 +69,7 @@
 {
     bool success = true;
     // We can't use makeUnique here because it does not have access to this private constructor.
-    auto tokenizer = std::unique_ptr<CSSTokenizer>(new CSSTokenizer(preprocessString(string), &wrapper, &success));
+    auto tokenizer = std::unique_ptr<CSSTokenizer>(new CSSTokenizer(string, &wrapper, &success));
     if (UNLIKELY(!success))
         return nullptr;
     return tokenizer;
@@ -72,17 +76,17 @@
 }
 
 CSSTokenizer::CSSTokenizer(const String& string)
-    : CSSTokenizer(preprocessString(string), nullptr, nullptr)
+    : CSSTokenizer(string, nullptr, nullptr)
 {
 }
 
 CSSTokenizer::CSSTokenizer(const String& string, CSSParserObserverWrapper& wrapper)
-    : CSSTokenizer(preprocessString(string), &wrapper, nullptr)
+    : CSSTokenizer(string, &wrapper, nullptr)
 {
 }
 
-CSSTokenizer::CSSTokenizer(String&& string, CSSParserObserverWrapper* wrapper, bool* constructionSuccessPtr)
-    : m_input(string)
+CSSTokenizer::CSSTokenizer(const String& string, CSSParserObserverWrapper* wrapper, bool* constructionSuccessPtr)
+    : m_input(preprocessString(string))
 {
     if (constructionSuccessPtr)
         *constructionSuccessPtr = true;

Modified: trunk/Source/WebCore/css/parser/CSSTokenizer.h (289492 => 289493)


--- trunk/Source/WebCore/css/parser/CSSTokenizer.h	2022-02-09 19:35:24 UTC (rev 289492)
+++ trunk/Source/WebCore/css/parser/CSSTokenizer.h	2022-02-09 19:39:13 UTC (rev 289493)
@@ -57,7 +57,7 @@
     Vector<String>&& escapedStringsForAdoption() { return WTFMove(m_stringPool); }
 
 private:
-    CSSTokenizer(String&&, CSSParserObserverWrapper*, bool* constructionSuccess);
+    CSSTokenizer(const String&, CSSParserObserverWrapper*, bool* constructionSuccess);
 
     CSSParserToken nextToken();
 
@@ -64,6 +64,8 @@
     UChar consume();
     void reconsume(UChar);
 
+    String preprocessString(String);
+
     CSSParserToken consumeNumericToken();
     CSSParserToken consumeIdentLikeToken();
     CSSParserToken consumeNumber();
@@ -122,11 +124,10 @@
     static const CodePoint codePoints[];
 
     Vector<CSSParserTokenType, 8> m_blockStack;
-    CSSTokenizerInputStream m_input;
-    
     Vector<CSSParserToken, 32> m_tokens;
     // We only allocate strings when escapes are used.
     Vector<String> m_stringPool;
+    CSSTokenizerInputStream m_input;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/parser/CSSTokenizerInputStream.h (289492 => 289493)


--- trunk/Source/WebCore/css/parser/CSSTokenizerInputStream.h	2022-02-09 19:35:24 UTC (rev 289492)
+++ trunk/Source/WebCore/css/parser/CSSTokenizerInputStream.h	2022-02-09 19:39:13 UTC (rev 289493)
@@ -41,8 +41,7 @@
 public:
     explicit CSSTokenizerInputStream(const String& input);
 
-    // Gets the char in the stream replacing NUL characters with a unicode
-    // replacement character. Will return (NUL) kEndOfFileMarker when at the
+    // Gets the char in the stream. Will return (NUL) kEndOfFileMarker when at the
     // end of the stream.
     UChar nextInputChar() const
     {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to