Index: third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp |
diff --git a/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp b/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp |
index 7f9213e213e24be7730548294b06b323f6672a0b..b66161ec3c25090c7fb7b0ad83ebede70e8871d7 100644 |
--- a/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp |
+++ b/third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp |
@@ -112,7 +112,7 @@ void ModuleTreeLinker::AdvanceState(State new_state) { |
registry_->ReleaseFinishedFetcher(this); |
// https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure |
- // Step 8. Asynchronously complete this algorithm with descendants result. |
+ // Step 9. Asynchronously complete this algorithm with descendants result. |
client_->NotifyModuleTreeLoadFinished(descendants_module_script_); |
} |
} |
@@ -204,13 +204,6 @@ void ModuleTreeLinker::FetchDescendants() { |
// this algorithm with module script. |
Vector<String> module_requests = |
modulator_->ModuleRequestsFromScriptModule(record); |
- if (module_requests.IsEmpty()) { |
- // Continue to Instantiate() to process "internal module script graph |
- // fetching procedure" Step 5-. |
- descendants_module_script_ = module_script_; |
- Instantiate(); |
- return; |
- } |
// Step 3. Let urls be a new empty list. |
Vector<KURL> urls; |
@@ -230,7 +223,7 @@ void ModuleTreeLinker::FetchDescendants() { |
// Abort this algorithm, and asynchronously complete it with null. |
// Note: The return variable for "internal module script graph fetching |
- // procedure" is descendants_module_script_ per Step 8. |
+ // procedure" is descendants_module_script_ per Step 9. |
DCHECK(!descendants_module_script_); |
// Note: while we complete "fetch the descendants of a module script" |
// algorithm here, we still need to continue to the rest of the |
@@ -258,7 +251,15 @@ void ModuleTreeLinker::FetchDescendants() { |
// steps, pass those along while performing the internal module script graph |
// fetching procedure. |
// TODO(kouhei): handle "destination". |
- DCHECK(!urls.IsEmpty()); |
+ if (urls.IsEmpty()) { |
kouhei (in TOK)
2017/04/26 13:03:44
DCHECK doesn't always hold. The requests may be al
hiroshige
2017/04/28 01:15:35
Memo: This causes crash in imports.html wpt test.
|
+ // Continue to Instantiate() to process "internal module script graph |
+ // fetching procedure" Step 5-. |
+ descendants_module_script_ = module_script_; |
+ Instantiate(); |
+ |
+ RESOURCE_LOADING_DVLOG(1) << "maybe cycles? " << module_script_->BaseURL().GetString(); |
+ return; |
+ } |
CHECK_EQ(num_incomplete_descendants_, 0u); |
num_incomplete_descendants_ = urls.size(); |
for (const KURL& url : urls) { |
@@ -336,33 +337,50 @@ void ModuleTreeLinker::Instantiate() { |
// https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-script-graph-fetching-procedure |
- // Step 5. Let record be result's module record. |
- ScriptModule record = module_script_->Record(); |
- |
- // Step 6. Let instantiationStatus be record.ModuleDeclarationInstantiation(). |
+ // Step 5. Let instantiationStatus be null. |
// Note: The |error| variable corresponds to spec variable |
// "instantiationStatus". If |error| is empty, it indicates successful |
// completion. |
- ScriptValue error = modulator_->InstantiateModule(record); |
+ ScriptValue error; |
+ |
+ // Step 6. If result's instantiation state is "errored",... |
+ if (module_script_->InstantiationState() == |
+ ModuleInstantiationState::kErrored) { |
+ // ... Set instantiationStatus to record.ModuleDeclarationInstantiation(). |
+ error = modulator_->GetInstantiationError(module_script_); |
+ } else { |
+ // Step 7. Otherwise: |
+ // Step 7.1. Let record be result's module record. |
+ ScriptModule record = module_script_->Record(); |
+ // Step 7.2. Set instantiationStatus to |
+ // record.ModuleDeclarationInstantiation(). |
+ error = modulator_->InstantiateModule(record); |
+ } |
- // Step 7. For each module script script in result's uninstantiated inclusive |
+ // Step 8. For each module script script in result's uninstantiated inclusive |
// descendant module scripts, perform the following steps: |
HeapHashSet<Member<ModuleScript>> uninstantiated_set = |
UninstantiatedInclusiveDescendants(); |
for (const auto& descendant : uninstantiated_set) { |
if (!error.IsEmpty()) { |
- // Step 7.1. If instantiationStatus is an abrupt completion, then set |
- // script's instantiation state to "errored", its instantiation error to |
- // instantiationStatus.[[Value]], and its module record to null. |
+ // Step 8.1. If instantiationStatus is an abrupt completion, then |
+ // Step 8.1.1. Set script module record's [[HostDefined]] field to |
+ // undefined. |
+ // TODO(kouhei): Implement this. |
+ |
+ // Step 8.1.2. Set script's module record to null. |
+ // Step 8.1.3. Set script's instantiation state to "errored". |
+ // Step 8.1.4. Set script's instantiation error to |
+ // instantiationStatus.[[Value]]. |
descendant->SetInstantiationErrorAndClearRecord(error); |
} else { |
- // Step 7.2. Otherwise, set script's instantiation state to |
+ // Step 8.2. Otherwise, set script's instantiation state to |
// "instantiated". |
descendant->SetInstantiationSuccess(); |
} |
} |
- // Step 8. Asynchronously complete this algorithm with descendants result. |
+ // Step 9. Asynchronously complete this algorithm with descendants result. |
AdvanceState(State::kFinished); |
} |