Chromium Code Reviews| 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..ee6f140fbe338f0072e40a6360f3b9f951218b9f |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp |
| @@ -0,0 +1,96 @@ |
| +// 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) { |
| +#if DCHECK_IS_ON() |
| + DVLOG(1) << "ScriptModuleResolverImpl::registerModuleScript(url=\"" |
|
kinuko
2017/04/05 14:05:00
I don't think we need to wrap DVLOG with DCHECK_IS
|
| + << moduleScript->baseURL().getString() |
| + << "\", hash=" << 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) { |
| +// https://html.spec.whatwg.org/#hostresolveimportedmodule(referencingmodule,-specifier) |
| +#if DCHECK_IS_ON() |
|
domenic
2017/04/05 07:07:45
You may want to add a second line pointing out thi
kouhei (in TOK)
2017/04/06 05:34:18
Done.
|
| + DVLOG(1) << "ScriptModuleResolverImpl::resolve(specifier=\"" << specifier |
| + << ", referrer.hash=" << ScriptModuleHash::hash(referrer) << ")"; |
| +#endif |
| + |
| + // Step 1. Let referencing module script be referencingModule.[[HostDefined]]. |
| + const auto it = m_recordToModuleScriptMap.find(referrer); |
| + CHECK_NE(it, m_recordToModuleScriptMap.end()) |
|
kinuko
2017/04/05 14:05:00
Do we need CHECK (not DCHECK) here?
kouhei (in TOK)
2017/04/06 05:34:18
hiroshige and I try to use CHECK wherever possible
|
| + << "Failed to find referrer ModuleScript corresponding to the record"; |
| + ModuleScript* referrerModule = it->value; |
| + |
| + // Step 2. Let moduleMap be referencing module script's settings object's |
| + // module map. Note: Blink finds out "module script's settings object" |
| + // (Modulator) from context where HostResolveImportedModule was called. |
|
kouhei (in TOK)
2017/04/05 06:30:11
+domenic FYI
|
| + |
| + // Step 3. Let url be the result of resolving a module specifier given |
| + // referencing module script and specifier. If the result is failure, then |
| + // throw a TypeError exception and abort these steps. |
| + KURL url = |
| + Modulator::resolveModuleSpecifier(specifier, referrerModule->baseURL()); |
| + if (!url.isValid()) { |
| + exceptionState.throwTypeError("Failed to resolve module specifier '" + |
| + specifier + "'"); |
| + return ScriptModule(); |
| + } |
| + |
| + // Step 4. Let resolved module script be moduleMap[url]. If no such entry |
| + // exists, or if resolved module script is null or "fetching", then throw a |
| + // TypeError exception and abort these steps. |
| + ModuleScript* moduleScript = m_modulator->getFetchedModuleScript(url); |
| + if (!moduleScript) { |
| + exceptionState.throwTypeError( |
| + "Failed to load module script for module specifier '" + specifier + |
| + "'"); |
| + return ScriptModule(); |
| + } |
| + |
| + // Step 5. If resolved module script's instantiation state is "errored", then |
| + // throw resolved module script's instantiation error. |
| + if (moduleScript->instantiationState() == ModuleInstantiationState::Errored) { |
| + // TODO(kouhei): Implement this path once |
| + // https://codereview.chromium.org/2782403002/ landed. |
| + NOTIMPLEMENTED(); |
| + return ScriptModule(); |
| + } |
| + |
| + // Step 6. Assert: resolved module script's instantiation state is |
| + // "instantiated" (and thus its module record is not null). |
| + // TODO(kouhei): Enable below check once once |
| + // https://codereview.chromium.org/2782403002/ landed. |
| + // CHECK_EQ(moduleScript->instantiationState(), |
| + // ModuleInstantiationState::Instantiated); |
| + |
| + // Step 7. Return resolved module script's module record. |
| + return moduleScript->record(); |
| +} |
| + |
| +DEFINE_TRACE(ScriptModuleResolverImpl) { |
| + ScriptModuleResolver::trace(visitor); |
| + visitor->trace(m_recordToModuleScriptMap); |
| + visitor->trace(m_modulator); |
| +} |
| + |
| +} // namespace blink |