Changeset 266986 in webkit


Ignore:
Timestamp:
Sep 12, 2020 6:31:27 PM (4 years ago)
Author:
Simon Fraser
Message:

Replace formatForDebugger() which uses raw char* with debugDescription()
https://bugs.webkit.org/show_bug.cgi?id=216447

Reviewed by Darin Adler.

formatForDebugger() relied on raw char* and buffer lengths. Replace with debugDescription()
which returns a String, and is already a convention used in various classes.

  • accessibility/mac/WebAccessibilityObjectWrapperMac.mm:

(-[WebAccessibilityObjectWrapper debugDescriptionForTextMarker:]):
(formatForDebugger):

  • dom/Element.cpp:

(WebCore::Element::formatForDebugger const): Deleted.

  • dom/Element.h:
  • dom/Node.cpp:

(WebCore::Node::debugDescription const):
(WebCore::Node::formatForDebugger const): Deleted.

  • dom/Node.h:
  • dom/Position.cpp:

(WebCore::Position::debugDescription const):
(WebCore::Position::formatForDebugger const): Deleted.

  • dom/Position.h:
  • dom/Range.cpp:

(WebCore::Range::debugDescription const):
(WebCore::Range::formatForDebugger const): Deleted.

  • dom/Range.h:
  • dom/Text.cpp:

(WebCore::Text::formatForDebugger const): Deleted.

  • dom/Text.h:
  • editing/FrameSelection.cpp:

(WebCore::FrameSelection::debugDescription const):
(WebCore::FrameSelection::formatForDebugger const): Deleted.

  • editing/FrameSelection.h:
  • editing/VisiblePosition.cpp:

(WebCore::VisiblePosition::debugDescription const):
(WebCore::VisiblePosition::formatForDebugger const): Deleted.

  • editing/VisiblePosition.h:
  • editing/VisibleSelection.cpp:

(WebCore::VisibleSelection::debugDescription const):
(WebCore::VisibleSelection::formatForDebugger const): Deleted.

  • editing/VisibleSelection.h:
Location:
trunk/Source/WebCore
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r266985 r266986  
     12020-09-12  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Replace formatForDebugger() which uses raw char* with debugDescription()
     4        https://bugs.webkit.org/show_bug.cgi?id=216447
     5
     6        Reviewed by Darin Adler.
     7
     8        formatForDebugger() relied on raw char* and buffer lengths. Replace with debugDescription()
     9        which returns a String, and is already a convention used in various classes.
     10
     11        * accessibility/mac/WebAccessibilityObjectWrapperMac.mm:
     12        (-[WebAccessibilityObjectWrapper debugDescriptionForTextMarker:]):
     13        (formatForDebugger):
     14        * dom/Element.cpp:
     15        (WebCore::Element::formatForDebugger const): Deleted.
     16        * dom/Element.h:
     17        * dom/Node.cpp:
     18        (WebCore::Node::debugDescription const):
     19        (WebCore::Node::formatForDebugger const): Deleted.
     20        * dom/Node.h:
     21        * dom/Position.cpp:
     22        (WebCore::Position::debugDescription const):
     23        (WebCore::Position::formatForDebugger const): Deleted.
     24        * dom/Position.h:
     25        * dom/Range.cpp:
     26        (WebCore::Range::debugDescription const):
     27        (WebCore::Range::formatForDebugger const): Deleted.
     28        * dom/Range.h:
     29        * dom/Text.cpp:
     30        (WebCore::Text::formatForDebugger const): Deleted.
     31        * dom/Text.h:
     32        * editing/FrameSelection.cpp:
     33        (WebCore::FrameSelection::debugDescription const):
     34        (WebCore::FrameSelection::formatForDebugger const): Deleted.
     35        * editing/FrameSelection.h:
     36        * editing/VisiblePosition.cpp:
     37        (WebCore::VisiblePosition::debugDescription const):
     38        (WebCore::VisiblePosition::formatForDebugger const): Deleted.
     39        * editing/VisiblePosition.h:
     40        * editing/VisibleSelection.cpp:
     41        (WebCore::VisibleSelection::debugDescription const):
     42        (WebCore::VisibleSelection::formatForDebugger const): Deleted.
     43        * editing/VisibleSelection.h:
     44
    1452020-09-12  Simon Fraser  <simon.fraser@apple.com>
    246
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperMac.mm

    r266487 r266986  
    36893689- (NSString *)debugDescriptionForTextMarker:(id)textMarker
    36903690{
    3691     char description[1024];
    3692     [self visiblePositionForTextMarker:textMarker].formatForDebugger(description, sizeof(description));
    3693     return [NSString stringWithUTF8String:description];
     3691    return [self visiblePositionForTextMarker:textMarker].debugDescription();
    36943692
    36953693}
     
    37293727    StringBuilder result;
    37303728   
    3731     const int FormatBufferSize = 1024;
    3732     char format[FormatBufferSize];
    37333729    result.appendLiteral("from ");
    3734     range.start.formatForDebugger(format, FormatBufferSize);
    3735     result.append(format);
     3730    result.append(range.start.debugDescription());
    37363731    result.appendLiteral(" to ");
    3737     range.end.formatForDebugger(format, FormatBufferSize);
    3738     result.append(format);
     3732    result.append(range.end.debugDescription());
    37393733   
    37403734    strlcpy(buffer, result.toString().utf8().data(), length);
  • trunk/Source/WebCore/dom/Element.cpp

    r266899 r266986  
    27232723}
    27242724
    2725 #if ENABLE(TREE_DEBUGGING)
    2726 
    2727 void Element::formatForDebugger(char* buffer, unsigned length) const
    2728 {
    2729     StringBuilder result;
    2730     String s;
    2731 
    2732     result.append(nodeName());
    2733 
    2734     s = getIdAttribute();
    2735     if (s.length() > 0) {
    2736         if (result.length() > 0)
    2737             result.appendLiteral("; ");
    2738         result.appendLiteral("id=");
    2739         result.append(s);
    2740     }
    2741 
    2742     s = getAttribute(classAttr);
    2743     if (s.length() > 0) {
    2744         if (result.length() > 0)
    2745             result.appendLiteral("; ");
    2746         result.appendLiteral("class=");
    2747         result.append(s);
    2748     }
    2749 
    2750     strncpy(buffer, result.toString().utf8().data(), length - 1);
    2751 }
    2752 
    2753 #endif
    2754 
    27552725const Vector<RefPtr<Attr>>& Element::attrNodeList()
    27562726{
  • trunk/Source/WebCore/dom/Element.h

    r266776 r266986  
    700700    LayoutRect absoluteEventBoundsOfElementAndDescendants(bool& includesFixedPositionElements);
    701701
    702 #if ENABLE(TREE_DEBUGGING)
    703     void formatForDebugger(char* buffer, unsigned length) const override;
    704 #endif
    705 
    706702#if ENABLE(INTERSECTION_OBSERVER)
    707703    void disconnectFromIntersectionObservers();
  • trunk/Source/WebCore/dom/Node.cpp

    r266776 r266986  
    17581758String Node::debugDescription() const
    17591759{
    1760     StringBuilder builder;
    1761     builder.append(nodeName(), " 0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase));
    1762     return builder.toString();
     1760    auto name = nodeName();
     1761    return makeString(name.isEmpty() ? "<none>" : "", name, " 0x"_s, hex(reinterpret_cast<uintptr_t>(this), Lowercase));
    17631762}
    17641763
     
    18831882    String startingIndent;
    18841883    traverseTreeAndMark(startingIndent, rootNode, markedNode1, markedLabel1, markedNode2, markedLabel2);
    1885 }
    1886 
    1887 void Node::formatForDebugger(char* buffer, unsigned length) const
    1888 {
    1889     String result;
    1890     String s;
    1891 
    1892     s = nodeName();
    1893     if (s.isEmpty())
    1894         result = "<none>";
    1895     else
    1896         result = s;
    1897 
    1898     strncpy(buffer, result.utf8().data(), length - 1);
    18991884}
    19001885
  • trunk/Source/WebCore/dom/Node.h

    r266887 r266986  
    424424
    425425#if ENABLE(TREE_DEBUGGING)
    426     virtual void formatForDebugger(char* buffer, unsigned length) const;
    427 
    428426    void showNode(const char* prefix = "") const;
    429427    void showTreeForThis() const;
  • trunk/Source/WebCore/dom/Position.cpp

    r266557 r266986  
    13801380}
    13811381
    1382 void Position::formatForDebugger(char* buffer, unsigned length) const
    1383 {
    1384     StringBuilder result;
    1385 
     1382String Position::debugDescription() const
     1383{
    13861384    if (isNull())
    1387         result.appendLiteral("<null>");
    1388     else {
    1389         char s[1024];
    1390         result.appendLiteral("offset ");
    1391         result.appendNumber(m_offset);
    1392         result.appendLiteral(" of ");
    1393         deprecatedNode()->formatForDebugger(s, sizeof(s));
    1394         result.append(s);
    1395     }
    1396 
    1397     strncpy(buffer, result.toString().utf8().data(), length - 1);
     1385        return "<null>"_s;
     1386    return makeString("offset ", m_offset, " of ", deprecatedNode()->debugDescription());
    13981387}
    13991388
  • trunk/Source/WebCore/dom/Position.h

    r266487 r266986  
    194194
    195195#if ENABLE(TREE_DEBUGGING)
    196     void formatForDebugger(char* buffer, unsigned length) const;
     196    String debugDescription() const;
    197197    void showAnchorTypeAndOffset() const;
    198198    void showTreeForThis() const;
  • trunk/Source/WebCore/dom/Range.cpp

    r266295 r266986  
    840840
    841841#if ENABLE(TREE_DEBUGGING)
    842 void Range::formatForDebugger(char* buffer, unsigned length) const
    843 {
    844     StringBuilder result;
    845 
    846     const int FormatBufferSize = 1024;
    847     char s[FormatBufferSize];
    848     result.appendLiteral("from offset ");
    849     result.appendNumber(m_start.offset());
    850     result.appendLiteral(" of ");
    851     startContainer().formatForDebugger(s, FormatBufferSize);
    852     result.append(s);
    853     result.appendLiteral(" to offset ");
    854     result.appendNumber(m_end.offset());
    855     result.appendLiteral(" of ");
    856     endContainer().formatForDebugger(s, FormatBufferSize);
    857     result.append(s);
    858 
    859     strncpy(buffer, result.toString().utf8().data(), length - 1);
     842String Range::debugDescription() const
     843{
     844    return makeString("from offset ", m_start.offset(), " of ", startContainer().debugDescription(), " to offset ", m_end.offset(), " of ", endContainer().debugDescription());
    860845}
    861846#endif
  • trunk/Source/WebCore/dom/Range.h

    r266295 r266986  
    101101
    102102#if ENABLE(TREE_DEBUGGING)
    103     void formatForDebugger(char* buffer, unsigned length) const;
     103    String debugDescription() const;
    104104#endif
    105105
  • trunk/Source/WebCore/dom/Text.cpp

    r264305 r266986  
    246246}
    247247
    248 #if ENABLE(TREE_DEBUGGING)
    249 void Text::formatForDebugger(char* buffer, unsigned length) const
    250 {
    251     strncpy(buffer, debugDescription().utf8().data(), length - 1);
    252     buffer[length - 1] = '\0';
    253 }
    254 #endif
    255 
    256248void Text::setDataAndUpdate(const String& newData, unsigned offsetOfReplacedData, unsigned oldLength, unsigned newLength)
    257249{
  • trunk/Source/WebCore/dom/Text.h

    r264305 r266986  
    7373
    7474    virtual Ref<Text> virtualCreate(const String&);
    75 
    76 #if ENABLE(TREE_DEBUGGING)
    77     void formatForDebugger(char* buffer, unsigned length) const override;
    78 #endif
    7975};
    8076
  • trunk/Source/WebCore/editing/FrameSelection.cpp

    r266557 r266986  
    24842484#if ENABLE(TREE_DEBUGGING)
    24852485
    2486 void FrameSelection::formatForDebugger(char* buffer, unsigned length) const
    2487 {
    2488     m_selection.formatForDebugger(buffer, length);
     2486String FrameSelection::debugDescription() const
     2487{
     2488    return m_selection.debugDescription();
    24892489}
    24902490
  • trunk/Source/WebCore/editing/FrameSelection.h

    r266557 r266986  
    218218
    219219#if ENABLE(TREE_DEBUGGING)
    220     void formatForDebugger(char* buffer, unsigned length) const;
     220    String debugDescription() const;
    221221    void showTreeForThis() const;
    222222#endif
  • trunk/Source/WebCore/editing/VisiblePosition.cpp

    r266557 r266986  
    682682}
    683683
    684 void VisiblePosition::formatForDebugger(char* buffer, unsigned length) const
    685 {
    686     m_deepPosition.formatForDebugger(buffer, length);
     684String VisiblePosition::debugDescription() const
     685{
     686    return m_deepPosition.debugDescription();
    687687}
    688688
  • trunk/Source/WebCore/editing/VisiblePosition.h

    r266489 r266986  
    9292#if ENABLE(TREE_DEBUGGING)
    9393    void debugPosition(const char* msg = "") const;
    94     void formatForDebugger(char* buffer, unsigned length) const;
     94    String debugDescription() const;
    9595    void showTreeForThis() const;
    9696#endif
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r266557 r266986  
    676676}
    677677
    678 void VisibleSelection::formatForDebugger(char* buffer, unsigned length) const
    679 {
    680     StringBuilder result;
    681     String s;
    682 
    683     if (isNone()) {
    684         result.appendLiteral("<none>");
    685     } else {
    686         const int FormatBufferSize = 1024;
    687         char s[FormatBufferSize];
    688         result.appendLiteral("from ");
    689         start().formatForDebugger(s, FormatBufferSize);
    690         result.append(s);
    691         result.appendLiteral(" to ");
    692         end().formatForDebugger(s, FormatBufferSize);
    693         result.append(s);
    694     }
    695 
    696     strncpy(buffer, result.toString().utf8().data(), length - 1);
     678String VisibleSelection::debugDescription() const
     679{
     680    if (isNone())
     681        return "<none>"_s;
     682    return makeString("from ", start().debugDescription(), " to ", end().debugDescription());
    697683}
    698684
  • trunk/Source/WebCore/editing/VisibleSelection.h

    r266557 r266986  
    107107#if ENABLE(TREE_DEBUGGING)
    108108    void debugPosition() const;
    109     void formatForDebugger(char* buffer, unsigned length) const;
     109    String debugDescription() const;
    110110    void showTreeForThis() const;
    111111#endif
Note: See TracChangeset for help on using the changeset viewer.