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