Title: [277692] trunk/Source/WebCore
Revision
277692
Author
simon.fra...@apple.com
Date
2021-05-18 16:55:08 -0700 (Tue, 18 May 2021)

Log Message

Layer names should not contain object addresses in release builds
https://bugs.webkit.org/show_bug.cgi?id=225926

Reviewed by Geoffrey Garen.

Avoid putting object addresses in layer name strings (which end up on CALayers)
to reduce string bloat.

RenderLayer::name() now calls a description() function on RenderObject, which
in turn calls the same on its Node. These description() functions don't put
object addresses in the string.

Alternatives considered: #ifdeffing in the debugDescription() implementations:
I decided not to because calling a function called debugFoo in release seems
wrong. It might also be useful to dump the string with addresses when debugging
in a release build.

Renaming debugDescription() to description() and passing a behavior enum:
Seems about as complicated as this change.

* dom/Element.cpp:
(WebCore::appendAttributes):
(WebCore::Element::description const):
(WebCore::Element::debugDescription const):
* dom/Element.h:
* dom/Node.cpp:
(WebCore::Node::description const):
* dom/Node.h:
* dom/Text.cpp:
(WebCore::appendTextRepresentation):
(WebCore::Text::description const):
(WebCore::Text::debugDescription const):
* dom/Text.h:
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::name const):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::description const):
* rendering/RenderObject.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (277691 => 277692)


--- trunk/Source/WebCore/ChangeLog	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/ChangeLog	2021-05-18 23:55:08 UTC (rev 277692)
@@ -1,3 +1,44 @@
+2021-05-18  Simon Fraser  <simon.fra...@apple.com>
+
+        Layer names should not contain object addresses in release builds
+        https://bugs.webkit.org/show_bug.cgi?id=225926
+
+        Reviewed by Geoffrey Garen.
+
+        Avoid putting object addresses in layer name strings (which end up on CALayers)
+        to reduce string bloat.
+
+        RenderLayer::name() now calls a description() function on RenderObject, which
+        in turn calls the same on its Node. These description() functions don't put
+        object addresses in the string.
+
+        Alternatives considered: #ifdeffing in the debugDescription() implementations:
+        I decided not to because calling a function called debugFoo in release seems
+        wrong. It might also be useful to dump the string with addresses when debugging
+        in a release build.
+
+        Renaming debugDescription() to description() and passing a behavior enum:
+        Seems about as complicated as this change.
+
+        * dom/Element.cpp:
+        (WebCore::appendAttributes):
+        (WebCore::Element::description const):
+        (WebCore::Element::debugDescription const):
+        * dom/Element.h:
+        * dom/Node.cpp:
+        (WebCore::Node::description const):
+        * dom/Node.h:
+        * dom/Text.cpp:
+        (WebCore::appendTextRepresentation):
+        (WebCore::Text::description const):
+        (WebCore::Text::debugDescription const):
+        * dom/Text.h:
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::name const):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::description const):
+        * rendering/RenderObject.h:
+
 2021-05-18  Jer Noble  <jer.no...@apple.com>
 
         [GPUP] RemoteAudioSession calls into AVAudioSession when GPUP is enabled, causing hangs

Modified: trunk/Source/WebCore/dom/Element.cpp (277691 => 277692)


--- trunk/Source/WebCore/dom/Element.cpp	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Element.cpp	2021-05-18 23:55:08 UTC (rev 277692)
@@ -2723,18 +2723,14 @@
     checkForSiblingStyleChanges(*this, FinishedParsingChildren, ElementTraversal::lastChild(*this), nullptr);
 }
 
-String Element::debugDescription() const
+static void appendAttributes(StringBuilder& builder, const Element& element)
 {
-    StringBuilder builder;
+    if (element.hasID())
+        builder.append(" id=\'", element.getIdAttribute(), '\'');
 
-    builder.append(ContainerNode::debugDescription());
-
-    if (hasID())
-        builder.append(" id=\'", getIdAttribute(), '\'');
-
-    if (hasClass()) {
+    if (element.hasClass()) {
         builder.appendLiteral(" class=\'");
-        size_t classNamesToDump = classNames().size();
+        size_t classNamesToDump = element.classNames().size();
         constexpr size_t maxNumClassNames = 7;
         bool addEllipsis = false;
         if (classNamesToDump > maxNumClassNames) {
@@ -2745,16 +2741,34 @@
         for (size_t i = 0; i < classNamesToDump; ++i) {
             if (i > 0)
                 builder.append(' ');
-            builder.append(classNames()[i]);
+            builder.append(element.classNames()[i]);
         }
         if (addEllipsis)
             builder.append(" ...");
         builder.append('\'');
     }
+}
 
+String Element::description() const
+{
+    StringBuilder builder;
+
+    builder.append(ContainerNode::description());
+    appendAttributes(builder, *this);
+
     return builder.toString();
 }
 
+String Element::debugDescription() const
+{
+    StringBuilder builder;
+
+    builder.append(ContainerNode::debugDescription());
+    appendAttributes(builder, *this);
+
+    return builder.toString();
+}
+
 const Vector<RefPtr<Attr>>& Element::attrNodeList()
 {
     ASSERT(hasSyntheticAttrChildNodes());

Modified: trunk/Source/WebCore/dom/Element.h (277691 => 277692)


--- trunk/Source/WebCore/dom/Element.h	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Element.h	2021-05-18 23:55:08 UTC (rev 277692)
@@ -624,6 +624,7 @@
 
     ElementIdentifier createElementIdentifier();
 
+    String description() const override;
     String debugDescription() const override;
 
 protected:

Modified: trunk/Source/WebCore/dom/Node.cpp (277691 => 277692)


--- trunk/Source/WebCore/dom/Node.cpp	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Node.cpp	2021-05-18 23:55:08 UTC (rev 277692)
@@ -1754,6 +1754,12 @@
     return p;
 }
 
+String Node::description() const
+{
+    auto name = nodeName();
+    return makeString(name.isEmpty() ? "<none>" : "", name);
+}
+
 String Node::debugDescription() const
 {
     auto name = nodeName();

Modified: trunk/Source/WebCore/dom/Node.h (277691 => 277692)


--- trunk/Source/WebCore/dom/Node.h	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Node.h	2021-05-18 23:55:08 UTC (rev 277692)
@@ -429,6 +429,7 @@
     };
     virtual void removedFromAncestor(RemovalType, ContainerNode& oldParentOfRemovedTree);
 
+    virtual String description() const;
     virtual String debugDescription() const;
 
 #if ENABLE(TREE_DEBUGGING)

Modified: trunk/Source/WebCore/dom/Text.cpp (277691 => 277692)


--- trunk/Source/WebCore/dom/Text.cpp	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Text.cpp	2021-05-18 23:55:08 UTC (rev 277692)
@@ -223,13 +223,9 @@
     document().updateTextRenderer(*this, offsetOfReplacedData, lengthOfReplacedData);
 }
 
-String Text::debugDescription() const
+static void appendTextRepresentation(StringBuilder& builder, const Text& text)
 {
-    StringBuilder builder;
-
-    builder.append(CharacterData::debugDescription());
-
-    String value = data();
+    String value = text.data();
     builder.append(" length="_s, value.length());
 
     value.replaceWithLiteral('\\', "\\\\");
@@ -242,10 +238,28 @@
     }
 
     builder.append(" \"", value, '\"');
+}
 
+String Text::description() const
+{
+    StringBuilder builder;
+
+    builder.append(CharacterData::description());
+    appendTextRepresentation(builder, *this);
+
     return builder.toString();
 }
 
+String Text::debugDescription() const
+{
+    StringBuilder builder;
+
+    builder.append(CharacterData::debugDescription());
+    appendTextRepresentation(builder, *this);
+
+    return builder.toString();
+}
+
 void Text::setDataAndUpdate(const String& newData, unsigned offsetOfReplacedData, unsigned oldLength, unsigned newLength, UpdateLiveRanges updateLiveRanges)
 {
     auto oldData = data();

Modified: trunk/Source/WebCore/dom/Text.h (277691 => 277692)


--- trunk/Source/WebCore/dom/Text.h	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/dom/Text.h	2021-05-18 23:55:08 UTC (rev 277692)
@@ -55,6 +55,7 @@
 
     void updateRendererAfterContentChange(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData);
 
+    String description() const final;
     String debugDescription() const final;
 
 protected:

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (277691 => 277692)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2021-05-18 23:55:08 UTC (rev 277692)
@@ -814,7 +814,7 @@
 String RenderLayer::name() const
 {
     StringBuilder name;
-    name.append(renderer().debugDescription());
+    name.append(renderer().description());
 
     if (isReflection())
         name.appendLiteral(" (reflection)");

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (277691 => 277692)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2021-05-18 23:55:08 UTC (rev 277692)
@@ -2410,6 +2410,17 @@
 
 #endif
 
+String RenderObject::description() const
+{
+    StringBuilder builder;
+
+    builder.append(renderName(), ' ');
+    if (node())
+        builder.append(' ', node()->description());
+    
+    return builder.toString();
+}
+
 String RenderObject::debugDescription() const
 {
     StringBuilder builder;

Modified: trunk/Source/WebCore/rendering/RenderObject.h (277691 => 277692)


--- trunk/Source/WebCore/rendering/RenderObject.h	2021-05-18 23:34:13 UTC (rev 277691)
+++ trunk/Source/WebCore/rendering/RenderObject.h	2021-05-18 23:55:08 UTC (rev 277692)
@@ -726,6 +726,7 @@
     void resetFragmentedFlowStateOnRemoval();
     void initializeFragmentedFlowStateOnInsertion();
 
+    virtual String description() const;
     virtual String debugDescription() const;
 
 protected:
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to