OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/loader/modulescript/ModuleTreeLinker.h" | 5 #include "core/loader/modulescript/ModuleTreeLinker.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptModule.h" | 7 #include "bindings/core/v8/ScriptModule.h" |
8 #include "core/dom/AncestorList.h" | 8 #include "core/dom/AncestorList.h" |
9 #include "core/dom/ModuleScript.h" | 9 #include "core/dom/ModuleScript.h" |
10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" | 10 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 CHECK(module_script_); | 226 CHECK(module_script_); |
227 AdvanceState(State::kFetchingDependencies); | 227 AdvanceState(State::kFetchingDependencies); |
228 | 228 |
229 // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendant
s-of-a-module-script | 229 // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-the-descendant
s-of-a-module-script |
230 | 230 |
231 // Step 1. Let record be module script's module record. | 231 // Step 1. Let record be module script's module record. |
232 ScriptModule record = module_script_->Record(); | 232 ScriptModule record = module_script_->Record(); |
233 | 233 |
234 // Step 2. If record.[[RequestedModules]] is empty, asynchronously complete | 234 // Step 2. If record.[[RequestedModules]] is empty, asynchronously complete |
235 // this algorithm with module script. | 235 // this algorithm with module script. |
236 Vector<String> module_requests = | 236 // Note: We defer this bail-out until Step 5. Step 4 will be no-op anyway if |
237 modulator_->ModuleRequestsFromScriptModule(record); | 237 // record.[[RequestedModules]] is empty. |
238 if (module_requests.IsEmpty()) { | |
239 // Continue to Instantiate() to process "internal module script graph | |
240 // fetching procedure" Step 5-. | |
241 descendants_module_script_ = module_script_; | |
242 Instantiate(); | |
243 return; | |
244 } | |
245 | 238 |
246 // Step 3. Let urls be a new empty list. | 239 // Step 3. Let urls be a new empty list. |
247 Vector<KURL> urls; | 240 Vector<KURL> urls; |
248 | 241 |
249 // Step 4. For each string requested of record.[[RequestedModules]], | 242 // Step 4. For each string requested of record.[[RequestedModules]], |
| 243 Vector<String> module_requests = |
| 244 modulator_->ModuleRequestsFromScriptModule(record); |
250 for (const auto& module_request : module_requests) { | 245 for (const auto& module_request : module_requests) { |
251 // Step 4.1. Let url be the result of resolving a module specifier given | 246 // Step 4.1. Let url be the result of resolving a module specifier given |
252 // module script and requested. | 247 // module script and requested. |
253 KURL url = Modulator::ResolveModuleSpecifier(module_request, | 248 KURL url = Modulator::ResolveModuleSpecifier(module_request, |
254 module_script_->BaseURL()); | 249 module_script_->BaseURL()); |
255 | 250 |
256 // Step 4.2. If the result is error: ... | 251 // Step 4.2. If the result is error: ... |
257 if (url.IsNull()) { | 252 if (url.IsNull()) { |
258 // Let error be a new TypeError exception. | 253 // Let error be a new TypeError exception. |
259 // Report the exception error for module script. | 254 // Report the exception error for module script. |
(...skipping 21 matching lines...) Expand all Loading... |
281 } | 276 } |
282 | 277 |
283 // Step 5. For each url in urls, perform the internal module script graph | 278 // Step 5. For each url in urls, perform the internal module script graph |
284 // fetching procedure given url, module script's credentials mode, module | 279 // fetching procedure given url, module script's credentials mode, module |
285 // script's cryptographic nonce, module script's parser state, destination, | 280 // script's cryptographic nonce, module script's parser state, destination, |
286 // module script's settings object, module script's settings object, ancestor | 281 // module script's settings object, module script's settings object, ancestor |
287 // list, module script's base URL, and with the top-level module fetch flag | 282 // list, module script's base URL, and with the top-level module fetch flag |
288 // unset. If the caller of this algorithm specified custom perform the fetch | 283 // unset. If the caller of this algorithm specified custom perform the fetch |
289 // steps, pass those along while performing the internal module script graph | 284 // steps, pass those along while performing the internal module script graph |
290 // fetching procedure. | 285 // fetching procedure. |
291 // TODO(kouhei): handle "destination". | 286 |
292 DCHECK(!urls.IsEmpty()); | 287 if (urls.IsEmpty()) { |
| 288 // Step 2. If record.[[RequestedModules]] is empty, asynchronously |
| 289 // complete this algorithm with module script. [spec text] |
| 290 // Also, if record.[[RequestedModules]] is not empty but |urls| is |
| 291 // empty here, we can immediately complete this algorithm, as |
| 292 // we don't have to process or wait for anything in Step 5. [non-spec text] |
| 293 |
| 294 // Proceed to Instantiate() to continue |
| 295 // "internal module script graph fetching procedure". |
| 296 descendants_module_script_ = module_script_; |
| 297 Instantiate(); |
| 298 return; |
| 299 } |
| 300 |
| 301 // Step 5, when "urls" is non-empty. |
293 CHECK_EQ(num_incomplete_descendants_, 0u); | 302 CHECK_EQ(num_incomplete_descendants_, 0u); |
294 num_incomplete_descendants_ = urls.size(); | 303 num_incomplete_descendants_ = urls.size(); |
295 for (const KURL& url : urls) { | 304 for (const KURL& url : urls) { |
296 DependencyModuleClient* dependency_client = | 305 DependencyModuleClient* dependency_client = |
297 DependencyModuleClient::Create(this); | 306 DependencyModuleClient::Create(this); |
298 dependency_clients_.insert(dependency_client); | 307 dependency_clients_.insert(dependency_client); |
299 | 308 |
300 ModuleScriptFetchRequest request(url, module_script_->Nonce(), | 309 ModuleScriptFetchRequest request(url, module_script_->Nonce(), |
301 module_script_->ParserState(), | 310 module_script_->ParserState(), |
302 module_script_->CredentialsMode(), | 311 module_script_->CredentialsMode(), |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 HeapHashSet<Member<ModuleScript>> uninstantiated_set; | 512 HeapHashSet<Member<ModuleScript>> uninstantiated_set; |
504 for (const auto& script : inclusive_descendants) { | 513 for (const auto& script : inclusive_descendants) { |
505 if (script->InstantiationState() == | 514 if (script->InstantiationState() == |
506 ModuleInstantiationState::kUninstantiated) | 515 ModuleInstantiationState::kUninstantiated) |
507 uninstantiated_set.insert(script); | 516 uninstantiated_set.insert(script); |
508 } | 517 } |
509 return uninstantiated_set; | 518 return uninstantiated_set; |
510 } | 519 } |
511 | 520 |
512 } // namespace blink | 521 } // namespace blink |
OLD | NEW |