OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/dom/ScriptRunner.h" | 26 #include "core/dom/ScriptRunner.h" |
27 | 27 |
28 #include <algorithm> | |
28 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
29 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
30 #include "core/dom/ScriptLoader.h" | 31 #include "core/dom/ScriptLoader.h" |
31 #include "core/dom/TaskRunnerHelper.h" | 32 #include "core/dom/TaskRunnerHelper.h" |
32 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
33 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
34 #include "public/platform/WebScheduler.h" | 35 #include "public/platform/WebScheduler.h" |
35 #include "public/platform/WebThread.h" | 36 #include "public/platform/WebThread.h" |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFirst()); | 103 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFirst()); |
103 postTask(BLINK_FROM_HERE); | 104 postTask(BLINK_FROM_HERE); |
104 } | 105 } |
105 } | 106 } |
106 | 107 |
107 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, | 108 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, |
108 AsyncExecutionType executionType) { | 109 AsyncExecutionType executionType) { |
109 SECURITY_CHECK(scriptLoader); | 110 SECURITY_CHECK(scriptLoader); |
110 switch (executionType) { | 111 switch (executionType) { |
111 case Async: | 112 case Async: |
112 // RELEASE_ASSERT makes us crash in a controlled way in error cases | 113 // SECURITY_CHECK() makes us crash in a controlled way in error cases |
113 // where the ScriptLoader is associated with the wrong ScriptRunner | 114 // where the ScriptLoader is associated with the wrong ScriptRunner |
114 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | 115 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries |
115 // to detach). | 116 // to detach). |
116 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); | 117 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); |
117 | 118 |
118 m_pendingAsyncScripts.erase(scriptLoader); | 119 m_pendingAsyncScripts.erase(scriptLoader); |
119 m_asyncScriptsToExecuteSoon.append(scriptLoader); | 120 m_asyncScriptsToExecuteSoon.append(scriptLoader); |
120 | 121 |
121 postTask(BLINK_FROM_HERE); | 122 postTask(BLINK_FROM_HERE); |
122 | 123 |
123 break; | 124 break; |
124 | 125 |
125 case InOrder: | 126 case InOrder: |
126 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); | 127 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); |
127 m_numberOfInOrderScriptsWithPendingNotification--; | 128 m_numberOfInOrderScriptsWithPendingNotification--; |
128 | 129 |
129 scheduleReadyInOrderScripts(); | 130 scheduleReadyInOrderScripts(); |
130 | 131 |
131 break; | 132 break; |
132 case None: | 133 case None: |
133 NOTREACHED(); | 134 NOTREACHED(); |
134 break; | 135 break; |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) { | 139 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) { |
139 for (auto it = m_pendingInOrderScripts.begin(); | 140 auto it = std::find_if( |
hiroshige
2017/02/23 17:07:19
Lack of (Heap)Deque::find() looks causing similar
sof
2017/02/23 19:15:30
Simplified to std::find(), Member<T> does have an
| |
140 it != m_pendingInOrderScripts.end(); ++it) { | 141 m_pendingInOrderScripts.begin(), m_pendingInOrderScripts.end(), |
141 if (*it == scriptLoader) { | 142 [=](ScriptLoader* loader) { return loader == scriptLoader; }); |
142 m_pendingInOrderScripts.remove(it); | 143 if (it == m_pendingInOrderScripts.end()) |
143 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); | 144 return false; |
144 m_numberOfInOrderScriptsWithPendingNotification--; | 145 m_pendingInOrderScripts.remove(it); |
145 return true; | 146 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); |
146 } | 147 m_numberOfInOrderScriptsWithPendingNotification--; |
147 } | 148 return true; |
148 return false; | |
149 } | 149 } |
150 | 150 |
151 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, | 151 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, |
152 AsyncExecutionType executionType) { | 152 AsyncExecutionType executionType) { |
153 switch (executionType) { | 153 switch (executionType) { |
154 case Async: { | 154 case Async: { |
155 // SECURITY_CHECK makes us crash in a controlled way in error cases | 155 // See notifyScriptReady() comment. |
156 // where the ScriptLoader is associated with the wrong ScriptRunner | |
157 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | |
158 // to detach). | |
159 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); | 156 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); |
160 m_pendingAsyncScripts.erase(scriptLoader); | 157 m_pendingAsyncScripts.erase(scriptLoader); |
161 break; | 158 break; |
162 } | 159 } |
163 case InOrder: | 160 case InOrder: { |
164 SECURITY_CHECK(removePendingInOrderScript(scriptLoader)); | 161 SECURITY_CHECK(removePendingInOrderScript(scriptLoader)); |
165 scheduleReadyInOrderScripts(); | 162 scheduleReadyInOrderScripts(); |
166 break; | 163 break; |
167 case None: | 164 } |
165 case None: { | |
168 NOTREACHED(); | 166 NOTREACHED(); |
169 break; | 167 break; |
168 } | |
170 } | 169 } |
171 m_document->decrementLoadEventDelayCount(); | 170 m_document->decrementLoadEventDelayCount(); |
172 } | 171 } |
173 | 172 |
174 void ScriptRunner::movePendingScript(Document& oldDocument, | 173 void ScriptRunner::movePendingScript(Document& oldDocument, |
175 Document& newDocument, | 174 Document& newDocument, |
176 ScriptLoader* scriptLoader) { | 175 ScriptLoader* scriptLoader) { |
177 Document* newContextDocument = newDocument.contextDocument(); | 176 Document* newContextDocument = newDocument.contextDocument(); |
178 if (!newContextDocument) { | 177 if (!newContextDocument) { |
179 // Document's contextDocument() method will return no Document if the | 178 // Document's contextDocument() method will return no Document if the |
(...skipping 14 matching lines...) Expand all Loading... | |
194 DCHECK(!oldDocument.frame()); | 193 DCHECK(!oldDocument.frame()); |
195 oldContextDocument = &oldDocument; | 194 oldContextDocument = &oldDocument; |
196 } | 195 } |
197 if (oldContextDocument != newContextDocument) | 196 if (oldContextDocument != newContextDocument) |
198 oldContextDocument->scriptRunner()->movePendingScript( | 197 oldContextDocument->scriptRunner()->movePendingScript( |
199 newContextDocument->scriptRunner(), scriptLoader); | 198 newContextDocument->scriptRunner(), scriptLoader); |
200 } | 199 } |
201 | 200 |
202 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, | 201 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, |
203 ScriptLoader* scriptLoader) { | 202 ScriptLoader* scriptLoader) { |
204 if (m_pendingAsyncScripts.contains(scriptLoader)) { | 203 auto it = m_pendingAsyncScripts.find(scriptLoader); |
204 if (it != m_pendingAsyncScripts.end()) { | |
205 newRunner->queueScriptForExecution(scriptLoader, Async); | 205 newRunner->queueScriptForExecution(scriptLoader, Async); |
206 m_pendingAsyncScripts.erase(scriptLoader); | 206 m_pendingAsyncScripts.erase(it); |
207 m_document->decrementLoadEventDelayCount(); | 207 m_document->decrementLoadEventDelayCount(); |
208 return; | 208 return; |
209 } | 209 } |
210 if (removePendingInOrderScript(scriptLoader)) { | 210 if (removePendingInOrderScript(scriptLoader)) { |
211 newRunner->queueScriptForExecution(scriptLoader, InOrder); | 211 newRunner->queueScriptForExecution(scriptLoader, InOrder); |
212 m_document->decrementLoadEventDelayCount(); | 212 m_document->decrementLoadEventDelayCount(); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 // Returns true if task was run, and false otherwise. | 216 // Returns true if task was run, and false otherwise. |
(...skipping 25 matching lines...) Expand all Loading... | |
242 | 242 |
243 DEFINE_TRACE(ScriptRunner) { | 243 DEFINE_TRACE(ScriptRunner) { |
244 visitor->trace(m_document); | 244 visitor->trace(m_document); |
245 visitor->trace(m_pendingInOrderScripts); | 245 visitor->trace(m_pendingInOrderScripts); |
246 visitor->trace(m_pendingAsyncScripts); | 246 visitor->trace(m_pendingAsyncScripts); |
247 visitor->trace(m_asyncScriptsToExecuteSoon); | 247 visitor->trace(m_asyncScriptsToExecuteSoon); |
248 visitor->trace(m_inOrderScriptsToExecuteSoon); | 248 visitor->trace(m_inOrderScriptsToExecuteSoon); |
249 } | 249 } |
250 | 250 |
251 } // namespace blink | 251 } // namespace blink |
OLD | NEW |