2009-04-03 Jian Li <jianli@chromium.org>
authordimich@chromium.org <dimich@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2009 22:24:39 +0000 (22:24 +0000)
committerdimich@chromium.org <dimich@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2009 22:24:39 +0000 (22:24 +0000)
        Reviewed by Darin Fisher.

        https://bugs.webkit.org/show_bug.cgi?id=25009
        Upstream changes to WorkerContextExecutionProxy for V8 bindings in order to use V8EventListenerList as container.

        * bindings/v8/WorkerContextExecutionProxy.cpp:
        (WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy):
        (WebCore::WorkerContextExecutionProxy::dispose):
        (WebCore::WorkerContextExecutionProxy::FindOrCreateEventListener):
        (WebCore::WorkerContextExecutionProxy::RemoveEventListener):
        * bindings/v8/WorkerContextExecutionProxy.h:

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

WebCore/ChangeLog
WebCore/bindings/v8/WorkerContextExecutionProxy.cpp
WebCore/bindings/v8/WorkerContextExecutionProxy.h

index cf9cdf5..3ef4011 100644 (file)
@@ -1,3 +1,17 @@
+2009-04-03  Jian Li  <jianli@chromium.org>
+
+        Reviewed by Darin Fisher.
+
+        https://bugs.webkit.org/show_bug.cgi?id=25009
+        Upstream changes to WorkerContextExecutionProxy for V8 bindings in order to use V8EventListenerList as container.
+
+        * bindings/v8/WorkerContextExecutionProxy.cpp:
+        (WebCore::WorkerContextExecutionProxy::WorkerContextExecutionProxy):
+        (WebCore::WorkerContextExecutionProxy::dispose):
+        (WebCore::WorkerContextExecutionProxy::FindOrCreateEventListener):
+        (WebCore::WorkerContextExecutionProxy::RemoveEventListener):
+        * bindings/v8/WorkerContextExecutionProxy.h:
+
 2009-04-03  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Sam Weinig.
index a46aa24..ab2e00c 100644 (file)
@@ -62,6 +62,9 @@ WorkerContextExecutionProxy::WorkerContextExecutionProxy(WorkerContext* workerCo
     : m_workerContext(workerContext)
     , m_recursion(0)
 {
+    // Need to use lock since V8EventListenerList constructor creates HandleScope.
+    v8::Locker locker;
+    m_listeners.set(new V8EventListenerList("m_listeners"));
 }
 
 WorkerContextExecutionProxy::~WorkerContextExecutionProxy()
@@ -72,10 +75,14 @@ WorkerContextExecutionProxy::~WorkerContextExecutionProxy()
 void WorkerContextExecutionProxy::dispose()
 {
     // Disconnect all event listeners.
-    for (size_t listenerIndex = 0; listenerIndex < m_listeners.size(); ++listenerIndex)
-       m_listeners[listenerIndex]->disconnect();
+    for (V8EventListenerList::iterator iterator(m_listeners->begin()); iterator != m_listeners->end(); ++iterator)
+       static_cast<V8WorkerContextEventListener*>(*iterator)->disconnect();
 
-    m_listeners.clear();
+    {
+        // Need to use lock since V8EventListenerList::clear() creates HandleScope.
+        v8::Locker locker;
+        m_listeners->clear();
+    }
 
     // Detach all events from their JS wrappers.
     for (size_t eventIndex = 0; eventIndex < m_events.size(); ++eventIndex) {
@@ -324,29 +331,26 @@ PassRefPtr<V8EventListener> WorkerContextExecutionProxy::FindOrCreateEventListen
     if (!object->IsObject())
         return 0;
 
-    for (size_t index = 0; index < m_listeners.size(); ++index) {
-        V8EventListener* el = m_listeners[index];
-        if (el->isInline() == isInline && el->getListenerObject() == object)
-            return el;
-    }
+    V8EventListener* listener = m_listeners->find(object->ToObject(), isInline);
     if (findOnly)
-        return NULL;
+        return listener;
 
     // Create a new one, and add to cache.
-    RefPtr<V8WorkerContextEventListener> listener = V8WorkerContextEventListener::create(this, v8::Local<v8::Object>::Cast(object), isInline);
-    m_listeners.append(listener.get());
+    RefPtr<V8WorkerContextEventListener> newListener = V8WorkerContextEventListener::create(this, v8::Local<v8::Object>::Cast(object), isInline);
+    {
+        // Need to use lock since V8EventListenerList::add() creates HandleScope.
+        v8::Locker locker;
+        m_listeners->add(newListener.get());
+    }
 
-    return listener.release();
+    return newListener.release();
 }
 
 void WorkerContextExecutionProxy::RemoveEventListener(V8EventListener* listener)
 {
-    for (size_t index = 0; index < m_listeners.size(); ++index) {
-        if (m_listeners[index] == listener) {
-            m_listeners.remove(index);
-            return;
-        }
-    }
+    // Need to use lock since V8EventListenerList::remove() creates HandleScope.
+    v8::Locker locker;
+    m_listeners->remove(listener);
 }
 
 void WorkerContextExecutionProxy::trackEvent(Event* event)
index 3023666..70f9fc5 100644 (file)
@@ -35,7 +35,9 @@
 #if ENABLE(WORKERS)
 
 #include <v8.h>
+#include "V8EventListenerList.h"
 #include "V8Index.h"
+#include <wtf/OwnPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
@@ -95,7 +97,7 @@ namespace WebCore {
         v8::Persistent<v8::Context> m_context;
         int m_recursion;
 
-        Vector<V8WorkerContextEventListener*> m_listeners;
+        OwnPtr<V8EventListenerList> m_listeners;
         Vector<Event*> m_events;
     };