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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/workers/WorkerGlobalScope.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Always use UTF-8 in Workers. 84 // Always use UTF-8 in Workers.
85 return KURL(m_url, url); 85 return KURL(m_url, url);
86 } 86 }
87 87
88 void WorkerGlobalScope::dispose() { 88 void WorkerGlobalScope::dispose() {
89 DCHECK(thread()->isCurrentThread()); 89 DCHECK(thread()->isCurrentThread());
90 90
91 // Event listeners would keep DOMWrapperWorld objects alive for too long. 91 // Event listeners would keep DOMWrapperWorld objects alive for too long.
92 // Also, they have references to JS objects, which become dangling once Heap 92 // Also, they have references to JS objects, which become dangling once Heap
93 // is destroyed. 93 // is destroyed.
94 for (auto it = m_eventListeners.begin(); it != m_eventListeners.end();) { 94 m_closing = true;
95 V8AbstractEventListener* listener = *it; 95 HeapHashSet<Member<V8AbstractEventListener>> listeners;
96 // clearListenerObject() will unregister the listener from 96 listeners.swap(m_eventListeners);
97 // m_eventListeners, and invalidate the iterator, so we have to advance 97 while (!listeners.isEmpty()) {
98 // it first. 98 for (const auto& listener : listeners)
99 ++it; 99 listener->clearListenerObject();
100 listener->clearListenerObject(); 100 listeners.clear();
101 // Pick up any additions made while iterating.
102 listeners.swap(m_eventListeners);
101 } 103 }
102 removeAllEventListeners(); 104 removeAllEventListeners();
103 105
104 m_scriptController->dispose(); 106 m_scriptController->dispose();
105 m_scriptController.clear(); 107 m_scriptController.clear();
106 m_eventQueue->close(); 108 m_eventQueue->close();
107 m_thread = nullptr; 109 m_thread = nullptr;
108 } 110 }
109 111
110 void WorkerGlobalScope::countFeature(UseCounter::Feature feature) { 112 void WorkerGlobalScope::countFeature(UseCounter::Feature feature) {
(...skipping 21 matching lines...) Expand all
132 V8AbstractEventListener* eventListener) { 134 V8AbstractEventListener* eventListener) {
133 // TODO(sof): remove once crbug.com/677654 has been diagnosed. 135 // TODO(sof): remove once crbug.com/677654 has been diagnosed.
134 CHECK(&ThreadState::fromObject(this)->heap() == &ThreadState::fromObject(event Listener)->heap()); 136 CHECK(&ThreadState::fromObject(this)->heap() == &ThreadState::fromObject(event Listener)->heap());
135 bool newEntry = m_eventListeners.add(eventListener).isNewEntry; 137 bool newEntry = m_eventListeners.add(eventListener).isNewEntry;
136 CHECK(newEntry); 138 CHECK(newEntry);
137 } 139 }
138 140
139 void WorkerGlobalScope::deregisterEventListener( 141 void WorkerGlobalScope::deregisterEventListener(
140 V8AbstractEventListener* eventListener) { 142 V8AbstractEventListener* eventListener) {
141 auto it = m_eventListeners.find(eventListener); 143 auto it = m_eventListeners.find(eventListener);
142 CHECK(it != m_eventListeners.end()); 144 CHECK(it != m_eventListeners.end() || m_closing);
143 m_eventListeners.remove(it); 145 m_eventListeners.remove(it);
144 } 146 }
145 147
146 WorkerLocation* WorkerGlobalScope::location() const { 148 WorkerLocation* WorkerGlobalScope::location() const {
147 if (!m_location) 149 if (!m_location)
148 m_location = WorkerLocation::create(m_url); 150 m_location = WorkerLocation::create(m_url);
149 return m_location.get(); 151 return m_location.get();
150 } 152 }
151 153
152 WorkerNavigator* WorkerGlobalScope::navigator() const { 154 WorkerNavigator* WorkerGlobalScope::navigator() const {
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 visitor->trace(m_timers); 378 visitor->trace(m_timers);
377 visitor->trace(m_eventListeners); 379 visitor->trace(m_eventListeners);
378 visitor->trace(m_pendingErrorEvents); 380 visitor->trace(m_pendingErrorEvents);
379 ExecutionContext::trace(visitor); 381 ExecutionContext::trace(visitor);
380 EventTargetWithInlineData::trace(visitor); 382 EventTargetWithInlineData::trace(visitor);
381 SecurityContext::trace(visitor); 383 SecurityContext::trace(visitor);
382 Supplementable<WorkerGlobalScope>::trace(visitor); 384 Supplementable<WorkerGlobalScope>::trace(visitor);
383 } 385 }
384 386
385 } // namespace blink 387 } // namespace blink
OLDNEW
« 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