| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 void HTMLScriptRunner::executeParsingBlockingScript() | 108 void HTMLScriptRunner::executeParsingBlockingScript() |
| 109 { | 109 { |
| 110 ASSERT(m_document); | 110 ASSERT(m_document); |
| 111 ASSERT(!isExecutingScript()); | 111 ASSERT(!isExecutingScript()); |
| 112 ASSERT(m_document->haveStylesheetsAndImportsLoaded()); | 112 ASSERT(m_document->haveStylesheetsAndImportsLoaded()); |
| 113 ASSERT(isPendingScriptReady(m_parserBlockingScript)); | 113 ASSERT(isPendingScriptReady(m_parserBlockingScript)); |
| 114 | 114 |
| 115 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 115 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 116 executePendingScriptAndDispatchEvent(m_parserBlockingScript); | 116 executePendingScriptAndDispatchEvent(m_parserBlockingScript, PendingScriptBl
ockingParser); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript) | 119 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript, PendingScriptType pendingScriptType) |
| 120 { | 120 { |
| 121 bool errorOccurred = false; | 121 bool errorOccurred = false; |
| 122 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); | 122 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); |
| 123 | 123 |
| 124 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. | 124 // Stop watching loads before executeScript to prevent recursion if the scri
pt reloads itself. |
| 125 if (pendingScript.resource() && pendingScript.watchingForLoad()) | 125 if (pendingScript.resource() && pendingScript.watchingForLoad()) |
| 126 stopWatchingForLoad(pendingScript); | 126 stopWatchingForLoad(pendingScript); |
| 127 | 127 |
| 128 if (!isExecutingScript()) | 128 if (!isExecutingScript()) { |
| 129 Microtask::performCheckpoint(); | 129 Microtask::performCheckpoint(); |
| 130 if (pendingScriptType == PendingScriptBlockingParser) { |
| 131 m_hasScriptsWaitingForResources = !m_document->haveStylesheetsAndImp
ortsLoaded(); |
| 132 // The parser cannot be unblocked as a microtask requested another r
esource |
| 133 if (m_hasScriptsWaitingForResources) |
| 134 return; |
| 135 } |
| 136 } |
| 130 | 137 |
| 131 // Clear the pending script before possible rentrancy from executeScript() | 138 // Clear the pending script before possible rentrancy from executeScript() |
| 132 RefPtr<Element> element = pendingScript.releaseElementAndClear(); | 139 RefPtr<Element> element = pendingScript.releaseElementAndClear(); |
| 133 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 140 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
| 134 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 141 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 135 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); | 142 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); |
| 136 if (errorOccurred) | 143 if (errorOccurred) |
| 137 scriptLoader->dispatchErrorEvent(); | 144 scriptLoader->dispatchErrorEvent(); |
| 138 else { | 145 else { |
| 139 ASSERT(isExecutingScript()); | 146 ASSERT(isExecutingScript()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 { | 223 { |
| 217 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 224 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
| 218 ASSERT(!isExecutingScript()); | 225 ASSERT(!isExecutingScript()); |
| 219 ASSERT(!hasParserBlockingScript()); | 226 ASSERT(!hasParserBlockingScript()); |
| 220 ASSERT(m_scriptsToExecuteAfterParsing.first().resource()); | 227 ASSERT(m_scriptsToExecuteAfterParsing.first().resource()); |
| 221 if (!m_scriptsToExecuteAfterParsing.first().resource()->isLoaded()) { | 228 if (!m_scriptsToExecuteAfterParsing.first().resource()->isLoaded()) { |
| 222 watchForLoad(m_scriptsToExecuteAfterParsing.first()); | 229 watchForLoad(m_scriptsToExecuteAfterParsing.first()); |
| 223 return false; | 230 return false; |
| 224 } | 231 } |
| 225 PendingScript first = m_scriptsToExecuteAfterParsing.takeFirst(); | 232 PendingScript first = m_scriptsToExecuteAfterParsing.takeFirst(); |
| 226 executePendingScriptAndDispatchEvent(first); | 233 executePendingScriptAndDispatchEvent(first, PendingScriptDeferred); |
| 227 // FIXME: What is this m_document check for? | 234 // FIXME: What is this m_document check for? |
| 228 if (!m_document) | 235 if (!m_document) |
| 229 return false; | 236 return false; |
| 230 } | 237 } |
| 231 return true; | 238 return true; |
| 232 } | 239 } |
| 233 | 240 |
| 234 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) | 241 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) |
| 235 { | 242 { |
| 236 if (!requestPendingScript(m_parserBlockingScript, element)) | 243 if (!requestPendingScript(m_parserBlockingScript, element)) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); | 316 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); |
| 310 scriptLoader->executeScript(sourceCode); | 317 scriptLoader->executeScript(sourceCode); |
| 311 } | 318 } |
| 312 } else { | 319 } else { |
| 313 requestParsingBlockingScript(script); | 320 requestParsingBlockingScript(script); |
| 314 } | 321 } |
| 315 } | 322 } |
| 316 } | 323 } |
| 317 | 324 |
| 318 } | 325 } |
| OLD | NEW |