tor-browser

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

browser_jsterm_await_assignments.js (2286B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test that top-level await expressions work as expected.
      5 
      6 "use strict";
      7 
      8 const TEST_URI =
      9  "data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test top-level await bindings";
     10 
     11 add_task(async function () {
     12  // Enable await mapping.
     13  await pushPref("devtools.debugger.features.map-await-expression", true);
     14  const hud = await openNewTabAndConsole(TEST_URI);
     15 
     16  info("Check that declaring a let variable does not create a global property");
     17  await executeAndWaitForResultMessage(
     18    hud,
     19    `let bazA = await new Promise(r => setTimeout(() => r("local-bazA"), 10))`,
     20    "local-bazA"
     21  );
     22  await checkVariable(hud, "bazA");
     23 
     24  info(
     25    "Check that declaring a const variable does not create a global property"
     26  );
     27  await executeAndWaitForResultMessage(
     28    hud,
     29    `const bazB = await new Promise(r => setTimeout(() => r("local-bazB"), 10))`,
     30    "local-bazB"
     31  );
     32  await checkVariable(hud, "bazB");
     33 
     34  info("Check that complex variable declarations work as expected");
     35  await executeAndWaitForResultMessage(
     36    hud,
     37    `
     38    let bazC = "local-bazC", bazD, bazE = "local-bazE";
     39    bazD = await new Promise(r => setTimeout(() => r("local-bazD"), 10));
     40    let {
     41      a: bazF,
     42      b: {
     43        c: {
     44          bazG = "local-bazG",
     45          d: bazH,
     46          e: [bazI, bazJ = "local-bazJ"]
     47        },
     48        d: bazK = "local-bazK"
     49      }
     50    } = await ({
     51      a: "local-bazF",
     52      b: {
     53        c: {
     54          d: "local-bazH",
     55          e: ["local-bazI"]
     56        }
     57      }
     58    });`,
     59    ""
     60  );
     61  await checkVariable(hud, "bazC");
     62  await checkVariable(hud, "bazD");
     63  await checkVariable(hud, "bazE");
     64  await checkVariable(hud, "bazF");
     65  await checkVariable(hud, "bazG");
     66  await checkVariable(hud, "bazH");
     67  await checkVariable(hud, "bazI");
     68  await checkVariable(hud, "bazJ");
     69  await checkVariable(hud, "bazK");
     70 });
     71 
     72 async function checkVariable(hud, varName) {
     73  await executeAndWaitForResultMessage(hud, `window.${varName}`, `undefined`);
     74  ok(true, `The ${varName} assignment did not create a global variable`);
     75  await executeAndWaitForResultMessage(hud, varName, `"local-${varName}"`);
     76  ok(true, `"${varName}" has the expected value`);
     77 }