js/src/tests/test262/language/import/import-defer/evaluation-sync/module-imported-defer-and-eager.js
raw symbols SCIP| 1 | // |reftest| skip module -- import-defer is not supported |
| 2 | // Copyright (C) 2024 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-static-semantics-modulerequests |
| 7 | description: > |
| 8 | `import defer` by itself does not trigger evaluation of sync modules |
| 9 | info: | |
| 10 | Static Semantics: ModuleRequests |
| 11 | ModuleItemList : ModuleItemList ModuleItem |
| 12 | 1. Let _requests_ be ModuleRequests of ModuleItemList. |
| 13 | 1. Let _additionalRequests_ be ModuleRequests of ModuleItem. |
| 14 | 1. For each ModuleRequest Record _mr_ of _additionalRequests_, do |
| 15 | 1. Let _found_ be false. |
| 16 | 1. For each ModuleRequest Record _mr2_ of _requests_, do |
| 17 | 1. If _mr_.[[Specifier]] is _mr2_.[[Specifier]] and _mr_.[[Phase]] is _mr2_.[[Phase]], then |
| 18 | 1. Assert: _found_ is false. |
| 19 | 1. Set _found_ to true. |
| 20 | 1. If _found_ is false, then |
| 21 | 1. Append _mr_ to _requests_. |
| 22 | 1. Return _requests_. |
| 23 | |
| 24 | 16.2.1.5.3.1 InnerModuleEvaluation ( _module_, _stack_, _index_ ) |
| 25 | 1. ... |
| 26 | 1. Let _evaluationList_ be a new empty List. |
| 27 | 1. For each ModuleRequest Record _required_ of _module_.[[RequestedModules]], do |
| 28 | 1. Let _requiredModule_ be GetImportedModule(_module_, _required_.[[Specifier]]). |
| 29 | 1. If _required_.[[Phase]] is ~defer~, then |
| 30 | i. Let _additionalModules_ be GatherAsynchronousTransitiveDependencies(_requiredModule_). |
| 31 | ii. For each Module Record _additionalModule_ of _additionalModules_, do |
| 32 | 1. If _evaluationList_ does not contain _additionalModule_, then |
| 33 | a. Append _additionalModule_ to _evaluationList_. |
| 34 | 1. Else if _evaluationList_ does not contain _requiredModule_, then |
| 35 | i. Append _requiredModule_ to _evaluationList_. |
| 36 | 1. ... |
| 37 | 1. For each Module Record _requiredModule_ of _evaluationList_, do |
| 38 | 1. Set _index_ to ? InnerModuleEvaluation(_requiredModule_, _stack_, _index_). |
| 39 | 1. ... |
| 40 | |
| 41 | flags: [module] |
| 42 | features: [import-defer] |
| 43 | includes: [compareArray.js] |
| 44 | ---*/ |
| 45 | |
| 46 | import "./setup_FIXTURE.js"; |
| 47 | |
| 48 | import defer * as ns1 from "./dep-1_FIXTURE.js"; |
| 49 | import "./dep-2_FIXTURE.js"; |
| 50 | import "./dep-1_FIXTURE.js"; |
| 51 | |
| 52 | assert.compareArray(globalThis.evaluations, [2, 1.1, 1], "the module is evaluated in the order where it's imported as non-deferred"); |
| 53 | |
| 54 | reportCompare(0, 0); |