Manage MutationObserverInterestGroup through std::unique_ptr
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Feb 2014 08:33:19 +0000 (08:33 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Feb 2014 08:33:19 +0000 (08:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=128468

Reviewed by Andreas Kling.

Use std::unique_ptr instead of OwnPtr for managing MutationObserverInterestGroup objects.

* css/PropertySetCSSStyleDeclaration.cpp:
* dom/CharacterData.cpp:
(WebCore::CharacterData::dispatchModifiedEvent):
* dom/ChildListMutationScope.cpp:
(WebCore::ChildListMutationAccumulator::ChildListMutationAccumulator):
* dom/ChildListMutationScope.h:
(WebCore::ChildListMutationAccumulator::hasObservers):
* dom/Element.cpp:
(WebCore::Element::willModifyAttribute):
* dom/MutationObserverInterestGroup.cpp:
(WebCore::MutationObserverInterestGroup::createIfNeeded):
* dom/MutationObserverInterestGroup.h:
(WebCore::MutationObserverInterestGroup::createForChildListMutation):
(WebCore::MutationObserverInterestGroup::createForCharacterDataMutation):
(WebCore::MutationObserverInterestGroup::createForAttributesMutation):

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

Source/WebCore/ChangeLog
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/dom/CharacterData.cpp
Source/WebCore/dom/ChildListMutationScope.cpp
Source/WebCore/dom/ChildListMutationScope.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/MutationObserverInterestGroup.cpp
Source/WebCore/dom/MutationObserverInterestGroup.h

index 948a1f7..b7e4f26 100644 (file)
@@ -1,5 +1,30 @@
 2014-02-09  Zan Dobersek  <zdobersek@igalia.com>
 
+        Manage MutationObserverInterestGroup through std::unique_ptr
+        https://bugs.webkit.org/show_bug.cgi?id=128468
+
+        Reviewed by Andreas Kling.
+
+        Use std::unique_ptr instead of OwnPtr for managing MutationObserverInterestGroup objects.
+
+        * css/PropertySetCSSStyleDeclaration.cpp:
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::dispatchModifiedEvent):
+        * dom/ChildListMutationScope.cpp:
+        (WebCore::ChildListMutationAccumulator::ChildListMutationAccumulator):
+        * dom/ChildListMutationScope.h:
+        (WebCore::ChildListMutationAccumulator::hasObservers):
+        * dom/Element.cpp:
+        (WebCore::Element::willModifyAttribute):
+        * dom/MutationObserverInterestGroup.cpp:
+        (WebCore::MutationObserverInterestGroup::createIfNeeded):
+        * dom/MutationObserverInterestGroup.h:
+        (WebCore::MutationObserverInterestGroup::createForChildListMutation):
+        (WebCore::MutationObserverInterestGroup::createForCharacterDataMutation):
+        (WebCore::MutationObserverInterestGroup::createForAttributesMutation):
+
+2014-02-09  Zan Dobersek  <zdobersek@igalia.com>
+
         Manage MessagePort, MessagePortChannel and friends through std::unique_ptr
         https://bugs.webkit.org/show_bug.cgi?id=128467
 
index 5be9c97..265d393 100644 (file)
@@ -107,7 +107,7 @@ private:
     static bool s_shouldNotifyInspector;
     static bool s_shouldDeliver;
 
-    OwnPtr<MutationObserverInterestGroup> m_mutationRecipients;
+    std::unique_ptr<MutationObserverInterestGroup> m_mutationRecipients;
     RefPtr<MutationRecord> m_mutation;
 };
 
index 7ac273f..31f0d5f 100644 (file)
@@ -210,7 +210,7 @@ void CharacterData::setDataAndUpdate(const String& newData, unsigned offsetOfRep
 
 void CharacterData::dispatchModifiedEvent(const String& oldData)
 {
-    if (OwnPtr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForCharacterDataMutation(*this))
+    if (std::unique_ptr<MutationObserverInterestGroup> mutationRecipients = MutationObserverInterestGroup::createForCharacterDataMutation(*this))
         mutationRecipients->enqueueMutationRecord(MutationRecord::createCharacterData(*this, oldData));
 
     if (!isInShadowTree()) {
index 2c50716..d8c202c 100644 (file)
@@ -47,10 +47,10 @@ static AccumulatorMap& accumulatorMap()
     return map;
 }
 
-ChildListMutationAccumulator::ChildListMutationAccumulator(ContainerNode& target, PassOwnPtr<MutationObserverInterestGroup> observers)
+ChildListMutationAccumulator::ChildListMutationAccumulator(ContainerNode& target, std::unique_ptr<MutationObserverInterestGroup> observers)
     : m_target(target)
-    , m_lastAdded(0)
-    , m_observers(observers)
+    , m_lastAdded(nullptr)
+    , m_observers(std::move(observers))
 {
 }
 
index a179f59..db5c76e 100644 (file)
@@ -34,9 +34,9 @@
 #include "Document.h"
 #include "MutationObserver.h"
 #include "Node.h"
+#include <memory>
 #include <wtf/HashMap.h>
 #include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
@@ -52,10 +52,10 @@ public:
     void childAdded(Node&);
     void willRemoveChild(Node&);
 
-    bool hasObservers() const { return m_observers; }
+    bool hasObservers() const { return !!m_observers; }
 
 private:
-    ChildListMutationAccumulator(ContainerNode&, PassOwnPtr<MutationObserverInterestGroup>);
+    ChildListMutationAccumulator(ContainerNode&, std::unique_ptr<MutationObserverInterestGroup>);
 
     void enqueueMutationRecord();
     bool isEmpty();
@@ -70,7 +70,7 @@ private:
     RefPtr<Node> m_nextSibling;
     Node* m_lastAdded;
 
-    OwnPtr<MutationObserverInterestGroup> m_observers;
+    std::unique_ptr<MutationObserverInterestGroup> m_observers;
 };
 
 class ChildListMutationScope {
index 5333447..a63e3b1 100644 (file)
@@ -2794,7 +2794,7 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
             setNeedsStyleRecalc();
     }
 
-    if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(*this, name))
+    if (std::unique_ptr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(*this, name))
         recipients->enqueueMutationRecord(MutationRecord::createAttributes(*this, name, oldValue));
 
 #if ENABLE(INSPECTOR)
index c28d2bd..8611ef3 100644 (file)
@@ -37,7 +37,7 @@
 
 namespace WebCore {
 
-PassOwnPtr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
+std::unique_ptr<MutationObserverInterestGroup> MutationObserverInterestGroup::createIfNeeded(Node& target, MutationObserver::MutationType type, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName)
 {
     ASSERT((type == MutationObserver::Attributes && attributeName) || !attributeName);
     HashMap<MutationObserver*, MutationRecordDeliveryOptions> observers;
@@ -45,7 +45,7 @@ PassOwnPtr<MutationObserverInterestGroup> MutationObserverInterestGroup::createI
     if (observers.isEmpty())
         return nullptr;
 
-    return adoptPtr(new MutationObserverInterestGroup(observers, oldValueFlag));
+    return std::make_unique<MutationObserverInterestGroup>(observers, oldValueFlag);
 }
 
 MutationObserverInterestGroup::MutationObserverInterestGroup(HashMap<MutationObserver*, MutationRecordDeliveryOptions>& observers, MutationRecordDeliveryOptions oldValueFlag)
index 84cef99..8e8181f 100644 (file)
 #include "Document.h"
 #include "MutationObserver.h"
 #include "QualifiedName.h"
+#include <memory>
 #include <wtf/HashMap.h>
-#include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
 
 class MutationObserverInterestGroup {
 public:
-    static PassOwnPtr<MutationObserverInterestGroup> createForChildListMutation(Node& target)
+    MutationObserverInterestGroup(HashMap<MutationObserver*, MutationRecordDeliveryOptions>& observers, MutationRecordDeliveryOptions oldValueFlag);
+
+    static std::unique_ptr<MutationObserverInterestGroup> createForChildListMutation(Node& target)
     {
         if (!target.document().hasMutationObserversOfType(MutationObserver::ChildList))
             return nullptr;
@@ -50,7 +52,7 @@ public:
         return createIfNeeded(target, MutationObserver::ChildList, oldValueFlag);
     }
 
-    static PassOwnPtr<MutationObserverInterestGroup> createForCharacterDataMutation(Node& target)
+    static std::unique_ptr<MutationObserverInterestGroup> createForCharacterDataMutation(Node& target)
     {
         if (!target.document().hasMutationObserversOfType(MutationObserver::CharacterData))
             return nullptr;
@@ -58,7 +60,7 @@ public:
         return createIfNeeded(target, MutationObserver::CharacterData, MutationObserver::CharacterDataOldValue);
     }
 
-    static PassOwnPtr<MutationObserverInterestGroup> createForAttributesMutation(Node& target, const QualifiedName& attributeName)
+    static std::unique_ptr<MutationObserverInterestGroup> createForAttributesMutation(Node& target, const QualifiedName& attributeName)
     {
         if (!target.document().hasMutationObserversOfType(MutationObserver::Attributes))
             return nullptr;
@@ -70,8 +72,7 @@ public:
     void enqueueMutationRecord(PassRefPtr<MutationRecord>);
 
 private:
-    static PassOwnPtr<MutationObserverInterestGroup> createIfNeeded(Node& target, MutationObserver::MutationType, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName = 0);
-    MutationObserverInterestGroup(HashMap<MutationObserver*, MutationRecordDeliveryOptions>& observers, MutationRecordDeliveryOptions oldValueFlag);
+    static std::unique_ptr<MutationObserverInterestGroup> createIfNeeded(Node& target, MutationObserver::MutationType, MutationRecordDeliveryOptions oldValueFlag, const QualifiedName* attributeName = nullptr);
 
     bool hasOldValue(MutationRecordDeliveryOptions options) { return options & m_oldValueFlag; }