Chromium Code Reviews| 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 "config.h" | 26 #include "config.h" |
| 27 #include "core/html/parser/HTMLScriptRunner.h" | 27 #include "core/html/parser/HTMLScriptRunner.h" |
| 28 | 28 |
| 29 #include "bindings/v8/ScriptSourceCode.h" | 29 #include "bindings/v8/ScriptSourceCode.h" |
| 30 #include "bindings/v8/V8PerIsolateData.h" | |
|
adamk
2014/03/20 21:58:47
This seems a bit wrong to include here, but this i
| |
| 30 #include "core/dom/Element.h" | 31 #include "core/dom/Element.h" |
| 31 #include "core/events/Event.h" | 32 #include "core/events/Event.h" |
| 32 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 33 #include "core/dom/Microtask.h" | 34 #include "core/dom/Microtask.h" |
| 34 #include "core/dom/ScriptLoader.h" | 35 #include "core/dom/ScriptLoader.h" |
| 35 #include "core/fetch/ScriptResource.h" | 36 #include "core/fetch/ScriptResource.h" |
| 36 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
| 37 #include "core/html/parser/HTMLInputStream.h" | 38 #include "core/html/parser/HTMLInputStream.h" |
| 38 #include "core/html/parser/HTMLScriptRunnerHost.h" | 39 #include "core/html/parser/HTMLScriptRunnerHost.h" |
| 39 #include "core/html/parser/NestingLevelIncrementer.h" | 40 #include "core/html/parser/NestingLevelIncrementer.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript) | 120 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript) |
| 120 { | 121 { |
| 121 bool errorOccurred = false; | 122 bool errorOccurred = false; |
| 122 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc curred); | 123 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc curred); |
| 123 | 124 |
| 124 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. | 125 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. |
| 125 if (pendingScript.resource() && pendingScript.watchingForLoad()) | 126 if (pendingScript.resource() && pendingScript.watchingForLoad()) |
| 126 stopWatchingForLoad(pendingScript); | 127 stopWatchingForLoad(pendingScript); |
| 127 | 128 |
| 128 if (!isExecutingScript()) { | 129 if (!isExecutingScript()) { |
| 129 Microtask::performCheckpoint(); | 130 if (!V8PerIsolateData::current()->recursionLevel()) |
| 131 Microtask::performCheckpoint(); | |
| 132 | |
| 130 m_hasScriptsWaitingForResources = !m_document->haveStylesheetsAndImports Loaded(); | 133 m_hasScriptsWaitingForResources = !m_document->haveStylesheetsAndImports Loaded(); |
| 131 if (m_hasScriptsWaitingForResources) | 134 if (m_hasScriptsWaitingForResources) |
| 132 return; | 135 return; |
| 133 } | 136 } |
| 134 | 137 |
| 135 // Clear the pending script before possible rentrancy from executeScript() | 138 // Clear the pending script before possible rentrancy from executeScript() |
| 136 RefPtr<Element> element = pendingScript.releaseElementAndClear(); | 139 RefPtr<Element> element = pendingScript.releaseElementAndClear(); |
| 137 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 140 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
| 138 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 141 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 139 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); | 142 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 // This contains both and ASSERTION and a null check since we should not | 288 // This contains both and ASSERTION and a null check since we should not |
| 286 // be getting into the case of a null script element, but seem to be fro m | 289 // be getting into the case of a null script element, but seem to be fro m |
| 287 // time to time. The assertion is left in to help find those cases and | 290 // time to time. The assertion is left in to help find those cases and |
| 288 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. | 291 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. |
| 289 ASSERT(scriptLoader); | 292 ASSERT(scriptLoader); |
| 290 if (!scriptLoader) | 293 if (!scriptLoader) |
| 291 return; | 294 return; |
| 292 | 295 |
| 293 ASSERT(scriptLoader->isParserInserted()); | 296 ASSERT(scriptLoader->isParserInserted()); |
| 294 | 297 |
| 295 if (!isExecutingScript()) | 298 if (!isExecutingScript() && !V8PerIsolateData::current()->recursionLevel ()) |
| 296 Microtask::performCheckpoint(); | 299 Microtask::performCheckpoint(); |
| 297 | 300 |
| 298 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 301 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 299 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 302 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 300 | 303 |
| 301 scriptLoader->prepareScript(scriptStartPosition); | 304 scriptLoader->prepareScript(scriptStartPosition); |
| 302 | 305 |
| 303 if (!scriptLoader->willBeParserExecuted()) | 306 if (!scriptLoader->willBeParserExecuted()) |
| 304 return; | 307 return; |
| 305 | 308 |
| 306 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { | 309 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { |
| 307 requestDeferredScript(script); | 310 requestDeferredScript(script); |
| 308 } else if (scriptLoader->readyToBeParserExecuted()) { | 311 } else if (scriptLoader->readyToBeParserExecuted()) { |
| 309 if (m_scriptNestingLevel == 1) { | 312 if (m_scriptNestingLevel == 1) { |
| 310 m_parserBlockingScript.setElement(script); | 313 m_parserBlockingScript.setElement(script); |
| 311 m_parserBlockingScript.setStartingPosition(scriptStartPosition); | 314 m_parserBlockingScript.setStartingPosition(scriptStartPosition); |
| 312 } else { | 315 } else { |
| 313 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); | 316 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); |
| 314 scriptLoader->executeScript(sourceCode); | 317 scriptLoader->executeScript(sourceCode); |
| 315 } | 318 } |
| 316 } else { | 319 } else { |
| 317 requestParsingBlockingScript(script); | 320 requestParsingBlockingScript(script); |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 } | 323 } |
| 321 | 324 |
| 322 } | 325 } |
| OLD | NEW |