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..9e1440b1a3b7044ac27541de364ad7c911291db8 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_); |
} |
} |
@@ -230,7 +230,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 |
@@ -336,33 +336,51 @@ 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_); |
+ DCHECK(!error.IsEmpty()); |
+ } 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); |
} |