<!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>[205652] 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/205652">205652</a></dd>
<dt>Author</dt> <dd>utatane.tea@gmail.com</dd>
<dt>Date</dt> <dd>2016-09-08 10:49:43 -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:
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 "defer" or "async"
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&`.
Another option is using HashSet<RefPtr<PendingScript>>. 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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/LayoutTests/ChangeLog        2016-09-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2016-09-08 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ 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-07 Simon Fraser <simon.fraser@apple.com>
</span><span class="cx">
</span><span class="cx"> Enable the <meter> element on iOS
</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 => 205652)</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-08 17:49:43 UTC (rev 205652)
</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 => 205652)</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-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body onload="loaded()">
+<script>
+ window.jsTestIsAsync = true;
+ function loaded() {
+ let script = document.createElement("script");
+ script.src = "script-tests/not-found.js";
+ script.addEventListener('error', function () {
+ document.write("<script>finishJSTest()<\/script>");
+ }, false);
+ document.body.appendChild(script);
+ }
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</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 => 205652)</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-08 17:49:43 UTC (rev 205652)
</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 => 205652)</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-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -0,0 +1,20 @@
</span><ins>+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../resources/js-test-pre.js"></script>
+</head>
+<body onload="loaded()">
+<script>
+ window.jsTestIsAsync = true;
+ function loaded() {
+ let script = document.createElement("script");
+ script.src = "script-tests/dummy.js";
+ script.addEventListener('load', function () {
+ document.write("<script>finishJSTest()<\/script>");
+ }, false);
+ document.body.appendChild(script);
+ }
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
</ins></span></pre></div>
<a id="trunkLayoutTestsjsdomscripttestsdummyjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/js/dom/script-tests/dummy.js (0 => 205652)</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-08 17:49:43 UTC (rev 205652)
</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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/ChangeLog        2016-09-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -1,3 +1,47 @@
</span><ins>+2016-09-08 Yusuke Suzuki <utatane.tea@gmail.com>
+
+ ScriptRunner should be driven by PendingScript rather than ScriptElement
+ https://bugs.webkit.org/show_bug.cgi?id=161726
+
+ Reviewed by Ryosuke Niwa.
+
+ 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 "defer" or "async"
+ 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&`.
+ Another option is using HashSet<RefPtr<PendingScript>>. 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.
+
</ins><span class="cx"> 2016-09-08 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Re-land r205580 after r205649 fixed the test failures
</span></span></pre></div>
<a id="trunkSourceWebCoredomScriptElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.cpp        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp        2016-09-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -75,11 +75,6 @@
</span><span class="cx"> m_startLineNumber = m_element.document().scriptableDocumentParser()->textPosition().m_line;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-ScriptElement::~ScriptElement()
-{
- stopLoadRequest();
-}
-
</del><span class="cx"> bool ScriptElement::shouldCallFinishedInsertingSubtree(ContainerNode& insertionPoint)
</span><span class="cx"> {
</span><span class="cx"> return insertionPoint.inDocument() && !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()->queueScriptForExecution(this, *m_loadableScript, ScriptRunner::IN_ORDER_EXECUTION);
</span><del>- m_loadableScript->addClient(*this);
</del><span class="cx"> } else if (hasSourceAttribute()) {
</span><span class="cx"> ASSERT(m_loadableScript);
</span><span class="cx"> m_element.document().scriptRunner()->queueScriptForExecution(this, *m_loadableScript, ScriptRunner::ASYNC_EXECUTION);
</span><del>- m_loadableScript->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->removeClient(*this);
- m_loadableScript = nullptr;
- }
-}
-
</del><span class="cx"> void ScriptElement::executeScriptAndDispatchEvent(LoadableScript& loadableScript)
</span><span class="cx"> {
</span><span class="cx"> if (Optional<LoadableScript::Error> 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& loadableScript)
</del><ins>+void ScriptElement::executeScriptForScriptRunner(PendingScript& pendingScript)
</ins><span class="cx"> {
</span><del>- ASSERT(!m_willBeParserExecuted);
- executeScriptAndDispatchEvent(loadableScript);
- loadableScript.removeClient(*this);
-}
-
-void ScriptElement::executeScriptForHTMLScriptRunner(PendingScript& pendingScript)
-{
- IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer(&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&)
-{
- 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()->notifyScriptReady(this, ScriptRunner::IN_ORDER_EXECUTION);
- else
- m_element.document().scriptRunner()->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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptElement.h        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/dom/ScriptElement.h        2016-09-08 17:49:43 UTC (rev 205652)
</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& element() { return m_element; }
</span><span class="cx"> const Element& 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&);
</span><span class="cx">
</span><del>- void executeScriptForScriptRunner(LoadableScript&);
- void executeScriptForHTMLScriptRunner(PendingScript&);
</del><ins>+ void executeScriptForScriptRunner(PendingScript&);
</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<CachedScript> requestScriptWithCache(const URL&, const String& nonceAttribute, const String& crossoriginAttribute);
</span><span class="cx">
</span><span class="cx"> bool requestClassicScript(const String& sourceURL);
</span><del>- void stopLoadRequest();
</del><span class="cx">
</span><del>- void notifyFinished(LoadableScript&) 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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/dom/ScriptRunner.cpp        2016-09-08 17:49:43 UTC (rev 205652)
</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 < m_scriptsToExecuteSoon.size(); ++i)
</del><ins>+ for (auto& pendingScript : m_scriptsToExecuteSoon) {
+ UNUSED_PARAM(pendingScript);
</ins><span class="cx"> m_document.decrementLoadEventDelayCount();
</span><del>- for (size_t i = 0; i < m_scriptsToExecuteInOrder.size(); ++i)
</del><ins>+ }
+ for (auto& pendingScript : m_scriptsToExecuteInOrder) {
+ if (pendingScript->watchingForLoad())
+ pendingScript->clearClient();
</ins><span class="cx"> m_document.decrementLoadEventDelayCount();
</span><del>- for (unsigned i = 0; i < m_pendingAsyncScripts.size(); ++i)
</del><ins>+ }
+ for (auto& pendingScript : m_pendingAsyncScripts) {
+ if (pendingScript->watchingForLoad())
+ const_cast<PendingScript&>(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& 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<PendingScript> 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->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& pendingScript)
</ins><span class="cx"> {
</span><del>- switch (executionType) {
- case ASYNC_EXECUTION:
- ASSERT(m_pendingAsyncScripts.contains(scriptElement));
- m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptElement)->ptr());
- break;
-
- case IN_ORDER_EXECUTION:
</del><ins>+ auto* scriptElement = toScriptElementIfPossible(&pendingScript.element());
+ ASSERT(scriptElement);
+ if (scriptElement->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)->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(&script->element());
</span><span class="cx"> ASSERT(scriptElement);
</span><span class="cx"> ASSERT(script->needsLoading());
</span><del>- scriptElement->executeScriptForScriptRunner(*script->loadableScript());
</del><ins>+ scriptElement->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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/ScriptRunner.h        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/dom/ScriptRunner.h        2016-09-08 17:49:43 UTC (rev 205652)
</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 "PendingScriptClient.h"
</ins><span class="cx"> #include "Timer.h"
</span><del>-#include <wtf/HashMap.h>
</del><ins>+#include <wtf/HashSet.h>
</ins><span class="cx"> #include <wtf/Noncopyable.h>
</span><span class="cx"> #include <wtf/Vector.h>
</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&);
</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&) override;
+
</ins><span class="cx"> Document& m_document;
</span><span class="cx"> Vector<Ref<PendingScript>> m_scriptsToExecuteInOrder;
</span><span class="cx"> Vector<RefPtr<PendingScript>> m_scriptsToExecuteSoon; // http://www.whatwg.org/specs/web-apps/current-work/#set-of-scripts-that-will-execute-as-soon-as-possible
</span><del>- HashMap<ScriptElement*, Ref<PendingScript>> m_pendingAsyncScripts;
</del><ins>+ HashSet<Ref<PendingScript>> 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 (205651 => 205652)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-09-08 17:37:53 UTC (rev 205651)
+++ trunk/Source/WebCore/html/parser/HTMLScriptRunner.cpp        2016-09-08 17:49:43 UTC (rev 205652)
</span><span class="lines">@@ -121,7 +121,7 @@
</span><span class="cx">
</span><span class="cx"> if (auto* scriptElement = toScriptElementIfPossible(&pendingScript->element())) {
</span><span class="cx"> NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
</span><del>- scriptElement->executeScriptForHTMLScriptRunner(*pendingScript);
</del><ins>+ scriptElement->executeScriptForScriptRunner(*pendingScript);
</ins><span class="cx"> }
</span><span class="cx"> ASSERT(!isExecutingScript());
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>