| 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 "core/dom/CustomElementRegistry.h" | |
| 31 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
| 32 #include "core/dom/Event.h" | 31 #include "core/dom/Event.h" |
| 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 32 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 34 #include "core/dom/MutationObserver.h" | 33 #include "core/dom/Microtask.h" |
| 35 #include "core/dom/ScriptElement.h" | 34 #include "core/dom/ScriptElement.h" |
| 36 #include "core/html/parser/HTMLInputStream.h" | 35 #include "core/html/parser/HTMLInputStream.h" |
| 37 #include "core/html/parser/HTMLScriptRunnerHost.h" | 36 #include "core/html/parser/HTMLScriptRunnerHost.h" |
| 38 #include "core/html/parser/NestingLevelIncrementer.h" | 37 #include "core/html/parser/NestingLevelIncrementer.h" |
| 39 #include "core/loader/cache/CachedScript.h" | 38 #include "core/loader/cache/CachedScript.h" |
| 40 #include "core/page/Frame.h" | 39 #include "core/page/Frame.h" |
| 41 #include "core/platform/NotImplemented.h" | 40 #include "core/platform/NotImplemented.h" |
| 42 | 41 |
| 43 namespace WebCore { | 42 namespace WebCore { |
| 44 | 43 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 118 |
| 120 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript) | 119 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi
ngScript) |
| 121 { | 120 { |
| 122 bool errorOccurred = false; | 121 bool errorOccurred = false; |
| 123 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); | 122 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc
curred); |
| 124 | 123 |
| 125 // 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. |
| 126 if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) | 125 if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) |
| 127 stopWatchingForLoad(pendingScript); | 126 stopWatchingForLoad(pendingScript); |
| 128 | 127 |
| 129 if (!isExecutingScript()) { | 128 if (!isExecutingScript()) |
| 130 CustomElementRegistry::deliverAllLifecycleCallbacks(); | 129 Microtask::performCheckpoint(); |
| 131 MutationObserver::deliverAllMutations(); | |
| 132 } | |
| 133 | 130 |
| 134 // Clear the pending script before possible rentrancy from executeScript() | 131 // Clear the pending script before possible rentrancy from executeScript() |
| 135 RefPtr<Element> element = pendingScript.releaseElementAndClear(); | 132 RefPtr<Element> element = pendingScript.releaseElementAndClear(); |
| 136 if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get()))
{ | 133 if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get()))
{ |
| 137 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 134 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 138 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); | 135 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); |
| 139 if (errorOccurred) | 136 if (errorOccurred) |
| 140 scriptElement->dispatchErrorEvent(); | 137 scriptElement->dispatchErrorEvent(); |
| 141 else { | 138 else { |
| 142 ASSERT(isExecutingScript()); | 139 ASSERT(isExecutingScript()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // time to time. The assertion is left in to help find those cases and | 282 // time to time. The assertion is left in to help find those cases and |
| 286 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. | 283 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. |
| 287 ASSERT(scriptElement); | 284 ASSERT(scriptElement); |
| 288 if (!scriptElement) | 285 if (!scriptElement) |
| 289 return; | 286 return; |
| 290 | 287 |
| 291 // FIXME: This may be too agressive as we always deliver mutations at | 288 // FIXME: This may be too agressive as we always deliver mutations at |
| 292 // every script element, even if it's not ready to execute yet. There's | 289 // every script element, even if it's not ready to execute yet. There's |
| 293 // unfortuantely no obvious way to tell if prepareScript is going to | 290 // unfortuantely no obvious way to tell if prepareScript is going to |
| 294 // execute the script from out here. | 291 // execute the script from out here. |
| 295 if (!isExecutingScript()) { | 292 if (!isExecutingScript()) |
| 296 CustomElementRegistry::deliverAllLifecycleCallbacks(); | 293 Microtask::performCheckpoint(); |
| 297 MutationObserver::deliverAllMutations(); | |
| 298 } | |
| 299 | 294 |
| 300 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 295 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 301 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 296 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 302 | 297 |
| 303 scriptElement->prepareScript(scriptStartPosition); | 298 scriptElement->prepareScript(scriptStartPosition); |
| 304 | 299 |
| 305 if (!scriptElement->willBeParserExecuted()) | 300 if (!scriptElement->willBeParserExecuted()) |
| 306 return; | 301 return; |
| 307 | 302 |
| 308 if (scriptElement->willExecuteWhenDocumentFinishedParsing()) | 303 if (scriptElement->willExecuteWhenDocumentFinishedParsing()) |
| 309 requestDeferredScript(script); | 304 requestDeferredScript(script); |
| 310 else if (scriptElement->readyToBeParserExecuted()) { | 305 else if (scriptElement->readyToBeParserExecuted()) { |
| 311 if (m_scriptNestingLevel == 1) { | 306 if (m_scriptNestingLevel == 1) { |
| 312 m_parserBlockingScript.setElement(script); | 307 m_parserBlockingScript.setElement(script); |
| 313 m_parserBlockingScript.setStartingPosition(scriptStartPosition); | 308 m_parserBlockingScript.setStartingPosition(scriptStartPosition); |
| 314 } else { | 309 } else { |
| 315 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); | 310 ScriptSourceCode sourceCode(script->textContent(), documentURLFo
rScriptExecution(m_document), scriptStartPosition); |
| 316 scriptElement->executeScript(sourceCode); | 311 scriptElement->executeScript(sourceCode); |
| 317 } | 312 } |
| 318 } else | 313 } else |
| 319 requestParsingBlockingScript(script); | 314 requestParsingBlockingScript(script); |
| 320 } | 315 } |
| 321 } | 316 } |
| 322 | 317 |
| 323 } | 318 } |
| OLD | NEW |