<!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>[208840] 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/208840">208840</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2016-11-16 22:47:31 -0800 (Wed, 16 Nov 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WebCore] Clean up script loading code in XML
https://bugs.webkit.org/show_bug.cgi?id=161651

Reviewed by Ryosuke Niwa.

Source/WebCore:

This patch cleans up XML document script handling by using PendingScript.
Previously, we directly used CachedScript. But it is not good since we
have PendingScript wrapper.

We also disable ES6 modules for non HTML document. While ES6 modules tag
requires &quot;defer&quot; semantics, &quot;defer&quot; semantics is not implemented in non
HTML documents. And ES6 module tag is only specified in whatwg HTML spec.

* dom/LoadableClassicScript.cpp:
(WebCore::LoadableClassicScript::execute):
* dom/ScriptElement.cpp:
(WebCore::ScriptElement::determineScriptType):
(WebCore::ScriptElement::prepareScript):
(WebCore::ScriptElement::executeClassicScript):
(WebCore::ScriptElement::executePendingScript):
(WebCore::ScriptElement::executeScript): Deleted.
(WebCore::ScriptElement::executeScriptForScriptRunner): Deleted.
* dom/ScriptElement.h:
* dom/ScriptRunner.cpp:
(WebCore::ScriptRunner::timerFired):
* html/parser/HTMLDocumentParser.cpp:
* html/parser/HTMLScriptRunner.cpp:
(WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
(WebCore::HTMLScriptRunner::runScript):
* xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::notifyFinished):
* xml/parser/XMLDocumentParser.h:
* xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::XMLDocumentParser):
(WebCore::XMLDocumentParser::~XMLDocumentParser):
(WebCore::XMLDocumentParser::endElementNs):

LayoutTests:

Add tests that ensure modules are not executed in XHTML documents.

* js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt: Added.
* js/dom/modules/module-inline-dynamic-in-xhtml.xhtml: Added.
* js/dom/modules/module-inline-simple-in-xhtml-expected.txt: Added.
* js/dom/modules/module-inline-simple-in-xhtml.xhtml: Added.
* js/dom/modules/module-src-dynamic-in-xhtml-expected.txt: Added.
* js/dom/modules/module-src-dynamic-in-xhtml.xhtml: Added.
* js/dom/modules/module-src-simple-in-xhtml-expected.txt: Added.
* js/dom/modules/module-src-simple-in-xhtml.xhtml: 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="#trunkSourceWebCoredomLoadableClassicScriptcpp">trunk/Source/WebCore/dom/LoadableClassicScript.cpp</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="#trunkSourceWebCorehtmlparserHTMLDocumentParsercpp">trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCorehtmlparserHTMLScriptRunnercpp">trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParsercpp">trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParserh">trunk/Source/WebCore/xml/parser/XMLDocumentParser.h</a></li>
<li><a href="#trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp">trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsjsdommodulesmoduleinlinedynamicinxhtmlexpectedtxt">trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmoduleinlinedynamicinxhtmlxhtml">trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml.xhtml</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmoduleinlinesimpleinxhtmlexpectedtxt">trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmoduleinlinesimpleinxhtmlxhtml">trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml.xhtml</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmodulesrcdynamicinxhtmlexpectedtxt">trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmodulesrcdynamicinxhtmlxhtml">trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml.xhtml</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmodulesrcsimpleinxhtmlexpectedtxt">trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml-expected.txt</a></li>
<li><a href="#trunkLayoutTestsjsdommodulesmodulesrcsimpleinxhtmlxhtml">trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml.xhtml</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/LayoutTests/ChangeLog        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-11-16  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        [WebCore] Clean up script loading code in XML
+        https://bugs.webkit.org/show_bug.cgi?id=161651
+
+        Reviewed by Ryosuke Niwa.
+
+        Add tests that ensure modules are not executed in XHTML documents.
+
+        * js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt: Added.
+        * js/dom/modules/module-inline-dynamic-in-xhtml.xhtml: Added.
+        * js/dom/modules/module-inline-simple-in-xhtml-expected.txt: Added.
+        * js/dom/modules/module-inline-simple-in-xhtml.xhtml: Added.
+        * js/dom/modules/module-src-dynamic-in-xhtml-expected.txt: Added.
+        * js/dom/modules/module-src-dynamic-in-xhtml.xhtml: Added.
+        * js/dom/modules/module-src-simple-in-xhtml-expected.txt: Added.
+        * js/dom/modules/module-src-simple-in-xhtml.xhtml: Added.
+
</ins><span class="cx"> 2016-11-16  Ryosuke Niwa  &lt;rniwa@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r208082): 1% Speedometer regression on iOS
</span></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmoduleinlinedynamicinxhtmlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml-expected.txt        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Test dynamically added inlined module does not work in XHTML document.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Module is not executed yet.
+PASS window.exportedCocoa is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmoduleinlinedynamicinxhtmlxhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml.xhtml (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml.xhtml                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-inline-dynamic-in-xhtml.xhtml        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,39 @@
</span><ins>+&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;DTD/xhtml1-strict.dtd&quot;&gt;
+&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+description('Test dynamically added inlined module does not work in XHTML document.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+debug('Module is not executed yet.');
+(function () {
+    var element = document.createElement(&quot;script&quot;);
+    element.textContent = `
+        import Cocoa from &quot;./script-tests/module-inline-dynamic.js&quot;;
+        var cocoa = new Cocoa();
+
+        debug(&quot;Module execution is confined in the module environment.&quot;);
+        shouldBeEqualToString(&quot;typeof cocoa&quot;, &quot;undefined&quot;);
+
+        window.exportedCocoa = cocoa;
+        shouldBeEqualToString(&quot;typeof exportedCocoa&quot;, &quot;object&quot;);
+        shouldBeEqualToString(&quot;exportedCocoa.taste()&quot;, &quot;awesome&quot;);
+        finishJSTest();
+    `;
+    element.type = &quot;module&quot;;
+    document.body.appendChild(element);
+    setTimeout(function () {
+        shouldBe(`window.exportedCocoa`, `undefined`);
+        finishJSTest();
+    }, 100);
+} ());
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmoduleinlinesimpleinxhtmlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml-expected.txt (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml-expected.txt        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Test inlined module does not work in XHTML document.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Module is not executed yet.
+PASS window.exportedCocoa is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmoduleinlinesimpleinxhtmlxhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml.xhtml (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml.xhtml                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-inline-simple-in-xhtml.xhtml        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;DTD/xhtml1-strict.dtd&quot;&gt;
+&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+description('Test inlined module does not work in XHTML document.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+&lt;/script&gt;
+&lt;script&gt;
+debug('Module is not executed yet.');
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;script type=&quot;module&quot;&gt;
+import Cocoa from &quot;./script-tests/module-inline-simple.js&quot;;
+var cocoa = new Cocoa();
+
+debug(&quot;Module execution is confined in the module environment.&quot;);
+shouldBeEqualToString(&quot;typeof cocoa&quot;, &quot;undefined&quot;);
+
+window.exportedCocoa = cocoa;
+shouldBeEqualToString(&quot;typeof exportedCocoa&quot;, &quot;object&quot;);
+shouldBeEqualToString(&quot;exportedCocoa.taste()&quot;, &quot;awesome&quot;);
+finishJSTest();
+&lt;/script&gt;
+&lt;script&gt;
+window.addEventListener('load', function () {
+    shouldBe(`window.exportedCocoa`, `undefined`);
+    finishJSTest();
+});
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmodulesrcdynamicinxhtmlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml-expected.txt (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml-expected.txt        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Test dynamically added module with &quot;src&quot; attribute does not work in XHTML document.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Module is not executed yet.
+PASS window.exportedCocoa is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmodulesrcdynamicinxhtmlxhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml.xhtml (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml.xhtml                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-src-dynamic-in-xhtml.xhtml        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,28 @@
</span><ins>+&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;DTD/xhtml1-strict.dtd&quot;&gt;
+&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+description('Test dynamically added module with &quot;src&quot; attribute does not work in XHTML document.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+debug('Module is not executed yet.');
+(function () {
+    var element = document.createElement('script');
+    element.type = 'module';
+    element.src = './script-tests/module-src-dynamic.js';
+    document.body.appendChild(element);
+    setTimeout(function () {
+        shouldBe(`window.exportedCocoa`, `undefined`);
+        finishJSTest();
+    }, 100);
+}());
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmodulesrcsimpleinxhtmlexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml-expected.txt (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml-expected.txt                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml-expected.txt        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Test module with &quot;src&quot; attribute does not work in XHTML document.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+Module is not executed yet.
+PASS window.exportedCocoa is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdommodulesmodulesrcsimpleinxhtmlxhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml.xhtml (0 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml.xhtml                                (rev 0)
+++ trunk/LayoutTests/js/dom/modules/module-src-simple-in-xhtml.xhtml        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;DTD/xhtml1-strict.dtd&quot;&gt;
+&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../../resources/js-test-pre.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+description('Test module with &quot;src&quot; attribute does not work in XHTML document.');
+
+// Module will be executed asynchronously.
+window.jsTestIsAsync = true;
+&lt;/script&gt;
+&lt;script&gt;
+debug('Module is not executed yet.');
+&lt;/script&gt;
+&lt;script src=&quot;../../../resources/js-test-post.js&quot;&gt;&lt;/script&gt;
+&lt;script type=&quot;module&quot; src=&quot;./script-tests/module-src-simple.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+window.addEventListener('load', function () {
+    shouldBe(`window.exportedCocoa`, `undefined`);
+    finishJSTest();
+});
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/ChangeLog        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -1,3 +1,42 @@
</span><ins>+2016-11-16  Yusuke Suzuki  &lt;utatane.tea@gmail.com&gt;
+
+        [WebCore] Clean up script loading code in XML
+        https://bugs.webkit.org/show_bug.cgi?id=161651
+
+        Reviewed by Ryosuke Niwa.
+
+        This patch cleans up XML document script handling by using PendingScript.
+        Previously, we directly used CachedScript. But it is not good since we
+        have PendingScript wrapper.
+
+        We also disable ES6 modules for non HTML document. While ES6 modules tag
+        requires &quot;defer&quot; semantics, &quot;defer&quot; semantics is not implemented in non
+        HTML documents. And ES6 module tag is only specified in whatwg HTML spec.
+
+        * dom/LoadableClassicScript.cpp:
+        (WebCore::LoadableClassicScript::execute):
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::determineScriptType):
+        (WebCore::ScriptElement::prepareScript):
+        (WebCore::ScriptElement::executeClassicScript):
+        (WebCore::ScriptElement::executePendingScript):
+        (WebCore::ScriptElement::executeScript): Deleted.
+        (WebCore::ScriptElement::executeScriptForScriptRunner): Deleted.
+        * dom/ScriptElement.h:
+        * dom/ScriptRunner.cpp:
+        (WebCore::ScriptRunner::timerFired):
+        * html/parser/HTMLDocumentParser.cpp:
+        * html/parser/HTMLScriptRunner.cpp:
+        (WebCore::HTMLScriptRunner::executePendingScriptAndDispatchEvent):
+        (WebCore::HTMLScriptRunner::runScript):
+        * xml/parser/XMLDocumentParser.cpp:
+        (WebCore::XMLDocumentParser::notifyFinished):
+        * xml/parser/XMLDocumentParser.h:
+        * xml/parser/XMLDocumentParserLibxml2.cpp:
+        (WebCore::XMLDocumentParser::XMLDocumentParser):
+        (WebCore::XMLDocumentParser::~XMLDocumentParser):
+        (WebCore::XMLDocumentParser::endElementNs):
+
</ins><span class="cx"> 2016-11-16  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Add Node::isDescendantOf() overload that takes in a reference
</span></span></pre></div>
<a id="trunkSourceWebCoredomLoadableClassicScriptcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/LoadableClassicScript.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/LoadableClassicScript.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/dom/LoadableClassicScript.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx"> void LoadableClassicScript::execute(ScriptElement&amp; scriptElement)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!error());
</span><del>-    scriptElement.executeScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program));
</del><ins>+    scriptElement.executeClassicScript(ScriptSourceCode(m_cachedScript.get(), JSC::SourceProviderSourceType::Program));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -163,6 +163,13 @@
</span><span class="cx">     if (supportLegacyTypes == AllowLegacyTypeInTypeAttribute &amp;&amp; isLegacySupportedJavaScriptLanguage(type))
</span><span class="cx">         return ScriptType::Classic;
</span><span class="cx"> 
</span><ins>+    // FIXME: XHTML spec defines &quot;defer&quot; attribute. But WebKit does not implement it for a long time.
+    // And module tag also uses defer attribute semantics. We disable script type=&quot;module&quot; for non HTML document.
+    // Once &quot;defer&quot; is implemented, we can reconsider enabling modules in XHTML.
+    // https://bugs.webkit.org/show_bug.cgi?id=123387
+    if (!m_element.document().isHTMLDocument())
+        return Nullopt;
+
</ins><span class="cx">     auto* settings = m_element.document().settings();
</span><span class="cx">     if (!settings || !settings-&gt;es6ModulesEnabled())
</span><span class="cx">         return Nullopt;
</span><span class="lines">@@ -271,7 +278,7 @@
</span><span class="cx">     } else {
</span><span class="cx">         ASSERT(scriptType == ScriptType::Classic);
</span><span class="cx">         TextPosition position = document.isInDocumentWrite() ? TextPosition() : scriptStartPosition;
</span><del>-        executeScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program));
</del><ins>+        executeClassicScript(ScriptSourceCode(scriptContent(), document.url(), position, JSC::SourceProviderSourceType::Program));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     return true;
</span><span class="lines">@@ -386,7 +393,7 @@
</span><span class="cx">     return document.cachedResourceLoader().requestScript(WTFMove(request));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptElement::executeScript(const ScriptSourceCode&amp; sourceCode)
</del><ins>+void ScriptElement::executeClassicScript(const ScriptSourceCode&amp; sourceCode)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(m_alreadyStarted);
</span><span class="cx"> 
</span><span class="lines">@@ -442,14 +449,14 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ScriptElement::executeScriptForScriptRunner(PendingScript&amp; pendingScript)
</del><ins>+void ScriptElement::executePendingScript(PendingScript&amp; pendingScript)
</ins><span class="cx"> {
</span><span class="cx">     if (auto* loadableScript = pendingScript.loadableScript())
</span><span class="cx">         executeScriptAndDispatchEvent(*loadableScript);
</span><span class="cx">     else {
</span><span class="cx">         ASSERT(!pendingScript.error());
</span><del>-        JSC::SourceProviderSourceType sourceType = scriptType() == ScriptType::Module ? JSC::SourceProviderSourceType::Module : JSC::SourceProviderSourceType::Program;
-        executeScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), sourceType));
</del><ins>+        ASSERT_WITH_MESSAGE(scriptType() == ScriptType::Classic, &quot;Module script always have a loadableScript pointer.&quot;);
+        executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program));
</ins><span class="cx">         dispatchLoadEvent();
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptElementh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptElement.h (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.h        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/dom/ScriptElement.h        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -51,10 +51,10 @@
</span><span class="cx"> 
</span><span class="cx">     String scriptCharset() const { return m_characterEncoding; }
</span><span class="cx">     WEBCORE_EXPORT String scriptContent() const;
</span><del>-    void executeScript(const ScriptSourceCode&amp;);
</del><ins>+    void executeClassicScript(const ScriptSourceCode&amp;);
</ins><span class="cx">     void executeModuleScript(CachedModuleScript&amp;);
</span><span class="cx"> 
</span><del>-    void executeScriptForScriptRunner(PendingScript&amp;);
</del><ins>+    void executePendingScript(PendingScript&amp;);
</ins><span class="cx"> 
</span><span class="cx">     // XML parser calls these
</span><span class="cx">     virtual void dispatchLoadEvent() = 0;
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptRunner.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -125,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);
</del><ins>+        scriptElement-&gt;executePendingScript(*script);
</ins><span class="cx">         m_document.decrementLoadEventDelayCount();
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -27,7 +27,6 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;HTMLDocumentParser.h&quot;
</span><span class="cx"> 
</span><del>-#include &quot;CachedScript.h&quot;
</del><span class="cx"> #include &quot;DocumentFragment.h&quot;
</span><span class="cx"> #include &quot;Frame.h&quot;
</span><span class="cx"> #include &quot;HTMLDocument.h&quot;
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlparserHTMLScriptRunnercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</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;executeScriptForScriptRunner(*pendingScript);
</del><ins>+        scriptElement-&gt;executePendingScript(*pendingScript);
</ins><span class="cx">     }
</span><span class="cx">     ASSERT(!isExecutingScript());
</span><span class="cx"> }
</span><span class="lines">@@ -275,7 +275,7 @@
</span><span class="cx">             if (m_scriptNestingLevel == 1)
</span><span class="cx">                 m_parserBlockingScript = PendingScript::create(*script, scriptStartPosition);
</span><span class="cx">             else
</span><del>-                scriptElement-&gt;executeScript(ScriptSourceCode(script-&gt;textContent(), documentURLForScriptExecution(m_document), scriptStartPosition));
</del><ins>+                scriptElement-&gt;executeClassicScript(ScriptSourceCode(script-&gt;textContent(), documentURLForScriptExecution(m_document), scriptStartPosition));
</ins><span class="cx">         } else
</span><span class="cx">             requestParsingBlockingScript(script);
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -27,7 +27,6 @@
</span><span class="cx"> #include &quot;XMLDocumentParser.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CDATASection.h&quot;
</span><del>-#include &quot;CachedScript.h&quot;
</del><span class="cx"> #include &quot;Comment.h&quot;
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="cx"> #include &quot;DocumentFragment.h&quot;
</span><span class="lines">@@ -39,6 +38,7 @@
</span><span class="cx"> #include &quot;HTMLNames.h&quot;
</span><span class="cx"> #include &quot;HTMLStyleElement.h&quot;
</span><span class="cx"> #include &quot;ImageLoader.h&quot;
</span><ins>+#include &quot;PendingScript.h&quot;
</ins><span class="cx"> #include &quot;ProcessingInstruction.h&quot;
</span><span class="cx"> #include &quot;ResourceError.h&quot;
</span><span class="cx"> #include &quot;ResourceRequest.h&quot;
</span><span class="lines">@@ -227,38 +227,19 @@
</span><span class="cx">     m_xmlErrors-&gt;insertErrorMessageBlock();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void XMLDocumentParser::notifyFinished(CachedResource&amp; unusedResource)
</del><ins>+void XMLDocumentParser::notifyFinished(PendingScript&amp; pendingScript)
</ins><span class="cx"> {
</span><del>-    ASSERT_UNUSED(unusedResource, &amp;unusedResource == m_pendingScript);
-    ASSERT(m_pendingScript-&gt;accessCount() &gt; 0);
</del><ins>+    ASSERT(&amp;pendingScript == m_pendingScript.get());
</ins><span class="cx"> 
</span><del>-    // FIXME: Support ES6 modules in XML document.
-    // https://bugs.webkit.org/show_bug.cgi?id=161651
-    ScriptSourceCode sourceCode(m_pendingScript.get(), JSC::SourceProviderSourceType::Program);
-    bool errorOccurred = m_pendingScript-&gt;errorOccurred();
-    bool wasCanceled = m_pendingScript-&gt;wasCanceled();
</del><ins>+    // JavaScript can detach this parser, make sure it's kept alive even if detached.
+    Ref&lt;XMLDocumentParser&gt; protectedThis(*this);
</ins><span class="cx"> 
</span><del>-    m_pendingScript-&gt;removeClient(*this);
</del><span class="cx">     m_pendingScript = nullptr;
</span><ins>+    pendingScript.clearClient();
</ins><span class="cx"> 
</span><del>-    RefPtr&lt;Element&gt; e = m_scriptElement;
-    m_scriptElement = nullptr;
</del><ins>+    auto&amp; scriptElement = *toScriptElementIfPossible(&amp;pendingScript.element());
+    scriptElement.executePendingScript(pendingScript);
</ins><span class="cx"> 
</span><del>-    ScriptElement* scriptElement = toScriptElementIfPossible(e.get());
-    ASSERT(scriptElement);
-
-    // JavaScript can detach this parser, make sure it's kept alive even if detached.
-    Ref&lt;XMLDocumentParser&gt; protectedThis(*this);
-    
-    if (errorOccurred)
-        scriptElement-&gt;dispatchErrorEvent();
-    else if (!wasCanceled) {
-        scriptElement-&gt;executeScript(sourceCode);
-        scriptElement-&gt;dispatchLoadEvent();
-    }
-
-    m_scriptElement = nullptr;
-
</del><span class="cx">     if (!isDetached() &amp;&amp; !m_requestingScript)
</span><span class="cx">         resumeParsing();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParserh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParser.h (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParser.h        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParser.h        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -24,9 +24,8 @@
</span><span class="cx"> 
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><del>-#include &quot;CachedResourceClient.h&quot;
-#include &quot;CachedResourceHandle.h&quot;
</del><span class="cx"> #include &quot;FragmentScriptingPermission.h&quot;
</span><ins>+#include &quot;PendingScriptClient.h&quot;
</ins><span class="cx"> #include &quot;ScriptableDocumentParser.h&quot;
</span><span class="cx"> #include &quot;SegmentedString.h&quot;
</span><span class="cx"> #include &quot;XMLErrors.h&quot;
</span><span class="lines">@@ -40,7 +39,6 @@
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> class ContainerNode;
</span><del>-class CachedScript;
</del><span class="cx"> class CachedResourceLoader;
</span><span class="cx"> class DocumentFragment;
</span><span class="cx"> class Document;
</span><span class="lines">@@ -47,6 +45,7 @@
</span><span class="cx"> class Element;
</span><span class="cx"> class FrameView;
</span><span class="cx"> class PendingCallbacks;
</span><ins>+class PendingScript;
</ins><span class="cx"> class Text;
</span><span class="cx"> 
</span><span class="cx">     class XMLParserContext : public RefCounted&lt;XMLParserContext&gt; {
</span><span class="lines">@@ -64,7 +63,7 @@
</span><span class="cx">         xmlParserCtxtPtr m_context;
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    class XMLDocumentParser final : public ScriptableDocumentParser, public CachedResourceClient {
</del><ins>+    class XMLDocumentParser final : public ScriptableDocumentParser, public PendingScriptClient {
</ins><span class="cx">         WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     public:
</span><span class="cx">         static Ref&lt;XMLDocumentParser&gt; create(Document&amp; document, FrameView* view)
</span><span class="lines">@@ -106,8 +105,7 @@
</span><span class="cx">         TextPosition textPosition() const override;
</span><span class="cx">         bool shouldAssociateConsoleMessagesWithTextPosition() const override;
</span><span class="cx"> 
</span><del>-        // from CachedResourceClient
-        void notifyFinished(CachedResource&amp;) final;
</del><ins>+        void notifyFinished(PendingScript&amp;) final;
</ins><span class="cx"> 
</span><span class="cx">         void end();
</span><span class="cx"> 
</span><span class="lines">@@ -178,8 +176,7 @@
</span><span class="cx"> 
</span><span class="cx">         std::unique_ptr&lt;XMLErrors&gt; m_xmlErrors;
</span><span class="cx"> 
</span><del>-        CachedResourceHandle&lt;CachedScript&gt; m_pendingScript;
-        RefPtr&lt;Element&gt; m_scriptElement;
</del><ins>+        RefPtr&lt;PendingScript&gt; m_pendingScript;
</ins><span class="cx">         TextPosition m_scriptStartPosition;
</span><span class="cx"> 
</span><span class="cx">         bool m_parsingFragment;
</span></span></pre></div>
<a id="trunkSourceWebCorexmlparserXMLDocumentParserLibxml2cpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp (208839 => 208840)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp        2016-11-17 06:24:13 UTC (rev 208839)
+++ trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp        2016-11-17 06:47:31 UTC (rev 208840)
</span><span class="lines">@@ -29,7 +29,6 @@
</span><span class="cx"> #include &quot;XMLDocumentParser.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;CDATASection.h&quot;
</span><del>-#include &quot;CachedScript.h&quot;
</del><span class="cx"> #include &quot;Comment.h&quot;
</span><span class="cx"> #include &quot;CachedResourceLoader.h&quot;
</span><span class="cx"> #include &quot;Document.h&quot;
</span><span class="lines">@@ -46,6 +45,7 @@
</span><span class="cx"> #include &quot;HTMLTemplateElement.h&quot;
</span><span class="cx"> #include &quot;LoadableClassicScript.h&quot;
</span><span class="cx"> #include &quot;Page.h&quot;
</span><ins>+#include &quot;PendingScript.h&quot;
</ins><span class="cx"> #include &quot;ProcessingInstruction.h&quot;
</span><span class="cx"> #include &quot;ResourceError.h&quot;
</span><span class="cx"> #include &quot;ResourceRequest.h&quot;
</span><span class="lines">@@ -588,7 +588,6 @@
</span><span class="cx">     , m_parserPaused(false)
</span><span class="cx">     , m_requestingScript(false)
</span><span class="cx">     , m_finishCalled(false)
</span><del>-    , m_pendingScript(nullptr)
</del><span class="cx">     , m_scriptStartPosition(TextPosition::belowRangePosition())
</span><span class="cx">     , m_parsingFragment(false)
</span><span class="cx"> {
</span><span class="lines">@@ -610,7 +609,6 @@
</span><span class="cx">     , m_parserPaused(false)
</span><span class="cx">     , m_requestingScript(false)
</span><span class="cx">     , m_finishCalled(false)
</span><del>-    , m_pendingScript(0)
</del><span class="cx">     , m_scriptStartPosition(TextPosition::belowRangePosition())
</span><span class="cx">     , m_parsingFragment(true)
</span><span class="cx"> {
</span><span class="lines">@@ -662,7 +660,7 @@
</span><span class="cx"> 
</span><span class="cx">     // FIXME: m_pendingScript handling should be moved into XMLDocumentParser.cpp!
</span><span class="cx">     if (m_pendingScript)
</span><del>-        m_pendingScript-&gt;removeClient(*this);
</del><ins>+        m_pendingScript-&gt;clearClient();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void XMLDocumentParser::doWrite(const String&amp; parseString)
</span><span class="lines">@@ -915,19 +913,15 @@
</span><span class="cx">         // the libxml2 and Qt XMLDocumentParser implementations.
</span><span class="cx"> 
</span><span class="cx">         if (scriptElement-&gt;readyToBeParserExecuted())
</span><del>-            scriptElement-&gt;executeScript(ScriptSourceCode(scriptElement-&gt;scriptContent(), document()-&gt;url(), m_scriptStartPosition));
-        else if (scriptElement-&gt;willBeParserExecuted() &amp;&amp; scriptElement-&gt;loadableScript() &amp;&amp; is&lt;LoadableClassicScript&gt;(*scriptElement-&gt;loadableScript())) {
-            // FIXME: Allow &quot;module&quot; scripts for XML documents.
-            // https://bugs.webkit.org/show_bug.cgi?id=161651
-            m_pendingScript = &amp;downcast&lt;LoadableClassicScript&gt;(*scriptElement-&gt;loadableScript()).cachedScript();
-            m_scriptElement = &amp;element;
-            m_pendingScript-&gt;addClient(*this);
</del><ins>+            scriptElement-&gt;executeClassicScript(ScriptSourceCode(scriptElement-&gt;scriptContent(), document()-&gt;url(), m_scriptStartPosition));
+        else if (scriptElement-&gt;willBeParserExecuted() &amp;&amp; scriptElement-&gt;loadableScript()) {
+            m_pendingScript = PendingScript::create(element, *scriptElement-&gt;loadableScript());
+            m_pendingScript-&gt;setClient(this);
</ins><span class="cx"> 
</span><del>-            // m_pendingScript will be 0 if script was already loaded and addClient() executed it.
</del><ins>+            // m_pendingScript will be nullptr if script was already loaded and setClient() executed it.
</ins><span class="cx">             if (m_pendingScript)
</span><span class="cx">                 pauseParsing();
</span><del>-        } else
-            m_scriptElement = nullptr;
</del><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         // JavaScript may have detached the parser
</span><span class="cx">         if (isDetached())
</span></span></pre>
</div>
</div>

</body>
</html>