<!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>[205695] trunk</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/205695">205695</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2016-09-08 22:20:17 -0700 (Thu, 08 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>ScriptRunner should be driven by PendingScript rather than ScriptElement
https://bugs.webkit.org/show_bug.cgi?id=161726

Reviewed by Ryosuke Niwa.

Source/WebCore:

Tests: js/dom/document-write-in-error-event.html
       js/dom/document-write-in-load-event.html

ScriptRunner is driven by ScriptElement::notifyFinished. While ScriptRunner is driven by this,
HTMLScriptRunner does not use it. Instead, HTMLScriptRunner uses PendingScriptClient. As a result,
ScriptElement::notifyFinished is used only when the script is annotated with &quot;defer&quot; or &quot;async&quot;
while all the external script will load the LoadableScript. It is confusing.
This patch removes ScriptElement::notifyFinished and use PendingScript's observability
in ScriptRunner instead.

This patch also fixes the behavior about ignore-destructive-writes counter[1]. When dispatching
the load and error events, this ignore-destructive-writes counter should not be incremeneted by
this execution. The added tests ensure this behavior.

[1]: https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block

* dom/ScriptElement.cpp: Drop LoadableScriptClient interface.
(WebCore::ScriptElement::prepareScript): Do not use addClient. ScriptRunner use PendingScript::{setClient,clearClient} instead.
(WebCore::ScriptElement::executeScriptForScriptRunner): IgnoreDestructiveWriteCountIncrementer will be done in ScriptElement::executeScript.
So no need to do it here, that's duplicated.
(WebCore::ScriptElement::~ScriptElement): Deleted. ScriptElement does not use addClient/removeClient.
(WebCore::ScriptElement::stopLoadRequest): Deleted.
(WebCore::ScriptElement::executeScriptForHTMLScriptRunner): Deleted. executeScriptForHTMLScriptRunner and executeScriptForScriptRunner are
merged into executeScriptForRunner.
(WebCore::ScriptElement::notifyFinished): Deleted.
* dom/ScriptElement.h:
(WebCore::ScriptElement::~ScriptElement):
(WebCore::ScriptElement::willExecuteInOrder): Used in ScriptRunner to determine whether the script is async or defer.
(WebCore::ScriptElement::willExecuteWhenDocumentFinishedParsing): Deleted.
* dom/ScriptRunner.cpp:
(WebCore::ScriptRunner::~ScriptRunner): HashSet's iterator will return `const PendingScript&amp;`.
Another option is using HashSet&lt;RefPtr&lt;PendingScript&gt;&gt;. Here, we use a little bit weired const_cast.
(WebCore::ScriptRunner::queueScriptForExecution): Use PendingScript::setClient to wait loading.
(WebCore::ScriptRunner::notifyFinished): Notify the script ready here.
(WebCore::ScriptRunner::timerFired): Use executeScriptForScriptRunner.
(WebCore::ScriptRunner::notifyScriptReady): Deleted.
* dom/ScriptRunner.h:
* html/parser/HTMLScriptRunner.cpp:
(WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Use executeScriptForScriptRunner.

LayoutTests:

* js/dom/document-write-in-error-event-expected.txt: Added.
* js/dom/document-write-in-error-event.html: Added.
* js/dom/document-write-in-load-event-expected.txt: Added.
* js/dom/document-write-in-load-event.html: Added.
* js/dom/script-tests/dummy.js: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomScriptElementcpp">trunk/Source/WebCore/dom/ScriptElement.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptElementh">trunk/Source/WebCore/dom/ScriptElement.h</a></li>
<li><a href="#trunkSourceWebCoredomScriptRunnercpp">trunk/Source/WebCore/dom/ScriptRunner.cpp</a></li>
<li><a href="#trunkSourceWebCoredomScriptRunnerh">trunk/Source/WebCore/dom/ScriptRunner.h</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLScriptRunnercpp">trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsdomdocumentwriteinerroreventexpectedtxt">trunk/LayoutTests/js/dom/document-write-in-error-event-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdomdocumentwriteinerroreventhtml">trunk/LayoutTests/js/dom/document-write-in-error-event.html</a></li>
<li><a href="#trunkLayoutTestsjsdomdocumentwriteinloadeventexpectedtxt">trunk/LayoutTests/js/dom/document-write-in-load-event-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdomdocumentwriteinloadeventhtml">trunk/LayoutTests/js/dom/document-write-in-load-event.html</a></li>
<li><a href="#trunkLayoutTestsjsdomscripttestsdummyjs">trunk/LayoutTests/js/dom/script-tests/dummy.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/LayoutTests/ChangeLog        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-09-08  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        ScriptRunner should be driven by PendingScript rather than ScriptElement
+        https://bugs.webkit.org/show_bug.cgi?id=161726
+
+        Reviewed by Ryosuke Niwa.
+
+        * js/dom/document-write-in-error-event-expected.txt: Added.
+        * js/dom/document-write-in-error-event.html: Added.
+        * js/dom/document-write-in-load-event-expected.txt: Added.
+        * js/dom/document-write-in-load-event.html: Added.
+        * js/dom/script-tests/dummy.js: Added.
+
</ins><span class="cx"> 2016-09-08  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add support for HTMLIframeElement.allowFullscreen attribute
</span></span></pre></div>
<a id="trunkLayoutTestsjsdomdocumentwriteinerroreventexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/document-write-in-error-event-expected.txt (0 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/document-write-in-error-event-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/document-write-in-error-event-expected.txt        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdomdocumentwriteinerroreventhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/document-write-in-error-event.html (0 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/document-write-in-error-event.html                                (rev 0)
+++ trunk/LayoutTests/js/dom/document-write-in-error-event.html        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+&lt;!DOCTYPE HTML&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;loaded()&quot;&gt;
+&lt;script&gt;
+    window.jsTestIsAsync = true;
+    function loaded() {
+        let script = document.createElement(&quot;script&quot;);
+        script.src = &quot;script-tests/not-found.js&quot;;
+        script.addEventListener('error', function () {
+            document.write(&quot;&lt;script&gt;finishJSTest()&lt;\/script&gt;&quot;);
+        }, false);
+        document.body.appendChild(script);
+    }
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdomdocumentwriteinloadeventexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/document-write-in-load-event-expected.txt (0 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/document-write-in-load-event-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/document-write-in-load-event-expected.txt        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -0,0 +1,4 @@
</span><ins>+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdomdocumentwriteinloadeventhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/document-write-in-load-event.html (0 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/document-write-in-load-event.html                                (rev 0)
+++ trunk/LayoutTests/js/dom/document-write-in-load-event.html        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+&lt;!DOCTYPE HTML&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;loaded()&quot;&gt;
+&lt;script&gt;
+    window.jsTestIsAsync = true;
+    function loaded() {
+        let script = document.createElement(&quot;script&quot;);
+        script.src = &quot;script-tests/dummy.js&quot;;
+        script.addEventListener('load', function () {
+            document.write(&quot;&lt;script&gt;finishJSTest()&lt;\/script&gt;&quot;);
+        }, false);
+        document.body.appendChild(script);
+    }
+&lt;/script&gt;
+&lt;script src=&quot;../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdomscripttestsdummyjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/script-tests/dummy.js (0 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/script-tests/dummy.js                                (rev 0)
+++ trunk/LayoutTests/js/dom/script-tests/dummy.js        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -0,0 +1 @@
</span><ins>+// Do nothing.
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/ChangeLog        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -1,5 +1,52 @@
</span><span class="cx"> 2016-09-08  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
</span><span class="cx"> 
</span><ins>+        ScriptRunner should be driven by PendingScript rather than ScriptElement
+        https://bugs.webkit.org/show_bug.cgi?id=161726
+
+        Reviewed by Ryosuke Niwa.
+
+        Tests: js/dom/document-write-in-error-event.html
+               js/dom/document-write-in-load-event.html
+
+        ScriptRunner is driven by ScriptElement::notifyFinished. While ScriptRunner is driven by this,
+        HTMLScriptRunner does not use it. Instead, HTMLScriptRunner uses PendingScriptClient. As a result,
+        ScriptElement::notifyFinished is used only when the script is annotated with &quot;defer&quot; or &quot;async&quot;
+        while all the external script will load the LoadableScript. It is confusing.
+        This patch removes ScriptElement::notifyFinished and use PendingScript's observability
+        in ScriptRunner instead.
+
+        This patch also fixes the behavior about ignore-destructive-writes counter[1]. When dispatching
+        the load and error events, this ignore-destructive-writes counter should not be incremeneted by
+        this execution. The added tests ensure this behavior.
+
+        [1]: https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block
+
+        * dom/ScriptElement.cpp: Drop LoadableScriptClient interface.
+        (WebCore::ScriptElement::prepareScript): Do not use addClient. ScriptRunner use PendingScript::{setClient,clearClient} instead.
+        (WebCore::ScriptElement::executeScriptForScriptRunner): IgnoreDestructiveWriteCountIncrementer will be done in ScriptElement::executeScript.
+        So no need to do it here, that's duplicated.
+        (WebCore::ScriptElement::~ScriptElement): Deleted. ScriptElement does not use addClient/removeClient.
+        (WebCore::ScriptElement::stopLoadRequest): Deleted.
+        (WebCore::ScriptElement::executeScriptForHTMLScriptRunner): Deleted. executeScriptForHTMLScriptRunner and executeScriptForScriptRunner are
+        merged into executeScriptForRunner.
+        (WebCore::ScriptElement::notifyFinished): Deleted.
+        * dom/ScriptElement.h:
+        (WebCore::ScriptElement::~ScriptElement):
+        (WebCore::ScriptElement::willExecuteInOrder): Used in ScriptRunner to determine whether the script is async or defer.
+        (WebCore::ScriptElement::willExecuteWhenDocumentFinishedParsing): Deleted.
+        * dom/ScriptRunner.cpp:
+        (WebCore::ScriptRunner::~ScriptRunner): HashSet's iterator will return `const PendingScript&amp;`.
+        Another option is using HashSet&lt;RefPtr&lt;PendingScript&gt;&gt;. Here, we use a little bit weired const_cast.
+        (WebCore::ScriptRunner::queueScriptForExecution): Use PendingScript::setClient to wait loading.
+        (WebCore::ScriptRunner::notifyFinished): Notify the script ready here.
+        (WebCore::ScriptRunner::timerFired): Use executeScriptForScriptRunner.
+        (WebCore::ScriptRunner::notifyScriptReady): Deleted.
+        * dom/ScriptRunner.h:
+        * html/parser/HTMLScriptRunner.cpp:
+        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent): Use executeScriptForScriptRunner.
+
+2016-09-08  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
</ins><span class="cx">         [WTF] HashTable's rehash is not compatible to Ref&lt;T&gt; and ASan
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=161763
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.cpp        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -75,11 +75,6 @@
</span><span class="cx">         m_startLineNumber = m_element.document().scriptableDocumentParser()-&gt;textPosition().m_line;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ScriptElement::~ScriptElement()
-{
-    stopLoadRequest();
-}
-
</del><span class="cx"> bool ScriptElement::shouldCallFinishedInsertingSubtree(ContainerNode&amp; insertionPoint)
</span><span class="cx"> {
</span><span class="cx">     return insertionPoint.inDocument() &amp;&amp; !m_parserInserted;
</span><span class="lines">@@ -245,11 +240,9 @@
</span><span class="cx">         ASSERT(m_loadableScript);
</span><span class="cx">         m_willExecuteInOrder = true;
</span><span class="cx">         document.scriptRunner()-&gt;queueScriptForExecution(this, *m_loadableScript, ScriptRunner::IN_ORDER_EXECUTION);
</span><del>-        m_loadableScript-&gt;addClient(*this);
</del><span class="cx">     } else if (hasSourceAttribute()) {
</span><span class="cx">         ASSERT(m_loadableScript);
</span><span class="cx">         m_element.document().scriptRunner()-&gt;queueScriptForExecution(this, *m_loadableScript, ScriptRunner::ASYNC_EXECUTION);
</span><del>-        m_loadableScript-&gt;addClient(*this);
</del><span class="cx">     } else {
</span><span class="cx">         // Reset line numbering for nested writes.
</span><span class="cx">         TextPosition position = document.isInDocumentWrite() ? TextPosition() : scriptStartPosition;
</span><span class="lines">@@ -336,15 +329,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptElement::stopLoadRequest()
-{
-    if (m_loadableScript) {
-        if (!m_willBeParserExecuted)
-            m_loadableScript-&gt;removeClient(*this);
-        m_loadableScript = nullptr;
-    }
-}
-
</del><span class="cx"> void ScriptElement::executeScriptAndDispatchEvent(LoadableScript&amp; loadableScript)
</span><span class="cx"> {
</span><span class="cx">     if (Optional&lt;LoadableScript::Error&gt; error = loadableScript.wasErrored()) {
</span><span class="lines">@@ -358,16 +342,8 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptElement::executeScriptForScriptRunner(LoadableScript&amp; loadableScript)
</del><ins>+void ScriptElement::executeScriptForScriptRunner(PendingScript&amp; pendingScript)
</ins><span class="cx"> {
</span><del>-    ASSERT(!m_willBeParserExecuted);
-    executeScriptAndDispatchEvent(loadableScript);
-    loadableScript.removeClient(*this);
-}
-
-void ScriptElement::executeScriptForHTMLScriptRunner(PendingScript&amp; pendingScript)
-{
-    IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(&amp;m_element.document());
</del><span class="cx">     if (auto* loadableScript = pendingScript.loadableScript())
</span><span class="cx">         executeScriptAndDispatchEvent(*loadableScript);
</span><span class="cx">     else {
</span><span class="lines">@@ -377,25 +353,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptElement::notifyFinished(LoadableScript&amp;)
-{
-    ASSERT(!m_willBeParserExecuted);
-
-    // LoadableScript possibly invokes this notifyFinished() more than
-    // once because ScriptElement doesn't unsubscribe itself from
-    // LoadableScript here and does it in execute() instead.
-    // We use m_loadableScript to check if this function is already called.
-    if (!m_loadableScript)
-        return;
-
-    if (m_willExecuteInOrder)
-        m_element.document().scriptRunner()-&gt;notifyScriptReady(this, ScriptRunner::IN_ORDER_EXECUTION);
-    else
-        m_element.document().scriptRunner()-&gt;notifyScriptReady(this, ScriptRunner::ASYNC_EXECUTION);
-
-    m_loadableScript = nullptr;
-}
-
</del><span class="cx"> bool ScriptElement::ignoresLoadRequest() const
</span><span class="cx"> {
</span><span class="cx">     return m_alreadyStarted || m_isExternalScript || m_parserInserted || !m_element.inDocument();
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptElement.h (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.h        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/dom/ScriptElement.h        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -38,9 +38,9 @@
</span><span class="cx"> class ScriptElement;
</span><span class="cx"> class ScriptSourceCode;
</span><span class="cx"> 
</span><del>-class ScriptElement : private LoadableScriptClient {
</del><ins>+class ScriptElement {
</ins><span class="cx"> public:
</span><del>-    virtual ~ScriptElement();
</del><ins>+    virtual ~ScriptElement() { }
</ins><span class="cx"> 
</span><span class="cx">     Element&amp; element() { return m_element; }
</span><span class="cx">     const Element&amp; element() const { return m_element; }
</span><span class="lines">@@ -52,8 +52,7 @@
</span><span class="cx">     WEBCORE_EXPORT String scriptContent() const;
</span><span class="cx">     void executeScript(const ScriptSourceCode&amp;);
</span><span class="cx"> 
</span><del>-    void executeScriptForScriptRunner(LoadableScript&amp;);
-    void executeScriptForHTMLScriptRunner(PendingScript&amp;);
</del><ins>+    void executeScriptForScriptRunner(PendingScript&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // XML parser calls these
</span><span class="cx">     virtual void dispatchLoadEvent() = 0;
</span><span class="lines">@@ -63,6 +62,7 @@
</span><span class="cx">     bool willBeParserExecuted() const { return m_willBeParserExecuted; }
</span><span class="cx">     bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; }
</span><span class="cx">     bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWhenDocumentFinishedParsing; }
</span><ins>+    bool willExecuteInOrder() const { return m_willExecuteInOrder; }
</ins><span class="cx">     LoadableScript* loadableScript() { return m_loadableScript.get(); }
</span><span class="cx"> 
</span><span class="cx"> protected:
</span><span class="lines">@@ -92,10 +92,7 @@
</span><span class="cx">     CachedResourceHandle&lt;CachedScript&gt; requestScriptWithCache(const URL&amp;, const String&amp; nonceAttribute, const String&amp; crossoriginAttribute);
</span><span class="cx"> 
</span><span class="cx">     bool requestClassicScript(const String&amp; sourceURL);
</span><del>-    void stopLoadRequest();
</del><span class="cx"> 
</span><del>-    void notifyFinished(LoadableScript&amp;) override;
-
</del><span class="cx">     virtual String sourceAttributeValue() const = 0;
</span><span class="cx">     virtual String charsetAttributeValue() const = 0;
</span><span class="cx">     virtual String typeAttributeValue() const = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptRunner.cpp (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -40,12 +40,20 @@
</span><span class="cx"> 
</span><span class="cx"> ScriptRunner::~ScriptRunner()
</span><span class="cx"> {
</span><del>-    for (size_t i = 0; i &lt; m_scriptsToExecuteSoon.size(); ++i)
</del><ins>+    for (auto&amp; pendingScript : m_scriptsToExecuteSoon) {
+        UNUSED_PARAM(pendingScript);
</ins><span class="cx">         m_document.decrementLoadEventDelayCount();
</span><del>-    for (size_t i = 0; i &lt; m_scriptsToExecuteInOrder.size(); ++i)
</del><ins>+    }
+    for (auto&amp; pendingScript : m_scriptsToExecuteInOrder) {
+        if (pendingScript-&gt;watchingForLoad())
+            pendingScript-&gt;clearClient();
</ins><span class="cx">         m_document.decrementLoadEventDelayCount();
</span><del>-    for (unsigned i = 0; i &lt; m_pendingAsyncScripts.size(); ++i)
</del><ins>+    }
+    for (auto&amp; pendingScript : m_pendingAsyncScripts) {
+        if (pendingScript-&gt;watchingForLoad())
+            const_cast&lt;PendingScript&amp;&gt;(pendingScript.get()).clearClient();
</ins><span class="cx">         m_document.decrementLoadEventDelayCount();
</span><ins>+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScriptRunner::queueScriptForExecution(ScriptElement* scriptElement, LoadableScript&amp; loadableScript, ExecutionType executionType)
</span><span class="lines">@@ -57,15 +65,17 @@
</span><span class="cx"> 
</span><span class="cx">     m_document.incrementLoadEventDelayCount();
</span><span class="cx"> 
</span><ins>+    Ref&lt;PendingScript&gt; pendingScript = PendingScript::create(element, loadableScript);
</ins><span class="cx">     switch (executionType) {
</span><span class="cx">     case ASYNC_EXECUTION:
</span><del>-        m_pendingAsyncScripts.add(scriptElement, PendingScript::create(element, loadableScript));
</del><ins>+        m_pendingAsyncScripts.add(pendingScript.copyRef());
</ins><span class="cx">         break;
</span><span class="cx"> 
</span><span class="cx">     case IN_ORDER_EXECUTION:
</span><del>-        m_scriptsToExecuteInOrder.append(PendingScript::create(element, loadableScript));
</del><ins>+        m_scriptsToExecuteInOrder.append(pendingScript.copyRef());
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><ins>+    pendingScript-&gt;setClient(this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void ScriptRunner::suspend()
</span><span class="lines">@@ -79,18 +89,17 @@
</span><span class="cx">         m_timer.startOneShot(0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptRunner::notifyScriptReady(ScriptElement* scriptElement, ExecutionType executionType)
</del><ins>+void ScriptRunner::notifyFinished(PendingScript&amp; pendingScript)
</ins><span class="cx"> {
</span><del>-    switch (executionType) {
-    case ASYNC_EXECUTION:
-        ASSERT(m_pendingAsyncScripts.contains(scriptElement));
-        m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptElement)-&gt;ptr());
-        break;
-
-    case IN_ORDER_EXECUTION:
</del><ins>+    auto* scriptElement = toScriptElementIfPossible(&amp;pendingScript.element());
+    ASSERT(scriptElement);
+    if (scriptElement-&gt;willExecuteInOrder())
</ins><span class="cx">         ASSERT(!m_scriptsToExecuteInOrder.isEmpty());
</span><del>-        break;
</del><ins>+    else {
+        ASSERT(m_pendingAsyncScripts.contains(pendingScript));
+        m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(pendingScript)-&gt;ptr());
</ins><span class="cx">     }
</span><ins>+    pendingScript.clearClient();
</ins><span class="cx">     m_timer.startOneShot(0);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -116,7 +125,7 @@
</span><span class="cx">         auto* scriptElement = toScriptElementIfPossible(&amp;script-&gt;element());
</span><span class="cx">         ASSERT(scriptElement);
</span><span class="cx">         ASSERT(script-&gt;needsLoading());
</span><del>-        scriptElement-&gt;executeScriptForScriptRunner(*script-&gt;loadableScript());
</del><ins>+        scriptElement-&gt;executeScriptForScriptRunner(*script);
</ins><span class="cx">         m_document.decrementLoadEventDelayCount();
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptRunnerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptRunner.h (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptRunner.h        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/dom/ScriptRunner.h        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -25,8 +25,9 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><ins>+#include &quot;PendingScriptClient.h&quot;
</ins><span class="cx"> #include &quot;Timer.h&quot;
</span><del>-#include &lt;wtf/HashMap.h&gt;
</del><ins>+#include &lt;wtf/HashSet.h&gt;
</ins><span class="cx"> #include &lt;wtf/Noncopyable.h&gt;
</span><span class="cx"> #include &lt;wtf/Vector.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -37,7 +38,7 @@
</span><span class="cx"> class ScriptElement;
</span><span class="cx"> class LoadableScript;
</span><span class="cx"> 
</span><del>-class ScriptRunner {
</del><ins>+class ScriptRunner : private PendingScriptClient {
</ins><span class="cx">     WTF_MAKE_NONCOPYABLE(ScriptRunner); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="cx">     explicit ScriptRunner(Document&amp;);
</span><span class="lines">@@ -53,10 +54,12 @@
</span><span class="cx"> private:
</span><span class="cx">     void timerFired();
</span><span class="cx"> 
</span><ins>+    void notifyFinished(PendingScript&amp;) override;
+
</ins><span class="cx">     Document&amp; m_document;
</span><span class="cx">     Vector&lt;Ref&lt;PendingScript&gt;&gt; m_scriptsToExecuteInOrder;
</span><span class="cx">     Vector&lt;RefPtr&lt;PendingScript&gt;&gt; m_scriptsToExecuteSoon; // http://www.whatwg.org/specs/web-apps/current-work/#set-of-scripts-that-will-execute-as-soon-as-possible
</span><del>-    HashMap&lt;ScriptElement*, Ref&lt;PendingScript&gt;&gt; m_pendingAsyncScripts;
</del><ins>+    HashSet&lt;Ref&lt;PendingScript&gt;&gt; m_pendingAsyncScripts;
</ins><span class="cx">     Timer m_timer;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLScriptRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp (205694 => 205695)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-09-09 05:11:25 UTC (rev 205694)
+++ trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-09-09 05:20:17 UTC (rev 205695)
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx"> 
</span><span class="cx">     if (auto* scriptElement = toScriptElementIfPossible(&amp;pendingScript-&gt;element())) {
</span><span class="cx">         NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
</span><del>-        scriptElement-&gt;executeScriptForHTMLScriptRunner(*pendingScript);
</del><ins>+        scriptElement-&gt;executeScriptForScriptRunner(*pendingScript);
</ins><span class="cx">     }
</span><span class="cx">     ASSERT(!isExecutingScript());
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>