Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp

Issue 1472823002: Couple V8AbstractEventListener's lifetime to the V8 listeners lifetime (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerGlobalScope.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
diff --git a/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp b/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
index 4a34b6afb5fd49820010066b6d7699389b0e0e21..adfe55ebe672167cf5caed5da39cf076d969115a 100644
--- a/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
@@ -32,6 +32,7 @@
#include "bindings/core/v8/ScheduledAction.h"
#include "bindings/core/v8/ScriptSourceCode.h"
#include "bindings/core/v8/ScriptValue.h"
+#include "bindings/core/v8/V8AbstractEventListener.h"
#include "bindings/core/v8/V8CacheOptions.h"
#include "core/dom/ActiveDOMObject.h"
#include "core/dom/AddConsoleMessageTask.h"
@@ -211,6 +212,14 @@ void WorkerGlobalScope::dispose()
// Event listeners would keep DOMWrapperWorld objects alive for too long. Also, they have references to JS objects,
// which become dangling once Heap is destroyed.
+ for (auto it = m_eventListeners.begin(); it != m_eventListeners.end(); ) {
+ RefPtrWillBeRawPtr<V8AbstractEventListener> listener = *it;
+ // clearListenerObject() will unregister the listener from
+ // m_eventListeners, and invalidate the iterator, so we have to advance
+ // it first.
+ ++it;
+ listener->clearListenerObject();
+ }
removeAllEventListeners();
clearScript();
@@ -324,6 +333,19 @@ WorkerEventQueue* WorkerGlobalScope::eventQueue() const
return m_eventQueue.get();
}
+void WorkerGlobalScope::registerEventListener(V8AbstractEventListener* eventListener)
+{
+ bool newEntry = m_eventListeners.add(eventListener).isNewEntry;
+ RELEASE_ASSERT(newEntry);
+}
+
+void WorkerGlobalScope::deregisterEventListener(V8AbstractEventListener* eventListener)
+{
+ auto it = m_eventListeners.find(eventListener);
+ RELEASE_ASSERT(it != m_eventListeners.end());
+ m_eventListeners.remove(it);
+}
+
void WorkerGlobalScope::countFeature(UseCounter::Feature) const
{
// FIXME: How should we count features for shared/service workers?
@@ -404,6 +426,7 @@ DEFINE_TRACE(WorkerGlobalScope)
visitor->trace(m_timers);
visitor->trace(m_messageStorage);
visitor->trace(m_pendingMessages);
+ visitor->trace(m_eventListeners);
HeapSupplementable<WorkerGlobalScope>::trace(visitor);
#endif
ExecutionContext::trace(visitor);
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerGlobalScope.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698