Title: [259581] trunk/Source/WebCore
Revision
259581
Author
[email protected]
Date
2020-04-06 11:09:10 -0700 (Mon, 06 Apr 2020)

Log Message

Make RenderObject TextStream-loggable
https://bugs.webkit.org/show_bug.cgi?id=210035

Post-landing followup. More use of StringBuilder's variadic append. Have Node::debugDescription() include
its address, and have derived classes get the base class debugDescription(). Add an override in Text.

* dom/Element.cpp:
(WebCore::Element::debugDescription const):
* dom/Node.cpp:
(WebCore::Node::debugDescription const):
* dom/Text.cpp:
(WebCore::Text::debugDescription const):
(WebCore::Text::formatForDebugger const):
* dom/Text.h:
* rendering/RenderObject.cpp:
(WebCore::RenderObject::debugDescription const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (259580 => 259581)


--- trunk/Source/WebCore/ChangeLog	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/ChangeLog	2020-04-06 18:09:10 UTC (rev 259581)
@@ -1,3 +1,22 @@
+2020-04-06  Simon Fraser  <[email protected]>
+
+        Make RenderObject TextStream-loggable
+        https://bugs.webkit.org/show_bug.cgi?id=210035
+
+        Post-landing followup. More use of StringBuilder's variadic append. Have Node::debugDescription() include
+        its address, and have derived classes get the base class debugDescription(). Add an override in Text.
+
+        * dom/Element.cpp:
+        (WebCore::Element::debugDescription const):
+        * dom/Node.cpp:
+        (WebCore::Node::debugDescription const):
+        * dom/Text.cpp:
+        (WebCore::Text::debugDescription const):
+        (WebCore::Text::formatForDebugger const):
+        * dom/Text.h:
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::debugDescription const):
+
 2020-04-06  Cathie Chen  <[email protected]>
 
         The change of zoom shouldn't affect ResizeObserverSize

Modified: trunk/Source/WebCore/dom/Element.cpp (259580 => 259581)


--- trunk/Source/WebCore/dom/Element.cpp	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/dom/Element.cpp	2020-04-06 18:09:10 UTC (rev 259581)
@@ -2629,18 +2629,15 @@
 {
     StringBuilder builder;
 
-    builder.append(nodeName());
+    builder.append(ContainerNode::debugDescription());
 
-    if (hasID()) {
-        builder.appendLiteral(" id=\'");
-        builder.append(getIdAttribute());
-        builder.append('\'');
-    }
+    if (hasID())
+        builder.append(" id=\'", getIdAttribute(), '\'');
 
     if (hasClass()) {
         builder.appendLiteral(" class=\'");
         size_t classNamesToDump = classNames().size();
-        const size_t maxNumClassNames = 7;
+        constexpr size_t maxNumClassNames = 7;
         bool addEllipsis = false;
         if (classNamesToDump > maxNumClassNames) {
             classNamesToDump = maxNumClassNames;
@@ -2653,7 +2650,7 @@
             builder.append(classNames()[i]);
         }
         if (addEllipsis)
-            builder.append("...");
+            builder.append(" ...");
         builder.append('\'');
     }
 

Modified: trunk/Source/WebCore/dom/Node.cpp (259580 => 259581)


--- trunk/Source/WebCore/dom/Node.cpp	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/dom/Node.cpp	2020-04-06 18:09:10 UTC (rev 259581)
@@ -77,6 +77,7 @@
 #include "XMLNSNames.h"
 #include "XMLNames.h"
 #include <_javascript_Core/HeapInlines.h>
+#include <wtf/HexNumber.h>
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/RefCountedLeakCounter.h>
 #include <wtf/SHA1.h>
@@ -1754,26 +1755,7 @@
 String Node::debugDescription() const
 {
     StringBuilder builder;
-
-    builder.append(nodeName());
-
-    if (isTextNode()) {
-        String value = nodeValue();
-        value.replaceWithLiteral('\\', "\\\\");
-        value.replaceWithLiteral('\n', "\\n");
-        
-        const size_t maxDumpLength = 30;
-        if (value.length() > maxDumpLength) {
-            value.truncate(maxDumpLength - 10);
-            value.append("..."_s);
-        }
-        
-        builder.append(' ');
-        builder.append('\"');
-        builder.append(value);
-        builder.append('\"');
-    }
-
+    builder.append(nodeName(), " 0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase));
     return builder.toString();
 }
 

Modified: trunk/Source/WebCore/dom/Text.cpp (259580 => 259581)


--- trunk/Source/WebCore/dom/Text.cpp	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/dom/Text.cpp	2020-04-06 18:09:10 UTC (rev 259581)
@@ -221,26 +221,33 @@
     document().updateTextRenderer(*this, offsetOfReplacedData, lengthOfReplacedData);
 }
 
-#if ENABLE(TREE_DEBUGGING)
-void Text::formatForDebugger(char* buffer, unsigned length) const
+String Text::debugDescription() const
 {
-    StringBuilder result;
-    String s;
+    StringBuilder builder;
 
-    result.append(nodeName());
+    builder.append(CharacterData::debugDescription());
 
-    s = data();
-    if (s.length() > 0) {
-        if (result.length())
-            result.appendLiteral("; ");
-        result.appendLiteral("length=");
-        result.appendNumber(s.length());
-        result.appendLiteral("; value=\"");
-        result.append(s);
-        result.append('"');
+    String value = data();
+    builder.append(" length="_s, value.length());
+
+    value.replaceWithLiteral('\\', "\\\\");
+    value.replaceWithLiteral('\n', "\\n");
+    
+    const size_t maxDumpLength = 30;
+    if (value.length() > maxDumpLength) {
+        value.truncate(maxDumpLength - 10);
+        value.append("..."_s);
     }
 
-    strncpy(buffer, result.toString().utf8().data(), length - 1);
+    builder.append(" \"", value, '\"');
+
+    return builder.toString();
+}
+
+#if ENABLE(TREE_DEBUGGING)
+void Text::formatForDebugger(char* buffer, unsigned length) const
+{
+    strncpy(buffer, debugDescription().utf8().data(), length - 1);
     buffer[length - 1] = '\0';
 }
 #endif

Modified: trunk/Source/WebCore/dom/Text.h (259580 => 259581)


--- trunk/Source/WebCore/dom/Text.h	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/dom/Text.h	2020-04-06 18:09:10 UTC (rev 259581)
@@ -55,6 +55,8 @@
 
     void updateRendererAfterContentChange(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData);
 
+    String debugDescription() const final;
+
 protected:
     Text(Document& document, const String& data, ConstructionType type)
         : CharacterData(document, data, type)

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (259580 => 259581)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2020-04-06 18:08:21 UTC (rev 259580)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2020-04-06 18:09:10 UTC (rev 259581)
@@ -1906,13 +1906,9 @@
 {
     StringBuilder builder;
 
-    builder.append(renderName());
-    builder.append(" 0x"_s);
-    builder.append(hex(reinterpret_cast<uintptr_t>(this), Lowercase));
-    builder.append(' ');
-
+    builder.append(renderName(), " 0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase));
     if (node())
-        builder.append(node()->debugDescription());
+        builder.append(' ', node()->debugDescription());
     
     return builder.toString();
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to