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

Side by Side Diff: third_party/WebKit/Source/core/loader/modulescript/ModuleTreeLinker.cpp

Issue 2839563002: [ES6 modules] Return previous error when an instantiation is reattempt. (Closed)
Patch Set: Created 3 years, 7 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
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 NOTREACHED(); 105 NOTREACHED();
106 break; 106 break;
107 } 107 }
108 108
109 state_ = new_state; 109 state_ = new_state;
110 110
111 if (state_ == State::kFinished) { 111 if (state_ == State::kFinished) {
112 registry_->ReleaseFinishedFetcher(this); 112 registry_->ReleaseFinishedFetcher(this);
113 113
114 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-sc ript-graph-fetching-procedure 114 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-sc ript-graph-fetching-procedure
115 // Step 8. Asynchronously complete this algorithm with descendants result. 115 // Step 9. Asynchronously complete this algorithm with descendants result.
116 client_->NotifyModuleTreeLoadFinished(descendants_module_script_); 116 client_->NotifyModuleTreeLoadFinished(descendants_module_script_);
117 } 117 }
118 } 118 }
119 119
120 void ModuleTreeLinker::FetchSelf(const ModuleScriptFetchRequest& request, 120 void ModuleTreeLinker::FetchSelf(const ModuleScriptFetchRequest& request,
121 ModuleGraphLevel level) { 121 ModuleGraphLevel level) {
122 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure 122 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure
123 123
124 // Step 1. Fetch a single module script given url, fetch client settings 124 // Step 1. Fetch a single module script given url, fetch client settings
125 // object, destination, cryptographic nonce, parser state, credentials mode, 125 // object, destination, cryptographic nonce, parser state, credentials mode,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 module_script_->BaseURL()); 223 module_script_->BaseURL());
224 224
225 // Step 4.2. If the result is error: ... 225 // Step 4.2. If the result is error: ...
226 if (url.IsNull()) { 226 if (url.IsNull()) {
227 // Let error be a new TypeError exception. 227 // Let error be a new TypeError exception.
228 // Report the exception error for module script. 228 // Report the exception error for module script.
229 // TODO(kouhei): Implement the exception. 229 // TODO(kouhei): Implement the exception.
230 230
231 // Abort this algorithm, and asynchronously complete it with null. 231 // Abort this algorithm, and asynchronously complete it with null.
232 // Note: The return variable for "internal module script graph fetching 232 // Note: The return variable for "internal module script graph fetching
233 // procedure" is descendants_module_script_ per Step 8. 233 // procedure" is descendants_module_script_ per Step 9.
234 DCHECK(!descendants_module_script_); 234 DCHECK(!descendants_module_script_);
235 // Note: while we complete "fetch the descendants of a module script" 235 // Note: while we complete "fetch the descendants of a module script"
236 // algorithm here, we still need to continue to the rest of the 236 // algorithm here, we still need to continue to the rest of the
237 // steps in "internal module script graph fetching procedure" 237 // steps in "internal module script graph fetching procedure"
238 Instantiate(); 238 Instantiate();
239 return; 239 return;
240 } 240 }
241 241
242 // Step 4.3. Otherwise, if ancestor list does not contain url, append url to 242 // Step 4.3. Otherwise, if ancestor list does not contain url, append url to
243 // urls. 243 // urls.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 Instantiate(); 329 Instantiate();
330 } 330 }
331 } 331 }
332 332
333 void ModuleTreeLinker::Instantiate() { 333 void ModuleTreeLinker::Instantiate() {
334 CHECK(module_script_); 334 CHECK(module_script_);
335 AdvanceState(State::kInstantiating); 335 AdvanceState(State::kInstantiating);
336 336
337 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure 337 // https://html.spec.whatwg.org/multipage/webappapis.html#internal-module-scri pt-graph-fetching-procedure
338 338
339 // Step 5. Let record be result's module record. 339 // Step 5. Let instantiationStatus be null.
340 ScriptModule record = module_script_->Record();
341
342 // Step 6. Let instantiationStatus be record.ModuleDeclarationInstantiation().
343 // Note: The |error| variable corresponds to spec variable 340 // Note: The |error| variable corresponds to spec variable
344 // "instantiationStatus". If |error| is empty, it indicates successful 341 // "instantiationStatus". If |error| is empty, it indicates successful
345 // completion. 342 // completion.
346 ScriptValue error = modulator_->InstantiateModule(record); 343 ScriptValue error;
347 344
348 // Step 7. For each module script script in result's uninstantiated inclusive 345 // Step 6. If result's instantiation state is "errored",...
346 if (module_script_->InstantiationState() ==
347 ModuleInstantiationState::kErrored) {
348 // ... Set instantiationStatus to record.ModuleDeclarationInstantiation().
349 error = modulator_->GetInstantiationError(module_script_);
hiroshige 2017/04/27 22:56:40 DCHECK(!error.IsEmpty());
kouhei (in TOK) 2017/04/28 00:55:09 Done.
350 } else {
351 // Step 7. Otherwise:
352 // Step 7.1. Let record be result's module record.
353 ScriptModule record = module_script_->Record();
354 // Step 7.2. Set instantiationStatus to
355 // record.ModuleDeclarationInstantiation().
356 error = modulator_->InstantiateModule(record);
357 }
358
359 // Step 8. For each module script script in result's uninstantiated inclusive
349 // descendant module scripts, perform the following steps: 360 // descendant module scripts, perform the following steps:
350 HeapHashSet<Member<ModuleScript>> uninstantiated_set = 361 HeapHashSet<Member<ModuleScript>> uninstantiated_set =
351 UninstantiatedInclusiveDescendants(); 362 UninstantiatedInclusiveDescendants();
352 for (const auto& descendant : uninstantiated_set) { 363 for (const auto& descendant : uninstantiated_set) {
353 if (!error.IsEmpty()) { 364 if (!error.IsEmpty()) {
354 // Step 7.1. If instantiationStatus is an abrupt completion, then set 365 // Step 8.1. If instantiationStatus is an abrupt completion, then
355 // script's instantiation state to "errored", its instantiation error to 366 // Step 8.1.1. Set script module record's [[HostDefined]] field to
356 // instantiationStatus.[[Value]], and its module record to null. 367 // undefined.
368 // TODO(kouhei): Implement this.
369
370 // Step 8.1.2. Set script's module record to null.
371 // Step 8.1.3. Set script's instantiation state to "errored".
372 // Step 8.1.4. Set script's instantiation error to
373 // instantiationStatus.[[Value]].
357 descendant->SetInstantiationErrorAndClearRecord(error); 374 descendant->SetInstantiationErrorAndClearRecord(error);
358 } else { 375 } else {
359 // Step 7.2. Otherwise, set script's instantiation state to 376 // Step 8.2. Otherwise, set script's instantiation state to
360 // "instantiated". 377 // "instantiated".
361 descendant->SetInstantiationSuccess(); 378 descendant->SetInstantiationSuccess();
362 } 379 }
363 } 380 }
364 381
365 // Step 8. Asynchronously complete this algorithm with descendants result. 382 // Step 9. Asynchronously complete this algorithm with descendants result.
366 AdvanceState(State::kFinished); 383 AdvanceState(State::kFinished);
367 } 384 }
368 385
369 HeapHashSet<Member<ModuleScript>> 386 HeapHashSet<Member<ModuleScript>>
370 ModuleTreeLinker::UninstantiatedInclusiveDescendants() { 387 ModuleTreeLinker::UninstantiatedInclusiveDescendants() {
371 // https://html.spec.whatwg.org/multipage/webappapis.html#uninstantiated-inclu sive-descendant-module-scripts 388 // https://html.spec.whatwg.org/multipage/webappapis.html#uninstantiated-inclu sive-descendant-module-scripts
372 // Step 1. Let moduleMap be script's settings object's module map. 389 // Step 1. Let moduleMap be script's settings object's module map.
373 // Note: Modulator is our "settings object". 390 // Note: Modulator is our "settings object".
374 // Note: We won't reference the ModuleMap directly here to aid testing. 391 // Note: We won't reference the ModuleMap directly here to aid testing.
375 392
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 HeapHashSet<Member<ModuleScript>> uninstantiated_set; 471 HeapHashSet<Member<ModuleScript>> uninstantiated_set;
455 for (const auto& script : inclusive_descendants) { 472 for (const auto& script : inclusive_descendants) {
456 if (script->InstantiationState() == 473 if (script->InstantiationState() ==
457 ModuleInstantiationState::kUninstantiated) 474 ModuleInstantiationState::kUninstantiated)
458 uninstantiated_set.insert(script); 475 uninstantiated_set.insert(script);
459 } 476 }
460 return uninstantiated_set; 477 return uninstantiated_set;
461 } 478 }
462 479
463 } // namespace blink 480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698