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 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 { | 149 { |
150 // Verify that detach() has been called. | 150 // Verify that detach() has been called. |
151 ASSERT(!m_document); | 151 ASSERT(!m_document); |
152 } | 152 } |
153 | 153 |
154 void HTMLScriptRunner::detach() | 154 void HTMLScriptRunner::detach() |
155 { | 155 { |
156 if (!m_document) | 156 if (!m_document) |
157 return; | 157 return; |
158 | 158 |
159 m_parserBlockingScript->stopWatchingForLoad(this); | 159 m_parserBlockingScript->stopWatchingForLoad(); |
160 m_parserBlockingScript->releaseElementAndClear(); | 160 m_parserBlockingScript->releaseElementAndClear(); |
161 | 161 |
162 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 162 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
163 OwnPtrWillBeRawPtr<PendingScript> pendingScript = m_scriptsToExecuteAfte
rParsing.takeFirst(); | 163 OwnPtrWillBeRawPtr<PendingScript> pendingScript = m_scriptsToExecuteAfte
rParsing.takeFirst(); |
164 pendingScript->stopWatchingForLoad(this); | 164 pendingScript->stopWatchingForLoad(); |
165 pendingScript->releaseElementAndClear(); | 165 pendingScript->releaseElementAndClear(); |
166 } | 166 } |
167 m_document = nullptr; | 167 m_document = nullptr; |
168 } | 168 } |
169 | 169 |
170 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) | 170 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) |
171 { | 171 { |
172 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); | 172 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); |
173 if (m_hasScriptsWaitingForResources) | 173 if (m_hasScriptsWaitingForResources) |
174 return false; | 174 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
186 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), ScriptStr
eamer::ParsingBlocking); | 186 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), ScriptStr
eamer::ParsingBlocking); |
187 } | 187 } |
188 | 188 |
189 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript* pendi
ngScript, ScriptStreamer::Type pendingScriptType) | 189 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript* pendi
ngScript, ScriptStreamer::Type pendingScriptType) |
190 { | 190 { |
191 bool errorOccurred = false; | 191 bool errorOccurred = false; |
192 double loadFinishTime = pendingScript->resource() && pendingScript->resource
()->url().protocolIsInHTTPFamily() ? pendingScript->resource()->loadFinishTime()
: 0; | 192 double loadFinishTime = pendingScript->resource() && pendingScript->resource
()->url().protocolIsInHTTPFamily() ? pendingScript->resource()->loadFinishTime()
: 0; |
193 ScriptSourceCode sourceCode = pendingScript->getSource(documentURLForScriptE
xecution(m_document), errorOccurred); | 193 ScriptSourceCode sourceCode = pendingScript->getSource(documentURLForScriptE
xecution(m_document), errorOccurred); |
194 | 194 |
195 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. | 195 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. |
196 pendingScript->stopWatchingForLoad(this); | 196 pendingScript->stopWatchingForLoad(); |
197 | 197 |
198 if (!isExecutingScript()) { | 198 if (!isExecutingScript()) { |
199 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); | 199 Microtask::performCheckpoint(V8PerIsolateData::mainThreadIsolate()); |
200 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { | 200 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { |
201 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); | 201 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); |
202 // The parser cannot be unblocked as a microtask requested another r
esource | 202 // The parser cannot be unblocked as a microtask requested another r
esource |
203 if (m_hasScriptsWaitingForResources) | 203 if (m_hasScriptsWaitingForResources) |
204 return; | 204 return; |
205 } | 205 } |
206 } | 206 } |
(...skipping 25 matching lines...) Expand all Loading... |
232 DEFINE_STATIC_LOCAL(CustomCountHistogram, loadAndCompileHistogram, ("Web
Core.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled", 0, 10000, 50)); | 232 DEFINE_STATIC_LOCAL(CustomCountHistogram, loadAndCompileHistogram, ("Web
Core.Scripts.ParsingBlocking.TimeBetweenLoadedAndCompiled", 0, 10000, 50)); |
233 loadAndCompileHistogram.count(duration); | 233 loadAndCompileHistogram.count(duration); |
234 } | 234 } |
235 | 235 |
236 ASSERT(!isExecutingScript()); | 236 ASSERT(!isExecutingScript()); |
237 } | 237 } |
238 | 238 |
239 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) | 239 void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) |
240 { | 240 { |
241 if (m_parserBlockingScript->resource() == resource) { | 241 if (m_parserBlockingScript->resource() == resource) { |
242 m_parserBlockingScript->stopWatchingForLoad(this); | 242 m_parserBlockingScript->stopWatchingForLoad(); |
243 m_parserBlockingScript->releaseElementAndClear(); | 243 m_parserBlockingScript->releaseElementAndClear(); |
244 return; | 244 return; |
245 } | 245 } |
246 for (auto& script : m_scriptsToExecuteAfterParsing) { | 246 for (auto& script : m_scriptsToExecuteAfterParsing) { |
247 if (script->resource() == resource) { | 247 if (script->resource() == resource) { |
248 script->stopWatchingForLoad(this); | 248 script->stopWatchingForLoad(); |
249 script->releaseElementAndClear(); | 249 script->releaseElementAndClear(); |
250 return; | 250 return; |
251 } | 251 } |
252 } | 252 } |
253 } | 253 } |
254 | 254 |
255 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 255 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
256 { | 256 { |
257 // Handle cancellations of parser-blocking script loads without | 257 // Handle cancellations of parser-blocking script loads without |
258 // notifying the host (i.e., parser) if these were initiated by nested | 258 // notifying the host (i.e., parser) if these were initiated by nested |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 383 |
384 ASSERT(pendingScript->resource()); | 384 ASSERT(pendingScript->resource()); |
385 m_scriptsToExecuteAfterParsing.append(pendingScript.release()); | 385 m_scriptsToExecuteAfterParsing.append(pendingScript.release()); |
386 } | 386 } |
387 | 387 |
388 bool HTMLScriptRunner::requestPendingScript(PendingScript* pendingScript, Elemen
t* script) const | 388 bool HTMLScriptRunner::requestPendingScript(PendingScript* pendingScript, Elemen
t* script) const |
389 { | 389 { |
390 ASSERT(!pendingScript->element()); | 390 ASSERT(!pendingScript->element()); |
391 pendingScript->setElement(script); | 391 pendingScript->setElement(script); |
392 // This should correctly return 0 for empty or invalid srcValues. | 392 // This should correctly return 0 for empty or invalid srcValues. |
393 ScriptResource* resource = toScriptLoaderIfPossible(script)->resource().get(
); | 393 ScriptResource* resource = toScriptLoaderIfPossible(script)->resource(); |
394 if (!resource) { | 394 if (!resource) { |
395 notImplemented(); // Dispatch error event. | 395 notImplemented(); // Dispatch error event. |
396 return false; | 396 return false; |
397 } | 397 } |
398 pendingScript->setScriptResource(resource); | 398 pendingScript->setScriptResource(resource); |
399 return true; | 399 return true; |
400 } | 400 } |
401 | 401 |
402 // Implements the initial steps for 'An end tag whose tag name is "script"' | 402 // Implements the initial steps for 'An end tag whose tag name is "script"' |
403 // http://whatwg.org/html#scriptEndTag | 403 // http://whatwg.org/html#scriptEndTag |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 DEFINE_TRACE(HTMLScriptRunner) | 448 DEFINE_TRACE(HTMLScriptRunner) |
449 { | 449 { |
450 visitor->trace(m_document); | 450 visitor->trace(m_document); |
451 visitor->trace(m_host); | 451 visitor->trace(m_host); |
452 visitor->trace(m_parserBlockingScript); | 452 visitor->trace(m_parserBlockingScript); |
453 visitor->trace(m_scriptsToExecuteAfterParsing); | 453 visitor->trace(m_scriptsToExecuteAfterParsing); |
454 } | 454 } |
455 | 455 |
456 } // namespace blink | 456 } // namespace blink |
OLD | NEW |