tor-browser

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

browser_jsterm_await_dynamic_import.js (1328B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that top-level await with dynamic import works as expected.
      5 
      6 "use strict";
      7 
      8 const TEST_URI =
      9  "http://example.com/browser/devtools/client/webconsole/test/browser/test-dynamic-import.html";
     10 
     11 add_task(async function () {
     12  // Enable dynamic import
     13  await pushPref("javascript.options.dynamicImport", true);
     14  // Enable await mapping.
     15  await pushPref("devtools.debugger.features.map-await-expression", true);
     16 
     17  const hud = await openNewTabAndConsole(TEST_URI);
     18 
     19  info("Evaluate an expression with a dynamic import");
     20  let importAwaitExpression = `
     21    var {sum} = await import("./test-dynamic-import.mjs");
     22    sum(1, 2, 3);
     23  `;
     24  await executeAndWaitForResultMessage(
     25    hud,
     26    importAwaitExpression,
     27    `1 + 2 + 3 = 6`
     28  );
     29  ok(true, "The `sum` module was imported and used successfully");
     30 
     31  info("Import the same module a second time");
     32  // This used to make the content page crash (See Bug 1523897).
     33  importAwaitExpression = `
     34    var {sum} = await import("./test-dynamic-import.mjs");
     35    sum(2, 3, 4);
     36  `;
     37  await executeAndWaitForResultMessage(
     38    hud,
     39    importAwaitExpression,
     40    `2 + 3 + 4 = 9`
     41  );
     42  ok(true, "The `sum` module was imported and used successfully a second time");
     43 });