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 |