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

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptModuleResolverImpl.cpp

Issue 2801073003: [local; kouhei 1][ES6 modules] Introduce ScriptModuleResolverImpl (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/dom/ScriptModuleResolverImpl.h"
6
7 #include "bindings/core/v8/ScriptModule.h"
8 #include "core/dom/Modulator.h"
9 #include "core/dom/ModuleScript.h"
10
11 namespace blink {
12
13 void ScriptModuleResolverImpl::registerModuleScript(
14 ModuleScript* moduleScript) {
15 DVLOG(1) << "ScriptModuleResolverImpl::registerModuleScript(url=\""
16 << moduleScript->baseURL().getString()
17 << "\", hash=" << ScriptModuleHash::hash(moduleScript->record())
18 << ")";
19
20 DCHECK(moduleScript);
21 DCHECK(!moduleScript->record().isNull());
22 auto result =
23 m_recordToModuleScriptMap.set(moduleScript->record(), moduleScript);
24 DCHECK(result.isNewEntry);
25 }
26
27 ScriptModule ScriptModuleResolverImpl::resolve(const String& specifier,
28 const ScriptModule& referrer,
29 ExceptionState& exceptionState) {
30 // https://html.spec.whatwg.org/commit-snapshots/f8e75a974ed9185e5b462bc5b2dfb 32034bd1145#hostresolveimportedmodule(referencingmodule,-specifier)
31 DVLOG(1) << "ScriptModuleResolverImpl::resolve(specifier=\"" << specifier
32 << ", referrer.hash=" << ScriptModuleHash::hash(referrer) << ")";
33
34 // Step 1. Let referencing module script be referencingModule.[[HostDefined]].
35 const auto it = m_recordToModuleScriptMap.find(referrer);
36 CHECK_NE(it, m_recordToModuleScriptMap.end())
37 << "Failed to find referrer ModuleScript corresponding to the record";
38 ModuleScript* referrerModule = it->value;
39
40 // Step 2. Let moduleMap be referencing module script's settings object's
41 // module map. Note: Blink finds out "module script's settings object"
42 // (Modulator) from context where HostResolveImportedModule was called.
43
44 // Step 3. Let url be the result of resolving a module specifier given
45 // referencing module script and specifier. If the result is failure, then
46 // throw a TypeError exception and abort these steps.
47 KURL url =
48 Modulator::resolveModuleSpecifier(specifier, referrerModule->baseURL());
49 if (!url.isValid()) {
50 exceptionState.throwTypeError("Failed to resolve module specifier '" +
51 specifier + "'");
52 return ScriptModule();
53 }
54
55 // Step 4. Let resolved module script be moduleMap[url]. If no such entry
56 // exists, or if resolved module script is null or "fetching", then throw a
57 // TypeError exception and abort these steps.
58 ModuleScript* moduleScript = m_modulator->getFetchedModuleScript(url);
59 if (!moduleScript) {
60 exceptionState.throwTypeError(
61 "Failed to load module script for module specifier '" + specifier +
62 "'");
63 return ScriptModule();
64 }
65
66 // Step 5. If resolved module script's instantiation state is "errored", then
67 // throw resolved module script's instantiation error.
68 if (moduleScript->instantiationState() == ModuleInstantiationState::Errored) {
69 // TODO(kouhei): Implement this path once
70 // https://codereview.chromium.org/2782403002/ landed.
71 NOTIMPLEMENTED();
72 return ScriptModule();
73 }
74
75 // Step 6. Assert: resolved module script's instantiation state is
76 // "instantiated" (and thus its module record is not null).
77 // TODO(kouhei): Enable below check once once
78 // https://codereview.chromium.org/2782403002/ landed.
79 // CHECK_EQ(moduleScript->instantiationState(),
80 // ModuleInstantiationState::Instantiated);
81
82 // Step 7. Return resolved module script's module record.
83 return moduleScript->record();
84 }
85
86 DEFINE_TRACE(ScriptModuleResolverImpl) {
87 ScriptModuleResolver::trace(visitor);
88 visitor->trace(m_recordToModuleScriptMap);
89 visitor->trace(m_modulator);
90 }
91
92 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698