<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[212556] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/212556">212556</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2017-02-17 11:00:25 -0800 (Fri, 17 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Unreviewed, rolling out <a href="http://trac.webkit.org/projects/webkit/changeset/212463">r212463</a>.
https://bugs.webkit.org/show_bug.cgi?id=168526

Some crashes with GuardMalloc (Requested by anttik on
#webkit).

Reverted changeset:

&quot;Execute pending scripts asynchronously after stylesheet loads
complete&quot;
https://bugs.webkit.org/show_bug.cgi?id=168367
http://trac.webkit.org/changeset/212463</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorecssStyleSheetContentscpp">trunk/Source/WebCore/css/StyleSheetContents.cpp</a></li>
<li><a href="#trunkSourceWebCoredomContainerNodecpp">trunk/Source/WebCore/dom/ContainerNode.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoredomDocumenth">trunk/Source/WebCore/dom/Document.h</a></li>
<li><a href="#trunkSourceWebCoredomScriptableDocumentParsercpp">trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptableDocumentParserh">trunk/Source/WebCore/dom/ScriptableDocumentParser.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementcpp">trunk/Source/WebCore/html/HTMLLinkElement.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLLinkElementh">trunk/Source/WebCore/html/HTMLLinkElement.h</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLDocumentParsercpp">trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLDocumentParserh">trunk/Source/WebCore/html/parser/HTMLDocumentParser.h</a></li>
<li><a href="#trunkSourceWebCoreloaderDocumentLoadercpp">trunk/Source/WebCore/loader/DocumentLoader.cpp</a></li>
<li><a href="#trunkSourceWebCoreloaderFrameLoadercpp">trunk/Source/WebCore/loader/FrameLoader.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopecpp">trunk/Source/WebCore/style/StyleScope.cpp</a></li>
<li><a href="#trunkSourceWebCorestyleStyleScopeh">trunk/Source/WebCore/style/StyleScope.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/ChangeLog        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -1,3 +1,18 @@
</span><ins>+2017-02-17  Commit Queue  &lt;commit-queue@webkit.org&gt;
+
+        Unreviewed, rolling out r212463.
+        https://bugs.webkit.org/show_bug.cgi?id=168526
+
+        Some crashes with GuardMalloc (Requested by anttik on
+        #webkit).
+
+        Reverted changeset:
+
+        &quot;Execute pending scripts asynchronously after stylesheet loads
+        complete&quot;
+        https://bugs.webkit.org/show_bug.cgi?id=168367
+        http://trac.webkit.org/changeset/212463
+
</ins><span class="cx"> 2017-02-16  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         RenderView needs to be updated when FrameView changes
</span></span></pre></div>
<a id="trunkSourceWebCorecssStyleSheetContentscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/css/StyleSheetContents.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/css/StyleSheetContents.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/css/StyleSheetContents.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -364,6 +364,9 @@
</span><span class="cx">     if (isLoading())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    // Avoid |this| being deleted by scripts that run via
+    // ScriptableDocumentParser::executeScriptsWaitingForStylesheets().
+    // See &lt;rdar://problem/6622300&gt;.
</ins><span class="cx">     Ref&lt;StyleSheetContents&gt; protectedThis(*this);
</span><span class="cx">     StyleSheetContents* parentSheet = parentStyleSheet();
</span><span class="cx">     if (parentSheet) {
</span></span></pre></div>
<a id="trunkSourceWebCoredomContainerNodecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ContainerNode.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ContainerNode.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/dom/ContainerNode.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -145,6 +145,8 @@
</span><span class="cx">         childrenChanged(change);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    document().notifyRemovePendingSheetIfNeeded();
+
</ins><span class="cx">     // FIXME: assert that we don't dispatch events here since this container node is still disconnected.
</span><span class="cx">     for (auto&amp; child : children) {
</span><span class="cx">         RELEASE_ASSERT(!child-&gt;parentNode() &amp;&amp; &amp;child-&gt;treeScope() == &amp;treeScope());
</span><span class="lines">@@ -362,6 +364,9 @@
</span><span class="cx"> 
</span><span class="cx">     childrenChanged(change);
</span><span class="cx"> 
</span><ins>+    // Some call sites may have deleted child nodes. Calling it earlier results in bugs like webkit.org/b/168069.
+    document().notifyRemovePendingSheetIfNeeded();
+
</ins><span class="cx">     for (auto&amp; target : postInsertionNotificationTargets)
</span><span class="cx">         target-&gt;finishedInsertingSubtree();
</span><span class="cx"> }
</span><span class="lines">@@ -549,6 +554,7 @@
</span><span class="cx">         notifyChildRemoved(child, prev, next, ChildChangeSourceAPI);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    document().notifyRemovePendingSheetIfNeeded();
</ins><span class="cx">     rebuildSVGExtensionsElementsIfNecessary();
</span><span class="cx">     dispatchSubtreeModifiedEvent();
</span><span class="cx"> 
</span><span class="lines">@@ -609,6 +615,7 @@
</span><span class="cx">     removeBetween(prev, next, oldChild);
</span><span class="cx"> 
</span><span class="cx">     notifyChildRemoved(oldChild, prev, next, ChildChangeSourceParser);
</span><ins>+    document().notifyRemovePendingSheetIfNeeded();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://dom.spec.whatwg.org/#concept-node-replace-all
</span><span class="lines">@@ -702,6 +709,7 @@
</span><span class="cx">         childrenChanged(change);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    document().notifyRemovePendingSheetIfNeeded();
</ins><span class="cx">     rebuildSVGExtensionsElementsIfNecessary();
</span><span class="cx">     dispatchSubtreeModifiedEvent();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/dom/Document.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -443,6 +443,7 @@
</span><span class="cx">     , m_referencingNodeCount(0)
</span><span class="cx">     , m_settings(frame ? Ref&lt;Settings&gt;(frame-&gt;settings()) : Settings::create(nullptr))
</span><span class="cx">     , m_hasNodesWithPlaceholderStyle(false)
</span><ins>+    , m_needsNotifyRemoveAllPendingStylesheet(false)
</ins><span class="cx">     , m_ignorePendingStylesheets(false)
</span><span class="cx">     , m_pendingSheetLayout(NoLayoutWithPendingSheets)
</span><span class="cx">     , m_cachedResourceLoader(m_frame ? Ref&lt;CachedResourceLoader&gt;(m_frame-&gt;loader().activeDocumentLoader()-&gt;cachedResourceLoader()) : CachedResourceLoader::create(nullptr))
</span><span class="lines">@@ -1845,9 +1846,6 @@
</span><span class="cx">     // to check if any other elements ended up under the mouse pointer due to re-layout.
</span><span class="cx">     if (m_hoveredElement &amp;&amp; !m_hoveredElement-&gt;renderer())
</span><span class="cx">         frameView.frame().mainFrame().eventHandler().dispatchFakeMouseMoveEventSoon();
</span><del>-
-    if (m_gotoAnchorNeededAfterStylesheetsLoad &amp;&amp; !styleScope().hasPendingSheets())
-        frameView.scrollToFragment(m_url);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Document::needsStyleRecalc() const
</span><span class="lines">@@ -2625,7 +2623,7 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    checkCompleted();
</del><ins>+    m_frame-&gt;loader().checkCompleted();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Document::implicitClose()
</span><span class="lines">@@ -3075,17 +3073,19 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::didRemoveAllPendingStylesheet()
</span><span class="cx"> {
</span><ins>+    m_needsNotifyRemoveAllPendingStylesheet = false;
+
</ins><span class="cx">     if (m_pendingSheetLayout == DidLayoutWithPendingSheets) {
</span><del>-        // Painting is disabled when doing layouts with pending sheets to avoid FOUC.
-        // We need to force paint when coming out from this state.
-        // FIXME: This is not very elegant.
</del><span class="cx">         m_pendingSheetLayout = IgnoreLayoutWithPendingSheets;
</span><span class="cx">         if (renderView())
</span><span class="cx">             renderView()-&gt;repaintViewAndCompositedLayers();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    if (auto* parser = scriptableDocumentParser())
-        parser-&gt;executeScriptsWaitingForStylesheetsSoon();
</del><ins>+    if (ScriptableDocumentParser* parser = scriptableDocumentParser())
+        parser-&gt;executeScriptsWaitingForStylesheets();
+
+    if (m_gotoAnchorNeededAfterStylesheetsLoad &amp;&amp; view())
+        view()-&gt;scrollToFragment(m_url);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Document::usesStyleBasedEditability() const
</span><span class="lines">@@ -6038,15 +6038,10 @@
</span><span class="cx"> 
</span><span class="cx"> void Document::loadEventDelayTimerFired()
</span><span class="cx"> {
</span><del>-    checkCompleted();
</del><ins>+    if (frame())
+        frame()-&gt;loader().checkCompleted();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Document::checkCompleted()
-{
-    if (auto* frame = this-&gt;frame())
-        frame-&gt;loader().checkCompleted();
-}
-
</del><span class="cx"> double Document::monotonicTimestamp() const
</span><span class="cx"> {
</span><span class="cx">     auto* loader = this-&gt;loader();
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.h (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.h        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/dom/Document.h        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -486,6 +486,8 @@
</span><span class="cx"> 
</span><span class="cx">     CSSFontSelector&amp; fontSelector() { return m_fontSelector; }
</span><span class="cx"> 
</span><ins>+    void notifyRemovePendingSheetIfNeeded();
+
</ins><span class="cx">     WEBCORE_EXPORT bool haveStylesheetsLoaded() const;
</span><span class="cx"> 
</span><span class="cx">     WEBCORE_EXPORT StyleSheetList&amp; styleSheets();
</span><span class="lines">@@ -1114,7 +1116,6 @@
</span><span class="cx">     void incrementLoadEventDelayCount() { ++m_loadEventDelayCount; }
</span><span class="cx">     void decrementLoadEventDelayCount();
</span><span class="cx">     bool isDelayingLoadEvent() const { return m_loadEventDelayCount; }
</span><del>-    void checkCompleted();
</del><span class="cx"> 
</span><span class="cx"> #if ENABLE(IOS_TOUCH_EVENTS)
</span><span class="cx"> #include &lt;WebKitAdditions/DocumentIOS.h&gt;
</span><span class="lines">@@ -1205,6 +1206,7 @@
</span><span class="cx">     DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); }
</span><span class="cx"> 
</span><span class="cx">     void didRemoveAllPendingStylesheet();
</span><ins>+    void setNeedsNotifyRemoveAllPendingStylesheet() { m_needsNotifyRemoveAllPendingStylesheet = true; }
</ins><span class="cx">     void didClearStyleResolver();
</span><span class="cx"> 
</span><span class="cx">     bool inStyleRecalc() const { return m_inStyleRecalc; }
</span><span class="lines">@@ -1389,6 +1391,7 @@
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;StyleResolver&gt; m_userAgentShadowTreeStyleResolver;
</span><span class="cx">     bool m_hasNodesWithPlaceholderStyle;
</span><ins>+    bool m_needsNotifyRemoveAllPendingStylesheet;
</ins><span class="cx">     // But sometimes you need to ignore pending stylesheet count to
</span><span class="cx">     // force an immediate layout when requested by JS.
</span><span class="cx">     bool m_ignorePendingStylesheets;
</span><span class="lines">@@ -1754,6 +1757,12 @@
</span><span class="cx"> 
</span><span class="cx"> Element* eventTargetElementForDocument(Document*);
</span><span class="cx"> 
</span><ins>+inline void Document::notifyRemovePendingSheetIfNeeded()
+{
+    if (m_needsNotifyRemoveAllPendingStylesheet)
+        didRemoveAllPendingStylesheet();
+}
+
</ins><span class="cx"> inline TextEncoding Document::textEncoding() const
</span><span class="cx"> {
</span><span class="cx">     if (auto* decoder = this-&gt;decoder())
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptableDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/dom/ScriptableDocumentParser.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -28,7 +28,6 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><del>-#include &quot;StyleScope.h&quot;
</del><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -36,7 +35,6 @@
</span><span class="cx">     : DecodedDataDocumentParser(document)
</span><span class="cx">     , m_wasCreatedByScript(false)
</span><span class="cx">     , m_parserContentPolicy(parserContentPolicy)
</span><del>-    , m_scriptsWaitingForStylesheetsExecutionTimer(*this, &amp;ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired)
</del><span class="cx"> {
</span><span class="cx">     if (!pluginContentIsAllowed(m_parserContentPolicy))
</span><span class="cx">         m_parserContentPolicy = allowPluginContent(m_parserContentPolicy);
</span><span class="lines">@@ -45,32 +43,4 @@
</span><span class="cx">         m_parserContentPolicy = disallowScriptingContent(m_parserContentPolicy);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptableDocumentParser::executeScriptsWaitingForStylesheetsSoon()
-{
-    ASSERT(!document()-&gt;styleScope().hasPendingSheets());
-
-    if (m_scriptsWaitingForStylesheetsExecutionTimer.isActive())
-        return;
-    if (!hasScriptsWaitingForStylesheets())
-        return;
-
-    m_scriptsWaitingForStylesheetsExecutionTimer.startOneShot(0);
-}
-
-void ScriptableDocumentParser::scriptsWaitingForStylesheetsExecutionTimerFired()
-{
-    if (!document()-&gt;styleScope().hasPendingSheets())
-        executeScriptsWaitingForStylesheets();
-
-    if (!isDetached())
-        document()-&gt;checkCompleted();
-}
-
-void ScriptableDocumentParser::detach()
-{
-    m_scriptsWaitingForStylesheetsExecutionTimer.stop();
-
-    DecodedDataDocumentParser::detach();
-}
-
</del><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptableDocumentParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptableDocumentParser.h (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptableDocumentParser.h        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/dom/ScriptableDocumentParser.h        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -27,7 +27,6 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;DecodedDataDocumentParser.h&quot;
</span><span class="cx"> #include &quot;FragmentScriptingPermission.h&quot;
</span><del>-#include &quot;Timer.h&quot;
</del><span class="cx"> #include &lt;wtf/text/TextPosition.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -38,14 +37,14 @@
</span><span class="cx">     // JavaScript document.open() call right now, or it should be ignored.
</span><span class="cx">     virtual bool isExecutingScript() const { return false; }
</span><span class="cx"> 
</span><ins>+    // FIXME: Only the HTMLDocumentParser ever blocks script execution on
+    // stylesheet load, which is likely a bug in the XMLDocumentParser.
+    virtual void executeScriptsWaitingForStylesheets() { }
+
</ins><span class="cx">     virtual bool isWaitingForScripts() const = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual TextPosition textPosition() const = 0;
</span><span class="cx"> 
</span><del>-    virtual bool hasScriptsWaitingForStylesheets() const { return false; }
-
-    void executeScriptsWaitingForStylesheetsSoon();
-
</del><span class="cx">     // Returns true if the parser didn't yield or pause or synchronously execute a script,
</span><span class="cx">     // so calls to PageConsoleClient should be associated with the parser's text position.
</span><span class="cx">     virtual bool shouldAssociateConsoleMessagesWithTextPosition() const = 0;
</span><span class="lines">@@ -58,19 +57,12 @@
</span><span class="cx"> protected:
</span><span class="cx">     explicit ScriptableDocumentParser(Document&amp;, ParserContentPolicy = AllowScriptingContent);
</span><span class="cx"> 
</span><del>-    virtual void executeScriptsWaitingForStylesheets() { }
-
-    void detach() override;
-
</del><span class="cx"> private:
</span><span class="cx">     ScriptableDocumentParser* asScriptableDocumentParser() final { return this; }
</span><span class="cx"> 
</span><del>-    void scriptsWaitingForStylesheetsExecutionTimerFired();
-
</del><span class="cx">     // http://www.whatwg.org/specs/web-apps/current-work/#script-created-parser
</span><span class="cx">     bool m_wasCreatedByScript;
</span><span class="cx">     ParserContentPolicy m_parserContentPolicy;
</span><del>-    Timer m_scriptsWaitingForStylesheetsExecutionTimer;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -327,7 +327,7 @@
</span><span class="cx">         clearSheet();
</span><span class="cx"> 
</span><span class="cx">     if (styleSheetIsLoading())
</span><del>-        removePendingSheet();
</del><ins>+        removePendingSheet(RemovePendingSheetNotifyLater);
</ins><span class="cx">     
</span><span class="cx">     if (m_styleScope) {
</span><span class="cx">         m_styleScope-&gt;removeStyleSheetCandidateNode(*this);
</span><span class="lines">@@ -554,7 +554,7 @@
</span><span class="cx">     m_styleScope-&gt;addPendingSheet();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void HTMLLinkElement::removePendingSheet()
</del><ins>+void HTMLLinkElement::removePendingSheet(RemovePendingSheetNotificationType notification)
</ins><span class="cx"> {
</span><span class="cx">     PendingSheetType type = m_pendingSheetType;
</span><span class="cx">     m_pendingSheetType = Unknown;
</span><span class="lines">@@ -569,7 +569,10 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_styleScope-&gt;removePendingSheet();
</del><ins>+    m_styleScope-&gt;removePendingSheet(
+        notification == RemovePendingSheetNotifyImmediately
+        ? Style::Scope::RemovePendingSheetNotifyImmediately
+        : Style::Scope::RemovePendingSheetNotifyLater);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLLinkElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLLinkElement.h        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -111,8 +111,13 @@
</span><span class="cx">     enum PendingSheetType { Unknown, ActiveSheet, InactiveSheet };
</span><span class="cx">     void addPendingSheet(PendingSheetType);
</span><span class="cx"> 
</span><del>-    void removePendingSheet();
</del><ins>+    enum RemovePendingSheetNotificationType {
+        RemovePendingSheetNotifyImmediately,
+        RemovePendingSheetNotifyLater
+    };
</ins><span class="cx"> 
</span><ins>+    void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
+
</ins><span class="cx">     LinkLoader m_linkLoader;
</span><span class="cx">     Style::Scope* m_styleScope { nullptr };
</span><span class="cx">     CachedResourceHandle&lt;CachedCSSStyleSheet&gt; m_cachedSheet;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLDocumentParser::detach()
</span><span class="cx"> {
</span><del>-    ScriptableDocumentParser::detach();
</del><ins>+    DocumentParser::detach();
</ins><span class="cx"> 
</span><span class="cx">     if (m_scriptRunner)
</span><span class="cx">         m_scriptRunner-&gt;detach();
</span><span class="lines">@@ -538,11 +538,6 @@
</span><span class="cx">         resumeParsingAfterScriptExecution();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool HTMLDocumentParser::hasScriptsWaitingForStylesheets() const
-{
-    return m_scriptRunner &amp;&amp; m_scriptRunner-&gt;hasScriptsWaitingForStylesheets();
-}
-
</del><span class="cx"> void HTMLDocumentParser::executeScriptsWaitingForStylesheets()
</span><span class="cx"> {
</span><span class="cx">     // Document only calls this when the Document owns the DocumentParser
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLDocumentParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.h (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.h        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.h        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -83,7 +83,6 @@
</span><span class="cx">     void stopParsing() final;
</span><span class="cx">     bool isWaitingForScripts() const override;
</span><span class="cx">     bool isExecutingScript() const final;
</span><del>-    bool hasScriptsWaitingForStylesheets() const final;
</del><span class="cx">     void executeScriptsWaitingForStylesheets() final;
</span><span class="cx">     void suspendScheduledTasks() final;
</span><span class="cx">     void resumeScheduledTasks() final;
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderDocumentLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/DocumentLoader.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -68,7 +68,6 @@
</span><span class="cx"> #include &quot;ResourceHandle.h&quot;
</span><span class="cx"> #include &quot;ResourceLoadObserver.h&quot;
</span><span class="cx"> #include &quot;SchemeRegistry.h&quot;
</span><del>-#include &quot;ScriptableDocumentParser.h&quot;
</del><span class="cx"> #include &quot;SecurityPolicy.h&quot;
</span><span class="cx"> #include &quot;Settings.h&quot;
</span><span class="cx"> #include &quot;SubresourceLoader.h&quot;
</span><span class="lines">@@ -1058,9 +1057,6 @@
</span><span class="cx">             return true;
</span><span class="cx">         if (document.hasActiveParser())
</span><span class="cx">             return true;
</span><del>-        auto* scriptableParser = document.scriptableDocumentParser();
-        if (scriptableParser &amp;&amp; scriptableParser-&gt;hasScriptsWaitingForStylesheets())
-            return true;
</del><span class="cx">     }
</span><span class="cx">     return frameLoader()-&gt;subframeIsLoading();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloaderFrameLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/FrameLoader.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -787,10 +787,6 @@
</span><span class="cx">     if (m_frame.document()-&gt;isDelayingLoadEvent())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    auto* scriptableParser = m_frame.document()-&gt;scriptableDocumentParser();
-    if (scriptableParser &amp;&amp; scriptableParser-&gt;hasScriptsWaitingForStylesheets())
-        return;
-
</del><span class="cx">     // Any frame that hasn't completed yet?
</span><span class="cx">     if (!allChildrenAreComplete())
</span><span class="cx">         return;
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.cpp (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.cpp        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/style/StyleScope.cpp        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -170,7 +170,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // This method is called whenever a top-level stylesheet has finished loading.
</span><del>-void Scope::removePendingSheet()
</del><ins>+void Scope::removePendingSheet(RemovePendingSheetNotificationType notification)
</ins><span class="cx"> {
</span><span class="cx">     // Make sure we knew this sheet was pending, and that our count isn't out of sync.
</span><span class="cx">     ASSERT(m_pendingStyleSheetCount &gt; 0);
</span><span class="lines">@@ -179,6 +179,11 @@
</span><span class="cx">     if (m_pendingStyleSheetCount)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><ins>+    if (notification == RemovePendingSheetNotifyLater) {
+        m_document.setNeedsNotifyRemoveAllPendingStylesheet();
+        return;
+    }
+
</ins><span class="cx">     didChangeActiveStyleSheetCandidates();
</span><span class="cx"> 
</span><span class="cx">     if (!m_shadowRoot)
</span></span></pre></div>
<a id="trunkSourceWebCorestyleStyleScopeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/style/StyleScope.h (212555 => 212556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/style/StyleScope.h        2017-02-17 18:48:11 UTC (rev 212555)
+++ trunk/Source/WebCore/style/StyleScope.h        2017-02-17 19:00:25 UTC (rev 212556)
</span><span class="lines">@@ -82,7 +82,11 @@
</span><span class="cx">     void setSelectedStylesheetSetName(const String&amp;);
</span><span class="cx"> 
</span><span class="cx">     void addPendingSheet() { m_pendingStyleSheetCount++; }
</span><del>-    void removePendingSheet();
</del><ins>+    enum RemovePendingSheetNotificationType {
+        RemovePendingSheetNotifyImmediately,
+        RemovePendingSheetNotifyLater
+    };
+    void removePendingSheet(RemovePendingSheetNotificationType = RemovePendingSheetNotifyImmediately);
</ins><span class="cx"> 
</span><span class="cx">     bool hasPendingSheets() const { return m_pendingStyleSheetCount &gt; 0; }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>