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

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

Issue 2790473002: [ES6 modules] Introduce ScriptModuleResolverImpl (Closed)
Patch Set: error impl / unit test 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 #if DCHECK_IS_ON()
16 DVLOG(1) << "ScriptModuleResolverImpl::registerModuleScript(url=\""
kinuko 2017/04/05 14:05:00 I don't think we need to wrap DVLOG with DCHECK_IS
17 << moduleScript->baseURL().getString()
18 << "\", hash=" << ScriptModuleHash::hash(moduleScript->record())
19 << ")";
20 #endif
21
22 DCHECK(moduleScript);
23 DCHECK(!moduleScript->record().isNull());
24 auto result =
25 m_recordToModuleScriptMap.set(moduleScript->record(), moduleScript);
26 DCHECK(result.isNewEntry);
27 }
28
29 ScriptModule ScriptModuleResolverImpl::resolve(const String& specifier,
30 const ScriptModule& referrer,
31 ExceptionState& exceptionState) {
32 // https://html.spec.whatwg.org/#hostresolveimportedmodule(referencingmodule,-sp ecifier)
33 #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.
34 DVLOG(1) << "ScriptModuleResolverImpl::resolve(specifier=\"" << specifier
35 << ", referrer.hash=" << ScriptModuleHash::hash(referrer) << ")";
36 #endif
37
38 // Step 1. Let referencing module script be referencingModule.[[HostDefined]].
39 const auto it = m_recordToModuleScriptMap.find(referrer);
40 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
41 << "Failed to find referrer ModuleScript corresponding to the record";
42 ModuleScript* referrerModule = it->value;
43
44 // Step 2. Let moduleMap be referencing module script's settings object's
45 // module map. Note: Blink finds out "module script's settings object"
46 // (Modulator) from context where HostResolveImportedModule was called.
kouhei (in TOK) 2017/04/05 06:30:11 +domenic FYI
47
48 // Step 3. Let url be the result of resolving a module specifier given
49 // referencing module script and specifier. If the result is failure, then
50 // throw a TypeError exception and abort these steps.
51 KURL url =
52 Modulator::resolveModuleSpecifier(specifier, referrerModule->baseURL());
53 if (!url.isValid()) {
54 exceptionState.throwTypeError("Failed to resolve module specifier '" +
55 specifier + "'");
56 return ScriptModule();
57 }
58
59 // Step 4. Let resolved module script be moduleMap[url]. If no such entry
60 // exists, or if resolved module script is null or "fetching", then throw a
61 // TypeError exception and abort these steps.
62 ModuleScript* moduleScript = m_modulator->getFetchedModuleScript(url);
63 if (!moduleScript) {
64 exceptionState.throwTypeError(
65 "Failed to load module script for module specifier '" + specifier +
66 "'");
67 return ScriptModule();
68 }
69
70 // Step 5. If resolved module script's instantiation state is "errored", then
71 // throw resolved module script's instantiation error.
72 if (moduleScript->instantiationState() == ModuleInstantiationState::Errored) {
73 // TODO(kouhei): Implement this path once
74 // https://codereview.chromium.org/2782403002/ landed.
75 NOTIMPLEMENTED();
76 return ScriptModule();
77 }
78
79 // Step 6. Assert: resolved module script's instantiation state is
80 // "instantiated" (and thus its module record is not null).
81 // TODO(kouhei): Enable below check once once
82 // https://codereview.chromium.org/2782403002/ landed.
83 // CHECK_EQ(moduleScript->instantiationState(),
84 // ModuleInstantiationState::Instantiated);
85
86 // Step 7. Return resolved module script's module record.
87 return moduleScript->record();
88 }
89
90 DEFINE_TRACE(ScriptModuleResolverImpl) {
91 ScriptModuleResolver::trace(visitor);
92 visitor->trace(m_recordToModuleScriptMap);
93 visitor->trace(m_modulator);
94 }
95
96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698