tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pending-async-dep-from-cycle.js (3711B)


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