Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: Source/core/html/parser/HTMLScriptRunner.cpp

Issue 14660019: Run Mutation Observer and Custom Element callbacks consistently at microtask checkpoint (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 11 matching lines...) Expand all
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 "HTMLNames.h" 29 #include "HTMLNames.h"
30 #include "bindings/v8/ScriptSourceCode.h" 30 #include "bindings/v8/ScriptSourceCode.h"
31 #include "core/dom/Attribute.h" 31 #include "core/dom/Attribute.h"
32 #include "core/dom/CustomElementRegistry.h"
33 #include "core/dom/Element.h" 32 #include "core/dom/Element.h"
34 #include "core/dom/Event.h" 33 #include "core/dom/Event.h"
35 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" 34 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
36 #include "core/dom/MutationObserver.h" 35 #include "core/dom/Microtask.h"
37 #include "core/dom/ScriptElement.h" 36 #include "core/dom/ScriptElement.h"
38 #include "core/html/parser/HTMLInputStream.h" 37 #include "core/html/parser/HTMLInputStream.h"
39 #include "core/html/parser/HTMLScriptRunnerHost.h" 38 #include "core/html/parser/HTMLScriptRunnerHost.h"
40 #include "core/html/parser/NestingLevelIncrementer.h" 39 #include "core/html/parser/NestingLevelIncrementer.h"
41 #include "core/loader/cache/CachedResourceLoader.h" 40 #include "core/loader/cache/CachedResourceLoader.h"
42 #include "core/loader/cache/CachedScript.h" 41 #include "core/loader/cache/CachedScript.h"
43 #include "core/page/Frame.h" 42 #include "core/page/Frame.h"
44 #include "core/platform/NotImplemented.h" 43 #include "core/platform/NotImplemented.h"
45 44
46 namespace WebCore { 45 namespace WebCore {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript) 122 void HTMLScriptRunner::executePendingScriptAndDispatchEvent(PendingScript& pendi ngScript)
124 { 123 {
125 bool errorOccurred = false; 124 bool errorOccurred = false;
126 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc curred); 125 ScriptSourceCode sourceCode = sourceFromPendingScript(pendingScript, errorOc curred);
127 126
128 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself. 127 // Stop watching loads before executeScript to prevent recursion if the scri pt reloads itself.
129 if (pendingScript.cachedScript() && pendingScript.watchingForLoad()) 128 if (pendingScript.cachedScript() && pendingScript.watchingForLoad())
130 stopWatchingForLoad(pendingScript); 129 stopWatchingForLoad(pendingScript);
131 130
132 if (!isExecutingScript()) { 131 if (!isExecutingScript()) {
133 CustomElementRegistry::deliverAllLifecycleCallbacks(); 132 Microtask::performCheckpoint();
134 MutationObserver::deliverAllMutations();
135 } 133 }
136 134
137 // Clear the pending script before possible rentrancy from executeScript() 135 // Clear the pending script before possible rentrancy from executeScript()
138 RefPtr<Element> element = pendingScript.releaseElementAndClear(); 136 RefPtr<Element> element = pendingScript.releaseElementAndClear();
139 if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get())) { 137 if (ScriptElement* scriptElement = toScriptElementIfPossible(element.get())) {
140 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 138 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
141 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document); 139 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem enter(m_document);
142 if (errorOccurred) 140 if (errorOccurred)
143 scriptElement->dispatchErrorEvent(); 141 scriptElement->dispatchErrorEvent();
144 else { 142 else {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. 287 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>.
290 ASSERT(scriptElement); 288 ASSERT(scriptElement);
291 if (!scriptElement) 289 if (!scriptElement)
292 return; 290 return;
293 291
294 // FIXME: This may be too agressive as we always deliver mutations at 292 // FIXME: This may be too agressive as we always deliver mutations at
295 // every script element, even if it's not ready to execute yet. There's 293 // every script element, even if it's not ready to execute yet. There's
296 // unfortuantely no obvious way to tell if prepareScript is going to 294 // unfortuantely no obvious way to tell if prepareScript is going to
297 // execute the script from out here. 295 // execute the script from out here.
298 if (!isExecutingScript()) { 296 if (!isExecutingScript()) {
299 CustomElementRegistry::deliverAllLifecycleCallbacks(); 297 Microtask::performCheckpoint();
300 MutationObserver::deliverAllMutations();
301 } 298 }
302 299
303 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 300 InsertionPointRecord insertionPointRecord(m_host->inputStream());
304 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 301 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
305 302
306 scriptElement->prepareScript(scriptStartPosition); 303 scriptElement->prepareScript(scriptStartPosition);
307 304
308 if (!scriptElement->willBeParserExecuted()) 305 if (!scriptElement->willBeParserExecuted())
309 return; 306 return;
310 307
311 if (scriptElement->willExecuteWhenDocumentFinishedParsing()) 308 if (scriptElement->willExecuteWhenDocumentFinishedParsing())
312 requestDeferredScript(script); 309 requestDeferredScript(script);
313 else if (scriptElement->readyToBeParserExecuted()) { 310 else if (scriptElement->readyToBeParserExecuted()) {
314 if (m_scriptNestingLevel == 1) { 311 if (m_scriptNestingLevel == 1) {
315 m_parserBlockingScript.setElement(script); 312 m_parserBlockingScript.setElement(script);
316 m_parserBlockingScript.setStartingPosition(scriptStartPosition); 313 m_parserBlockingScript.setStartingPosition(scriptStartPosition);
317 } else { 314 } else {
318 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); 315 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition);
319 scriptElement->executeScript(sourceCode); 316 scriptElement->executeScript(sourceCode);
320 } 317 }
321 } else 318 } else
322 requestParsingBlockingScript(script); 319 requestParsingBlockingScript(script);
323 } 320 }
324 } 321 }
325 322
326 } 323 }
OLDNEW
« Source/core/dom/CustomElementRegistry.h ('K') | « Source/core/dom/Microtask.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698