RenderTable should not hold a collection of raw pointers to RenderTableCaption
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Oct 2017 04:15:03 +0000 (04:15 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 7 Oct 2017 04:15:03 +0000 (04:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=178026
<rdar://problem/34863090>

Reviewed by Simon Fraser.

Similar to sections, RenderTable should not store captions as raw pointers. Their lifetimes are
not guaranteed to be sync with the RenderTable's.

Covered by existing tests.

* rendering/RenderTable.cpp:
(WebCore::RenderTable::addCaption):
(WebCore::RenderTable::removeCaption):
(WebCore::RenderTable::addOverflowFromChildren):
* rendering/RenderTable.h:
* rendering/RenderTableCaption.cpp:
(WebCore::RenderTableCaption::insertedIntoTree):
(WebCore::RenderTableCaption::willBeRemovedFromTree):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderTable.cpp
Source/WebCore/rendering/RenderTable.h
Source/WebCore/rendering/RenderTableCaption.cpp

index 74eded0..d539886 100644 (file)
@@ -1,3 +1,25 @@
+2017-10-06  Zalan Bujtas  <zalan@apple.com>
+
+        RenderTable should not hold a collection of raw pointers to RenderTableCaption
+        https://bugs.webkit.org/show_bug.cgi?id=178026
+        <rdar://problem/34863090>
+
+        Reviewed by Simon Fraser.
+
+        Similar to sections, RenderTable should not store captions as raw pointers. Their lifetimes are
+        not guaranteed to be sync with the RenderTable's.
+
+        Covered by existing tests.
+
+        * rendering/RenderTable.cpp:
+        (WebCore::RenderTable::addCaption):
+        (WebCore::RenderTable::removeCaption):
+        (WebCore::RenderTable::addOverflowFromChildren):
+        * rendering/RenderTable.h:
+        * rendering/RenderTableCaption.cpp:
+        (WebCore::RenderTableCaption::insertedIntoTree):
+        (WebCore::RenderTableCaption::willBeRemovedFromTree):
+
 2017-10-06  Daniel Bates  <dabates@apple.com>
 
         Spelling error annotation should encompass hyphen in misspelled word that wraps across multiple lines
index 6b63c4b..6237ab3 100644 (file)
@@ -218,15 +218,15 @@ void RenderTable::addChild(RenderPtr<RenderObject> child, RenderObject* beforeCh
     section.addChild(WTFMove(child));
 }
 
-void RenderTable::addCaption(const RenderTableCaption* caption)
+void RenderTable::addCaption(RenderTableCaption& caption)
 {
-    ASSERT(m_captions.find(caption) == notFound);
-    m_captions.append(const_cast<RenderTableCaption*>(caption));
+    ASSERT(m_captions.find(&caption) == notFound);
+    m_captions.append(makeWeakPtr(caption));
 }
 
-void RenderTable::removeCaption(const RenderTableCaption* oldCaption)
+void RenderTable::removeCaption(RenderTableCaption& oldCaption)
 {
-    bool removed = m_captions.removeFirst(oldCaption);
+    bool removed = m_captions.removeFirst(&oldCaption);
     ASSERT_UNUSED(removed, removed);
 }
 
@@ -686,7 +686,7 @@ void RenderTable::addOverflowFromChildren()
 
     // Add overflow from our caption.
     for (unsigned i = 0; i < m_captions.size(); i++) 
-        addOverflowFromChild(m_captions[i]);
+        addOverflowFromChild(m_captions[i].get());
 
     // Add overflow from our sections.
     for (RenderTableSection* section = topSection(); section; section = sectionBelow(section))
index 48c982d..c3f8b21 100644 (file)
@@ -256,8 +256,8 @@ public:
     const BorderValue& tableStartBorderAdjoiningCell(const RenderTableCell&) const;
     const BorderValue& tableEndBorderAdjoiningCell(const RenderTableCell&) const;
 
-    void addCaption(const RenderTableCaption*);
-    void removeCaption(const RenderTableCaption*);
+    void addCaption(RenderTableCaption&);
+    void removeCaption(RenderTableCaption&);
     void addColumn(const RenderTableCol*);
     void removeColumn(const RenderTableCol*);
 
@@ -325,7 +325,7 @@ private:
 
     mutable Vector<LayoutUnit> m_columnPos;
     mutable Vector<ColumnStruct> m_columns;
-    mutable Vector<RenderTableCaption*> m_captions;
+    mutable Vector<WeakPtr<RenderTableCaption>> m_captions;
     mutable Vector<WeakPtr<RenderTableCol>> m_columnRenderers;
 
     unsigned effectiveIndexOfColumn(const RenderTableCol&) const;
index 90961fe..a4c4549 100644 (file)
@@ -36,13 +36,13 @@ RenderTableCaption::~RenderTableCaption()
 void RenderTableCaption::insertedIntoTree()
 {
     RenderBlockFlow::insertedIntoTree();
-    table()->addCaption(this);
+    table()->addCaption(*this);
 }
 
 void RenderTableCaption::willBeRemovedFromTree()
 {
     RenderBlockFlow::willBeRemovedFromTree();
-    table()->removeCaption(this);
+    table()->removeCaption(*this);
 }
 
 RenderTable* RenderTableCaption::table() const