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

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

Issue 2609413002: Simplify WorkerGlobalScope::m_eventListeners. (Closed)
Patch Set: adjust deregister assert Created 3 years, 11 months 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 8f5f58086ddc2173907092df8160c9e4d507f74a..4455c27cc0e1530589e6781cea6b0f1526006234 100644
--- a/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
+++ b/third_party/WebKit/Source/core/workers/WorkerGlobalScope.cpp
@@ -91,13 +91,15 @@ 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();) {
- 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();
+ m_closing = true;
+ HeapHashSet<Member<V8AbstractEventListener>> listeners;
+ listeners.swap(m_eventListeners);
+ while (!listeners.isEmpty()) {
+ for (const auto& listener : listeners)
+ listener->clearListenerObject();
+ listeners.clear();
+ // Pick up any additions made while iterating.
+ listeners.swap(m_eventListeners);
}
removeAllEventListeners();
@@ -139,7 +141,7 @@ void WorkerGlobalScope::registerEventListener(
void WorkerGlobalScope::deregisterEventListener(
V8AbstractEventListener* eventListener) {
auto it = m_eventListeners.find(eventListener);
- CHECK(it != m_eventListeners.end());
+ CHECK(it != m_eventListeners.end() || m_closing);
m_eventListeners.remove(it);
}
« 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