Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: rebased Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp
diff --git a/third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp b/third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f40fea302abc65036249035f5084311ce6ca84e0
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp
@@ -0,0 +1,57 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/dom/ScriptModuleResolverImpl.h"
+
+#include "bindings/core/v8/ScriptModule.h"
+#include "core/dom/Modulator.h"
+#include "core/dom/ModuleScript.h"
+
+namespace blink {
+
+void ScriptModuleResolverImpl::registerModuleScript(
+ ModuleScript* moduleScript) {
+#ifndef NDEBUG
+ printf(
+ "ScriptModuleResolverImpl::registerModuleScript(url=\"%s\", hash=%u)\n",
+ moduleScript->baseURL().getString().utf8().data(),
+ ScriptModuleHash::hash(moduleScript->record()));
+#endif
+
+ DCHECK(moduleScript);
+ DCHECK(!moduleScript->record().isNull());
+ auto result = m_recordToModuleScriptMap.set(
+ moduleScript->record(), moduleScript);
+ DCHECK(result.isNewEntry);
+}
+
+ScriptModule ScriptModuleResolverImpl::resolve(
+ const String& specifier,
+ const ScriptModule& referrer,
+ ExceptionState& exceptionState) {
+// TODO(kouhei):
+// https://html.spec.whatwg.org/#hostresolveimportedmodule(referencingmodule,-specifier)
+#ifndef NDEBUG
+ printf("ScriptModuleResolverImpl::resolve(\"%s\") hash: %u\n",
+ specifier.utf8().data(), ScriptModuleHash::hash(referrer));
+#endif
+
+ const auto it = m_recordToModuleScriptMap.find(referrer);
+ CHECK_NE(it, m_recordToModuleScriptMap.end())
+ << "Failed to find referrer ModuleScript corresponding to the record";
+ ModuleScript* referrerModule = it->value;
+
+ KURL url =
+ Modulator::resolveModuleSpecifier(specifier, referrerModule->baseURL());
+ ModuleScript* moduleScript = m_modulator->getFetchedModuleScript(url);
+ return moduleScript->record();
+}
+
+DEFINE_TRACE(ScriptModuleResolverImpl) {
+ ScriptModuleResolver::trace(visitor);
+ visitor->trace(m_recordToModuleScriptMap);
+ visitor->trace(m_modulator);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698