Skip to content

Commit fbd7f63

Browse files
Test a module depending on a non-root node of an async cycle
1 parent 93d6396 commit fbd7f63

5 files changed

+96
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-innermoduleevaluation
6+
description: >
7+
A module depending on an async module of a separate cycle should wait for the cycle root to complete
8+
info: |
9+
Module graph:
10+
11+
┌──────────────────┐
12+
│ entrypoint │
13+
└──────────────────┘
14+
│ │
15+
▼ ▼
16+
┌──────────────────┐ ┌────────────────────────┐
17+
│ cycle root (TLA) │ │ importer of cycle leaf │
18+
└──────────────────┘ └────────────────────────┘
19+
│ ▲ │
20+
▼ │ │
21+
┌──────────────────┐ │
22+
│ cycle leaf (TLA) │ ◄──────┘
23+
└──────────────────┘
24+
25+
This test exercises step 11.c.iv.1 of the following algorithm when _module_ is
26+
"importer of cycle leaf", _requiredModule_ is "cycle leaf (TLA)", and
27+
_requiredModule_.[[CycleRoot]] is "cycle root (TLA)".
28+
The [[Status]] of "cycle leaf (TLA)" and of "cycle root (TLA)" is ~evaluating-async~,
29+
because they have alredy been traversed and they are blocked on the TLA in "cycle leaf (TLA)".
30+
Thus, their [[AsyncEvaluationOrder]] is an integer, so the _requiredModule_ variable is used
31+
to determine what module "importer of cycle leaf" should wait for.
32+
33+
InnerModuleEvaluation ( module, stack, index )
34+
...
35+
11. For each ModuleRequest Record request of module.[[RequestedModules]], do
36+
a. Let requiredModule be GetImportedModule(module, request).
37+
b. Set index to ? InnerModuleEvaluation(requiredModule, stack, index).
38+
c. If requiredModule is a Cyclic Module Record, then
39+
i. Assert: requiredModule.[[Status]] is one of evaluating, evaluating-async, or evaluated.
40+
ii. Assert: requiredModule.[[Status]] is evaluating if and only if stack contains requiredModule.
41+
iii. If requiredModule.[[Status]] is evaluating, then
42+
1. Set module.[[DFSAncestorIndex]] to min(module.[[DFSAncestorIndex]], requiredModule.[[DFSAncestorIndex]]).
43+
iv. Else,
44+
1. Set requiredModule to requiredModule.[[CycleRoot]].
45+
2. Assert: requiredModule.[[Status]] is either evaluating-async or evaluated.
46+
3. If requiredModule.[[EvaluationError]] is not empty, return ? requiredModule.[[EvaluationError]].
47+
v. If requiredModule.[[AsyncEvaluationOrder]] is an integer, then
48+
1. Set module.[[PendingAsyncDependencies]] to module.[[PendingAsyncDependencies]] + 1.
49+
2. Append module to requiredModule.[[AsyncParentModules]].
50+
51+
flags: [module, async]
52+
features: [top-level-await]
53+
includes: [compareArray.js]
54+
---*/
55+
56+
import "./pending-async-dep-from-cycle_setup_FIXTURE.js";
57+
import "./pending-async-dep-from-cycle_cycle-root_FIXTURE.js";
58+
import "./pending-async-dep-from-cycle_import-cycle-leaf_FIXTURE.js";
59+
60+
assert.compareArray(globalThis.logs, [
61+
"cycle leaf start",
62+
"cycle leaf end",
63+
"cycle root start",
64+
// Without the step covered by this test,
65+
// these last two entries would be swapped.
66+
"cycle root end",
67+
"importer of cycle leaf"
68+
]);
69+
70+
$DONE();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
import "./pending-async-dep-from-cycle_cycle-root_FIXTURE.js";
5+
6+
globalThis.logs.push("cycle leaf start");
7+
await 1;
8+
globalThis.logs.push("cycle leaf end");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
import "./pending-async-dep-from-cycle_cycle-leaf_FIXTURE.js";
5+
6+
globalThis.logs.push("cycle root start");
7+
await 1;
8+
globalThis.logs.push("cycle root end");
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
import "./pending-async-dep-from-cycle_cycle-leaf_FIXTURE.js";
5+
6+
globalThis.logs.push("importer of cycle leaf");
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
globalThis.logs = [];

0 commit comments

Comments
 (0)