| Index: third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| index 7b3915aaac0eec2ae7e42d89ecbea6a1915a3734..06728b6cba34a67d9b0a2af2fdf7551ab27c2285 100644
|
| --- a/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| +++ b/third_party/WebKit/Source/core/dom/ScriptLoader.cpp
|
| @@ -26,11 +26,13 @@
|
|
|
| #include "bindings/core/v8/ScriptController.h"
|
| #include "bindings/core/v8/ScriptSourceCode.h"
|
| +#include "bindings/core/v8/ScriptState.h"
|
| #include "core/HTMLNames.h"
|
| #include "core/SVGNames.h"
|
| #include "core/dom/Document.h"
|
| #include "core/dom/DocumentParserTiming.h"
|
| #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
|
| +#include "core/dom/ModuleMap.h"
|
| #include "core/dom/ScriptLoaderClient.h"
|
| #include "core/dom/ScriptRunner.h"
|
| #include "core/dom/ScriptableDocumentParser.h"
|
| @@ -60,6 +62,59 @@
|
|
|
| namespace blink {
|
|
|
| +class ScriptElementModuleClient
|
| + : public GarbageCollectedFinalized<ScriptElementModuleClient>,
|
| + public ModuleMap::Client {
|
| + USING_GARBAGE_COLLECTED_MIXIN(ScriptElementModuleClient);
|
| +
|
| + public:
|
| + static ScriptElementModuleClient* create(Element* element) {
|
| + return new ScriptElementModuleClient(element);
|
| + }
|
| + virtual ~ScriptElementModuleClient() = default;
|
| +
|
| + DECLARE_TRACE();
|
| +
|
| + private:
|
| + ScriptElementModuleClient(Element* element) : m_element(element) {}
|
| +
|
| + // Implements ModuleMap::Client
|
| + void notifyFinished(ScriptModule) override;
|
| +
|
| + Member<Element> m_element;
|
| +};
|
| +
|
| +void ScriptElementModuleClient::notifyFinished(ScriptModule module) {
|
| + // The code below is entirely wrong o(`ω´*)o
|
| + // TODO(kouhei? dominicc?): Fix this as a part of implementing "fetch a module
|
| + // script graph" algorithm.
|
| + if (module.isNull()) {
|
| + printf("ScriptElementModuleClient::notifyFinished: load has failed\n");
|
| + return;
|
| + }
|
| + printf("ScriptElementModuleClient::notifyFinished: load successful\n");
|
| +
|
| + Document* contextDocument = m_element->document().contextDocument();
|
| + DCHECK(contextDocument);
|
| +
|
| + // Below should belong to ScriptController.cpp
|
| + LocalFrame* frame = contextDocument->frame();
|
| + if (!frame)
|
| + return;
|
| + ScriptState* scriptState =
|
| + ScriptState::forMainWorld(contextDocument->frame());
|
| + DCHECK(scriptState);
|
| + ScriptState::Scope scope(scriptState);
|
| +
|
| + CHECK(module.instantiate(scriptState));
|
| + module.evaluate(scriptState);
|
| +}
|
| +
|
| +DEFINE_TRACE(ScriptElementModuleClient) {
|
| + visitor->trace(m_element);
|
| + ModuleMap::Client::trace(visitor);
|
| +}
|
| +
|
| ScriptLoader::ScriptLoader(Element* element,
|
| bool parserInserted,
|
| bool alreadyStarted,
|
| @@ -90,6 +145,7 @@ ScriptLoader::~ScriptLoader() {}
|
| DEFINE_TRACE(ScriptLoader) {
|
| visitor->trace(m_element);
|
| visitor->trace(m_resource);
|
| + visitor->trace(m_elementModuleClient);
|
| visitor->trace(m_pendingScript);
|
| PendingScriptClient::trace(visitor);
|
| }
|
| @@ -260,6 +316,7 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition,
|
| if (m_documentWriteIntervention ==
|
| DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle)
|
| defer = FetchRequest::IdleLoad;
|
| +
|
| if (!fetchScript(client->sourceAttributeValue(), defer))
|
| return false;
|
| }
|
| @@ -335,10 +392,22 @@ bool ScriptLoader::fetchScript(const String& sourceUrl,
|
| return false;
|
|
|
| DCHECK(!m_resource);
|
| +
|
| if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
|
| - FetchRequest request(
|
| - ResourceRequest(elementDocument->completeURL(sourceUrl)),
|
| - m_element->localName());
|
| + KURL url = elementDocument->completeURL(sourceUrl);
|
| +
|
| + if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
|
| + client()->typeAttributeValue() == "module") {
|
| + m_elementModuleClient = ScriptElementModuleClient::create(m_element);
|
| +
|
| + // TODO(kouhei,dominicc): Below should trigger "fetch a module script
|
| + // graph", not "fetch a single module script" algorithm.
|
| + elementDocument->ensureModuleMap()->fetchSingle(url,
|
| + m_elementModuleClient);
|
| + return true;
|
| + }
|
| +
|
| + FetchRequest request(ResourceRequest(url), m_element->localName());
|
|
|
| CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(
|
| m_element->fastGetAttribute(HTMLNames::crossoriginAttr));
|
|
|