tor-browser

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

dynamic-import-of-waiting-module.js (3353B)


      1 // |reftest| 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-ContinueDynamicImport
      7 description: >
      8  Dynamic import of an ~evaluating-async~ module waits for the module to finish its evaluation
      9 info: |
     10  ContinueDynamicImport ( _promiseCapability_, _moduleCompletion_ )
     11    1. ...
     12    1. Let _module_ be _moduleCompletion_.[[Value]].
     13    1. Let _loadPromise_ be _module_.LoadRequestedModules().
     14    1. Let _rejectedClosure_ be a new Abstract Closure with parameters (_reason_) that captures _promiseCapability_ and performs the following steps when called:
     15      1. Perform ! Call(_promiseCapability_.[[Reject]], *undefined*, « _reason_ »).
     16      1. Return ~unused~.
     17    1. Let _onRejected_ be CreateBuiltinFunction(_rejectedClosure_, 1, *""*, « »).
     18    1. Let _linkAndEvaluateClosure_ be a new Abstract Closure with no parameters that captures _module_, _promiseCapability_, and _onRejected_ and performs the following steps when called:
     19      1. Let _link_ be Completion(_module_.Link()).
     20      1. ...
     21      1. Let _evaluatePromise_ be _module_.Evaluate().
     22      1. Let _fulfilledClosure_ be a new Abstract Closure with no parameters that captures _module_ and _promiseCapability_ and performs the following steps when called:
     23        1. Let _namespace_ be GetModuleNamespace(_module_).
     24        1. Perform ! <emu-meta effects="user-code">Call</emu-meta>(_promiseCapability_.[[Resolve]], *undefined*, « _namespace_ »).
     25        1. Return ~unused~.
     26      1. Let _onFulfilled_ be CreateBuiltinFunction(_fulfilledClosure_, 0, *""*, « »).
     27      1. Perform PerformPromiseThen(_evaluatePromise_, _onFulfilled_, _onRejected_).
     28      1. Return ~unused~.
     29    1. Let _linkAndEvaluate_ be CreateBuiltinFunction(_linkAndEvaluateClosure_, 0, *""*, « »).
     30    1. Perform PerformPromiseThen(_loadPromise_, _linkAndEvaluate_, _onRejected_).
     31    1. Return ~unused~.
     32 
     33  _module_ . Evaluate (  )
     34    4. If _module_.[[TopLevelCapability]] is not ~empty~, then
     35       a. Return _module_.[[TopLevelCapability]].[[Promise]].
     36 
     37 flags: [async]
     38 features: [dynamic-import]
     39 includes: [asyncHelpers.js]
     40 ---*/
     41 
     42 let continueExecution;
     43 globalThis.promise = new Promise((resolve) => continueExecution = resolve);
     44 
     45 const executionStartPromise = new Promise((resolve) => globalThis.executionStarted = resolve);
     46 
     47 asyncTest(async function () {
     48  const promiseForNamespace = import("./dynamic-import-of-waiting-module_FIXTURE.js");
     49 
     50  await executionStartPromise;
     51 
     52  const promiseForNamespace2 = import("./dynamic-import-of-waiting-module_FIXTURE.js");
     53 
     54  // We only continue execution of the first fixture file after importing a second,
     55  // empty, fixture file. This is so that if the implementation uses a separate
     56  // queue to resolve dynamic import promises, if dynamic-import-of-waiting-module_FIXTURE
     57  // wasn't waiting on top-level await its top-level promise would already be resolved.
     58  await import("./dynamic-import-of-waiting-module-2_FIXTURE.js");
     59  continueExecution();
     60 
     61  let secondPromiseResolved = false;
     62  await Promise.all([
     63    promiseForNamespace.then(() => {
     64      assert(!secondPromiseResolved, "The second import should not resolve before the first one");
     65    }),
     66    promiseForNamespace2.then(() => {
     67      secondPromiseResolved = true;
     68    })
     69  ]);
     70 });