2006-06-01 Anders Carlsson <acarlsson@apple.com>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jun 2006 19:06:09 +0000 (19:06 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Jun 2006 19:06:09 +0000 (19:06 +0000)
        Reviewed by Maciej.

        http://bugzilla.opendarwin.org/show_bug.cgi?id=9212
        dispatchEvent13.html crashes under GuardMalloc

        * dom/EventTargetNode.cpp:
        (WebCore::EventTargetNode::addEventListener):
        (WebCore::EventTargetNode::removeEventListener):
        (WebCore::EventTargetNode::handleLocalEvents):

        (WebCore::EventTargetNode::removeHTMLEventListener):
        (WebCore::EventTargetNode::getHTMLEventListener):
        * dom/EventTargetNode.h:
        Make the list of registered event listeners refcount the listeners
        by using a value list of RefPtr objects.

        Set removed flag to true in removeEventListener
        Only invoke event listeners if they don't have the removed flag.

        * dom/dom2_eventsimpl.cpp:
        (WebCore::RegisteredEventListener::RegisteredEventListener):
        * dom/dom2_eventsimpl.h:
        Make RegisteredEventListener refcounted.

        (WebCore::RegisteredEventListener::removed):
        (WebCore::RegisteredEventListener::setRemoved):
        Add removed flag and getter and setter

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

WebCore/ChangeLog
WebCore/dom/EventTargetNode.cpp
WebCore/dom/EventTargetNode.h
WebCore/dom/dom2_eventsimpl.cpp
WebCore/dom/dom2_eventsimpl.h

index 59a3a0adc6088c8b37edec2ebdf83b997ab86c78..4f35bacdb9ddb04bc082c4a9af318068fa621a6d 100644 (file)
@@ -1,3 +1,33 @@
+2006-06-01  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Maciej.
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9212
+        dispatchEvent13.html crashes under GuardMalloc
+
+        * dom/EventTargetNode.cpp:
+        (WebCore::EventTargetNode::addEventListener):
+        (WebCore::EventTargetNode::removeEventListener):        
+        (WebCore::EventTargetNode::handleLocalEvents):
+        
+        (WebCore::EventTargetNode::removeHTMLEventListener):
+        (WebCore::EventTargetNode::getHTMLEventListener):
+        * dom/EventTargetNode.h:
+        Make the list of registered event listeners refcount the listeners
+        by using a value list of RefPtr objects.
+        
+        Set removed flag to true in removeEventListener
+        Only invoke event listeners if they don't have the removed flag.
+        
+        * dom/dom2_eventsimpl.cpp:
+        (WebCore::RegisteredEventListener::RegisteredEventListener):
+        * dom/dom2_eventsimpl.h:
+        Make RegisteredEventListener refcounted.
+        
+        (WebCore::RegisteredEventListener::removed):
+        (WebCore::RegisteredEventListener::setRemoved):
+        Add removed flag and getter and setter
+
 2006-06-01  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by harrison
index fe831f1428f7520960261467266a30a03af377e3..9fecfe28eb14b64e0ce8535146411cded097d6df 100644 (file)
@@ -99,10 +99,8 @@ void EventTargetNode::addEventListener(const AtomicString &eventType, PassRefPtr
     if (type)
         document()->addListenerType(type);
     
-    if (!m_regdListeners) {
-        m_regdListeners = new DeprecatedPtrList<RegisteredEventListener>;
-        m_regdListeners->setAutoDelete(true);
-    }
+    if (!m_regdListeners)
+        m_regdListeners = new RegisteredEventListenerList;
     
     // Remove existing identical listener set with identical arguments.
     // The DOM2 spec says that "duplicate instances are discarded" in this case.
@@ -122,10 +120,12 @@ void EventTargetNode::removeEventListener(const AtomicString &eventType, EventLi
     
     RegisteredEventListener rl(eventType, listener, useCapture);
     
-    DeprecatedPtrListIterator<RegisteredEventListener> it(*m_regdListeners);
-    for (; it.current(); ++it)
-        if (*(it.current()) == rl) {
-            m_regdListeners->removeRef(it.current());
+    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
+    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it)
+        if (*(*it).get() == rl) {
+            (*it)->setRemoved(true);
+            
+            it = m_regdListeners->remove(it);
             // removed last
             if (m_regdListeners->isEmpty() && !inDocument())
                 document()->unregisterDisconnectedNodeWithEventListeners(this);
@@ -147,11 +147,12 @@ void EventTargetNode::handleLocalEvents(Event *evt, bool useCapture)
     if (disabled() && evt->isMouseEvent())
         return;
     
-    DeprecatedPtrList<RegisteredEventListener> listenersCopy = *m_regdListeners;
-    DeprecatedPtrListIterator<RegisteredEventListener> it(listenersCopy);
-    for (; it.current(); ++it)
-        if (it.current()->eventType() == evt->type() && it.current()->useCapture() == useCapture)
-            it.current()->listener()->handleEvent(evt, false);
+    RegisteredEventListenerList listenersCopy = *m_regdListeners;
+    RegisteredEventListenerList::Iterator end = listenersCopy.end();    
+    
+    for (RegisteredEventListenerList::Iterator it = listenersCopy.begin(); it != end; ++it)
+        if ((*it)->eventType() == evt->type() && (*it)->useCapture() == useCapture && !(*it)->removed())
+            (*it)->listener()->handleEvent(evt, false);
 }
 
 bool EventTargetNode::dispatchGenericEvent(PassRefPtr<Event> e, ExceptionCode&, bool tempEvent)
@@ -475,10 +476,10 @@ void EventTargetNode::removeHTMLEventListener(const AtomicString &eventType)
     if (!m_regdListeners) // nothing to remove
         return;
     
-    DeprecatedPtrListIterator<RegisteredEventListener> it(*m_regdListeners);
-    for (; it.current(); ++it)
-        if (it.current()->eventType() == eventType && it.current()->listener()->isHTMLEventListener()) {
-            m_regdListeners->removeRef(it.current());
+    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
+    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it)
+        if ((*it)->eventType() == eventType && (*it)->listener()->isHTMLEventListener()) {
+            it = m_regdListeners->remove(it);
             // removed last
             if (m_regdListeners->isEmpty() && !inDocument())
                 document()->unregisterDisconnectedNodeWithEventListeners(this);
@@ -499,10 +500,10 @@ EventListener *EventTargetNode::getHTMLEventListener(const AtomicString &eventTy
     if (!m_regdListeners)
         return 0;
     
-    DeprecatedPtrListIterator<RegisteredEventListener> it(*m_regdListeners);
-    for (; it.current(); ++it)
-        if (it.current()->eventType() == eventType && it.current()->listener()->isHTMLEventListener())
-            return it.current()->listener();
+    RegisteredEventListenerList::Iterator end = m_regdListeners->end();
+    for (RegisteredEventListenerList::Iterator it = m_regdListeners->begin(); it != end; ++it)
+        if ((*it)->eventType() == eventType && (*it)->listener()->isHTMLEventListener())
+            return (*it)->listener();
     return 0;
 }
 
index 7e49e74047fdd16ac96d9562868fa5ad4b5a430c..affb13b9c65a057e5e434884c23e08db7fc74ffc 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "Node.h"
 
-template <typename T> class DeprecatedPtrList;
+template <typename T> class DeprecatedValueList;
 
 namespace WebCore {
 
@@ -92,7 +92,8 @@ public:
 #endif
 
 protected:
-    DeprecatedPtrList<RegisteredEventListener>* m_regdListeners;
+    typedef DeprecatedValueList<RefPtr<RegisteredEventListener> > RegisteredEventListenerList;
+    RegisteredEventListenerList* m_regdListeners;
 };
 
 inline EventTargetNode* EventTargetNodeCast(Node* n) 
index d85a46372360bda479e09d21b9569285c1857cb7..eeebd250574b9177376d53dc9752f3c7b557351c 100644 (file)
@@ -616,7 +616,10 @@ bool WheelEvent::isWheelEvent() const
 // -----------------------------------------------------------------------------
 
 RegisteredEventListener::RegisteredEventListener(const AtomicString &eventType, PassRefPtr<EventListener> listener, bool useCapture)
-    : m_eventType(eventType), m_listener(listener), m_useCapture(useCapture)
+    : m_eventType(eventType)
+    , m_listener(listener)
+    , m_useCapture(useCapture)
+    , m_removed(false)
 {
 }
 
index b12b83b1c165125f2eb860c524260baaec3d8d01..09ca9b61c2411a1daabe511475907c11941d241b 100644 (file)
@@ -412,18 +412,21 @@ private:
     int m_wheelDelta;
 };
 
-class RegisteredEventListener {
+class RegisteredEventListener : public Shared<RegisteredEventListener> {
 public:
     RegisteredEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture);
 
     const AtomicString &eventType() const { return m_eventType; }
     EventListener *listener() const { return m_listener.get(); }
     bool useCapture() const { return m_useCapture; }
-
+    bool removed() const { return m_removed; }
+    void setRemoved(bool removed) { m_removed = removed; }
+    
 private:
     AtomicString m_eventType;
     RefPtr<EventListener> m_listener;
     bool m_useCapture;
+    bool m_removed;
 };
 
 bool operator==(const RegisteredEventListener&, const RegisteredEventListener&);