@@ -398,6 +398,7 @@ bool SourceTextModule::MaybeTransitionComponent(
398
398
DCHECK_LE (module->dfs_ancestor_index (), module->dfs_index ());
399
399
if (module->dfs_ancestor_index () == module->dfs_index ()) {
400
400
// This is the root of its strongly connected component.
401
+ Handle <SourceTextModule> cycle_root = module;
401
402
Handle <SourceTextModule> ancestor;
402
403
do {
403
404
ancestor = stack->front ();
@@ -407,6 +408,9 @@ bool SourceTextModule::MaybeTransitionComponent(
407
408
if (new_status == kInstantiated ) {
408
409
if (!SourceTextModule::RunInitializationCode (isolate, ancestor))
409
410
return false ;
411
+ } else if (new_status == kEvaluated ) {
412
+ DCHECK (ancestor->cycle_root ().IsTheHole (isolate));
413
+ ancestor->set_cycle_root (*cycle_root);
410
414
}
411
415
ancestor->SetStatus (new_status);
412
416
} while (*ancestor != *module);
@@ -617,9 +621,9 @@ MaybeHandle<Object> SourceTextModule::EvaluateMaybeAsync(
617
621
CHECK (module->status () == kInstantiated || module->status () == kEvaluated );
618
622
619
623
// 3. If module.[[Status]] is "evaluated", set module to
620
- // GetAsyncCycleRoot( module) .
624
+ // module.[[CycleRoot]] .
621
625
if (module->status () == kEvaluated ) {
622
- module = GetAsyncCycleRoot (isolate, module );
626
+ module = module-> GetCycleRoot (isolate);
623
627
}
624
628
625
629
// 4. If module.[[TopLevelCapability]] is not undefined, then
@@ -734,37 +738,27 @@ void SourceTextModule::AsyncModuleExecutionFulfilled(
734
738
for (int i = 0 ; i < module->AsyncParentModuleCount (); i++) {
735
739
Handle <SourceTextModule> m = module->GetAsyncParentModule (isolate, i);
736
740
737
- // a. If module.[[DFSIndex]] is not equal to module.[[DFSAncestorIndex]],
738
- // then
739
- if (module->dfs_index () != module->dfs_ancestor_index ()) {
740
- // i. Assert: m.[[DFSAncestorIndex]] is equal to
741
- // module.[[DFSAncestorIndex]].
742
- DCHECK_LE (m->dfs_ancestor_index (), module->dfs_ancestor_index ());
743
- }
744
- // b. Decrement m.[[PendingAsyncDependencies]] by 1.
741
+ // a. Decrement m.[[PendingAsyncDependencies]] by 1.
745
742
m->DecrementPendingAsyncDependencies ();
746
743
747
- // c . If m.[[PendingAsyncDependencies]] is 0 and m.[[EvaluationError]] is
744
+ // b . If m.[[PendingAsyncDependencies]] is 0 and m.[[EvaluationError]] is
748
745
// undefined, then
749
746
if (!m->HasPendingAsyncDependencies () && m->status () == kEvaluated ) {
750
747
// i. Assert: m.[[AsyncEvaluating]] is true.
751
748
DCHECK (m->async_evaluating ());
752
749
753
- // ii. Let cycleRoot be ! GetAsyncCycleRoot(m).
754
- auto cycle_root = GetAsyncCycleRoot (isolate, m);
755
-
756
- // iii. If cycleRoot.[[EvaluationError]] is not undefined,
750
+ // ii. If m.[[CycleRoot]].[[EvaluationError]] is not undefined,
757
751
// return undefined.
758
- if (cycle_root ->status () == kErrored ) {
752
+ if (m-> GetCycleRoot (isolate) ->status () == kErrored ) {
759
753
return ;
760
754
}
761
755
762
- // iv . If m.[[Async]] is true, then
756
+ // iii . If m.[[Async]] is true, then
763
757
if (m->async ()) {
764
758
// 1. Perform ! ExecuteAsyncModule(m).
765
759
ExecuteAsyncModule (isolate, m);
766
760
} else {
767
- // v . Otherwise,
761
+ // iv . Otherwise,
768
762
// 1. Let result be m.ExecuteModule().
769
763
// 2. If result is a normal completion,
770
764
Handle <Object> unused_result;
@@ -1044,8 +1038,8 @@ MaybeHandle<Object> SourceTextModule::InnerModuleEvaluation(
1044
1038
required_module->dfs_ancestor_index ()));
1045
1039
} else {
1046
1040
// iv. Otherwise,
1047
- // 1. Set requiredModule to GetAsyncCycleRoot( requiredModule) .
1048
- required_module = GetAsyncCycleRoot (isolate, required_module );
1041
+ // 1. Set requiredModule to requiredModule.[[CycleRoot]] .
1042
+ required_module = required_module-> GetCycleRoot (isolate);
1049
1043
1050
1044
// 2. Assert: requiredModule.[[Status]] is "evaluated".
1051
1045
CHECK_GE (required_module->status (), kEvaluated );
@@ -1103,43 +1097,6 @@ MaybeHandle<Object> SourceTextModule::InnerModuleEvaluation(
1103
1097
return result;
1104
1098
}
1105
1099
1106
- Handle <SourceTextModule> SourceTextModule::GetAsyncCycleRoot (
1107
- Isolate* isolate, Handle <SourceTextModule> module) {
1108
- // 1. Assert: module.[[Status]] is "evaluated".
1109
- CHECK_GE (module->status (), kEvaluated );
1110
-
1111
- // 2. If module.[[AsyncParentModules]] is an empty List, return module.
1112
- if (module->AsyncParentModuleCount () == 0 ) {
1113
- return module;
1114
- }
1115
-
1116
- // 3. Repeat, while module.[[DFSIndex]] is greater than
1117
- // module.[[DFSAncestorIndex]],
1118
- while (module->dfs_index () > module->dfs_ancestor_index ()) {
1119
- // a. Assert: module.[[AsyncParentModules]] is a non-empty List.
1120
- DCHECK_GT (module->AsyncParentModuleCount (), 0 );
1121
-
1122
- // b. Let nextCycleModule be the first element of
1123
- // module.[[AsyncParentModules]].
1124
- Handle <SourceTextModule> next_cycle_module =
1125
- module->GetAsyncParentModule (isolate, 0 );
1126
-
1127
- // c. Assert: nextCycleModule.[[DFSAncestorIndex]] is less than or equal
1128
- // to module.[[DFSAncestorIndex]].
1129
- DCHECK_LE (next_cycle_module->dfs_ancestor_index (),
1130
- module->dfs_ancestor_index ());
1131
-
1132
- // d. Set module to nextCycleModule
1133
- module = next_cycle_module;
1134
- }
1135
-
1136
- // 4. Assert: module.[[DFSIndex]] is equal to module.[[DFSAncestorIndex]].
1137
- DCHECK_EQ (module->dfs_index (), module->dfs_ancestor_index ());
1138
-
1139
- // 5. Return module.
1140
- return module;
1141
- }
1142
-
1143
1100
void SourceTextModule::Reset (Isolate* isolate,
1144
1101
Handle <SourceTextModule> module) {
1145
1102
Factory* factory = isolate->factory ();
0 commit comments