1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
// 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 "third_party/blink/renderer/core/testing/dummy_modulator.h"
#include "third_party/blink/renderer/bindings/core/v8/module_record.h"
#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/loader/modulescript/module_script_creation_params.h"
#include "third_party/blink/renderer/core/script/module_record_resolver.h"
namespace blink {
namespace {
class EmptyModuleRecordResolver final : public ModuleRecordResolver {
public:
EmptyModuleRecordResolver() = default;
// We ignore {Unr,R}egisterModuleScript() calls caused by
// ModuleScript::CreateForTest().
void RegisterModuleScript(const ModuleScript*) override {}
void UnregisterModuleScript(const ModuleScript*) override {}
const ModuleScript* GetModuleScriptFromModuleRecord(
v8::Local<v8::Module>) const override {
NOTREACHED();
return nullptr;
}
v8::Local<v8::Module> Resolve(const ModuleRequest& module_request,
v8::Local<v8::Module> referrer,
ExceptionState&) override {
NOTREACHED();
return v8::Local<v8::Module>();
}
};
} // namespace
DummyModulator::DummyModulator()
: resolver_(MakeGarbageCollected<EmptyModuleRecordResolver>()) {}
DummyModulator::~DummyModulator() = default;
void DummyModulator::Trace(Visitor* visitor) const {
visitor->Trace(resolver_);
Modulator::Trace(visitor);
}
ScriptState* DummyModulator::GetScriptState() {
NOTREACHED();
return nullptr;
}
mojom::blink::V8CacheOptions DummyModulator::GetV8CacheOptions() const {
return mojom::blink::V8CacheOptions::kDefault;
}
bool DummyModulator::IsScriptingDisabled() const {
return false;
}
bool DummyModulator::ImportMapsEnabled() const {
return false;
}
ModuleRecordResolver* DummyModulator::GetModuleRecordResolver() {
return resolver_.Get();
}
base::SingleThreadTaskRunner* DummyModulator::TaskRunner() {
NOTREACHED();
return nullptr;
}
void DummyModulator::FetchTree(const KURL&,
ModuleType,
ResourceFetcher*,
mojom::blink::RequestContextType,
network::mojom::RequestDestination,
const ScriptFetchOptions&,
ModuleScriptCustomFetchType,
ModuleTreeClient*) {
NOTREACHED();
}
void DummyModulator::FetchSingle(const ModuleScriptFetchRequest&,
ResourceFetcher*,
ModuleGraphLevel,
ModuleScriptCustomFetchType,
SingleModuleClient*) {
NOTREACHED();
}
void DummyModulator::FetchDescendantsForInlineScript(
ModuleScript*,
ResourceFetcher*,
mojom::blink::RequestContextType,
network::mojom::RequestDestination,
ModuleTreeClient*) {
NOTREACHED();
}
ModuleScript* DummyModulator::GetFetchedModuleScript(const KURL&, ModuleType) {
NOTREACHED();
return nullptr;
}
KURL DummyModulator::ResolveModuleSpecifier(const String&,
const KURL&,
String*) {
NOTREACHED();
return KURL();
}
bool DummyModulator::HasValidContext() {
return true;
}
void DummyModulator::ResolveDynamically(const ModuleRequest& module_request,
const KURL&,
const ReferrerScriptInfo&,
ScriptPromiseResolver*) {
NOTREACHED();
}
ScriptValue DummyModulator::CreateTypeError(const String& message) const {
NOTREACHED();
return ScriptValue();
}
ScriptValue DummyModulator::CreateSyntaxError(const String& message) const {
NOTREACHED();
return ScriptValue();
}
void DummyModulator::RegisterImportMap(const ImportMap*,
ScriptValue error_to_rethrow) {
NOTREACHED();
}
Modulator::AcquiringImportMapsState
DummyModulator::GetAcquiringImportMapsState() const {
NOTREACHED();
return AcquiringImportMapsState::kAcquiring;
}
void DummyModulator::SetAcquiringImportMapsState(AcquiringImportMapsState) {
NOTREACHED();
}
const ImportMap* DummyModulator::GetImportMapForTest() const {
NOTREACHED();
return nullptr;
}
ModuleImportMeta DummyModulator::HostGetImportMetaProperties(
v8::Local<v8::Module>) const {
NOTREACHED();
return ModuleImportMeta(String());
}
ScriptValue DummyModulator::InstantiateModule(v8::Local<v8::Module>,
const KURL&) {
NOTREACHED();
return ScriptValue();
}
Vector<ModuleRequest> DummyModulator::ModuleRequestsFromModuleRecord(
v8::Local<v8::Module>) {
NOTREACHED();
return Vector<ModuleRequest>();
}
ModuleType DummyModulator::ModuleTypeFromRequest(
const ModuleRequest& module_request) const {
String module_type_string = module_request.GetModuleTypeString();
if (module_type_string.IsNull()) {
// Per https://github.com/whatwg/html/pull/5883, if no type assertion is
// provided then the import should be treated as a JavaScript module.
return ModuleType::kJavaScript;
} else if (module_type_string == "json") {
// Per https://github.com/whatwg/html/pull/5658, a "json" type assertion
// indicates that the import should be treated as a JSON module script.
return ModuleType::kJSON;
} else if (module_type_string == "css") {
// Per https://github.com/whatwg/html/pull/4898, a "css" type assertion
// indicates that the import should be treated as a CSS module script.
return ModuleType::kCSS;
} else {
// Per https://github.com/whatwg/html/pull/5883, if an unsupported type
// assertion is provided then the import should be treated as an error
// similar to an invalid module specifier.
return ModuleType::kInvalid;
}
}
ModuleScriptFetcher* DummyModulator::CreateModuleScriptFetcher(
ModuleScriptCustomFetchType,
base::PassKey<ModuleScriptLoader> pass_key) {
NOTREACHED();
return nullptr;
}
void DummyModulator::ProduceCacheModuleTreeTopLevel(ModuleScript*) {}
} // namespace blink
|