RenderMenuList should not hold raw pointers
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2017 22:39:49 +0000 (22:39 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2017 22:39:49 +0000 (22:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177836

Reviewed by Antti Koivisto.

While both m_buttonText and m_innerBlock are child renderers of
the RenderMenuList, so the their lifecycles are supposed to tied
to the parent object, this patch removes some manual raw pointer managing.

Covered by existing tests.

* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::RenderMenuList):
(WebCore::RenderMenuList::createInnerBlock):
(RenderMenuList::takeChild):
(RenderMenuList::setText):
* rendering/RenderMenuList.h:

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderMenuList.cpp
Source/WebCore/rendering/RenderMenuList.h

index 760cd7d..be6ec0a 100644 (file)
@@ -1,3 +1,23 @@
+2017-10-03  Zalan Bujtas  <zalan@apple.com>
+
+        RenderMenuList should not hold raw pointers
+        https://bugs.webkit.org/show_bug.cgi?id=177836
+
+        Reviewed by Antti Koivisto.
+
+        While both m_buttonText and m_innerBlock are child renderers of
+        the RenderMenuList, so the their lifecycles are supposed to tied
+        to the parent object, this patch removes some manual raw pointer managing.
+
+        Covered by existing tests.
+
+        * rendering/RenderMenuList.cpp:
+        (WebCore::RenderMenuList::RenderMenuList):
+        (WebCore::RenderMenuList::createInnerBlock):
+        (RenderMenuList::takeChild):
+        (RenderMenuList::setText):
+        * rendering/RenderMenuList.h:
+
 2017-10-03  Timothy Horton  <timothy_horton@apple.com>
 
         Include a few widespread WTF headers in WebCorePrefix.h
index d0ad610..da4607f 100644 (file)
@@ -71,8 +71,6 @@ static size_t selectedOptionCount(const RenderMenuList& renderMenuList)
 
 RenderMenuList::RenderMenuList(HTMLSelectElement& element, RenderStyle&& style)
     : RenderFlexibleBox(element, WTFMove(style))
-    , m_buttonText(nullptr)
-    , m_innerBlock(nullptr)
     , m_needsOptionsWidthUpdate(true)
     , m_optionsWidth(0)
 #if !PLATFORM(IOS)
@@ -108,7 +106,7 @@ void RenderMenuList::createInnerBlock()
     // Create an anonymous block.
     ASSERT(!firstChild());
     auto newInnerBlock = createAnonymousBlock();
-    m_innerBlock = newInnerBlock.get();
+    m_innerBlock = makeWeakPtr(*newInnerBlock.get());
     adjustInnerStyle();
     RenderFlexibleBox::addChild(WTFMove(newInnerBlock));
 }
@@ -185,10 +183,8 @@ void RenderMenuList::addChild(RenderPtr<RenderObject> newChild, RenderObject* be
 
 RenderPtr<RenderObject> RenderMenuList::takeChild(RenderObject& oldChild)
 {
-    if (&oldChild == m_innerBlock || !m_innerBlock) {
-        m_innerBlock = 0;
+    if (!m_innerBlock || &oldChild == m_innerBlock)
         return RenderFlexibleBox::takeChild(oldChild);
-    }
     return m_innerBlock->takeChild(oldChild);
 }
 
@@ -297,7 +293,7 @@ void RenderMenuList::setText(const String& s)
         m_buttonText->setText(textToUse.impl(), true);
     else {
         auto newButtonText = createRenderer<RenderText>(document(), textToUse);
-        m_buttonText = newButtonText.get();
+        m_buttonText = makeWeakPtr(*newButtonText);
         addChild(WTFMove(newButtonText));
     }
 
index fa5a618..ef4333f 100644 (file)
@@ -137,8 +137,8 @@ private:
 
     bool isFlexibleBoxImpl() const override { return true; }
 
-    RenderText* m_buttonText;
-    RenderBlock* m_innerBlock;
+    WeakPtr<RenderText> m_buttonText;
+    WeakPtr<RenderBlock> m_innerBlock;
 
     bool m_needsOptionsWidthUpdate;
     int m_optionsWidth;