tor-browser

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

browser_dbg-scopes.js (3691B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 "use strict";
      6 
      7 // Test that the values of the scope nodes are displayed correctly.
      8 add_task(async function testScopeNodes() {
      9  const dbg = await initDebugger("doc-script-switching.html");
     10 
     11  const ready = Promise.all([
     12    waitForPaused(dbg),
     13    waitForLoadedSource(dbg, "script-switching-02.js"),
     14 
     15    // MAP_FRAMES triggers a new Scopes panel render cycle, which introduces
     16    // a race condition with the click event on the foo node.
     17    waitForDispatch(dbg.store, "MAP_FRAMES"),
     18  ]);
     19  invokeInTab("firstCall");
     20  await ready;
     21 
     22  is(getScopeNodeLabel(dbg, 1), "secondCall");
     23  is(getScopeNodeLabel(dbg, 2), "<this>");
     24  is(getScopeNodeLabel(dbg, 4), "foo()");
     25  await toggleScopeNode(dbg, 4);
     26  is(getScopeNodeLabel(dbg, 5), "arguments");
     27 
     28  await stepOver(dbg);
     29  is(getScopeNodeLabel(dbg, 4), "foo()");
     30  is(getScopeNodeLabel(dbg, 5), "Window");
     31  is(getScopeNodeValue(dbg, 5), "Global");
     32 
     33  info("Resuming the thread");
     34  await resume(dbg);
     35 });
     36 
     37 // Test that the scope nodes for destructuring paramters are not displayed.
     38 add_task(async function testDestructuringParametersScopeNodes() {
     39  const dbg = await initDebuggerWithAbsoluteURL(
     40    "data:text/html;charset=utf8,<!DOCTYPE html><script>function foo({x}){debugger;};foo({x:2})</script>"
     41  );
     42 
     43  info("Reload the page to hit the debugger statement while loading");
     44  const onReloaded = reload(dbg);
     45  await waitForPaused(dbg);
     46  ok(true, "We're paused");
     47 
     48  info(
     49    "Checking all the nodes to assert that the scope node for the destructuring parameter is not displayed"
     50  );
     51  is(getScopeNodeLabel(dbg, 1), "foo");
     52  is(getScopeNodeLabel(dbg, 2), "<this>");
     53  is(getScopeNodeLabel(dbg, 3), "arguments");
     54  is(getScopeNodeLabel(dbg, 4), "x");
     55  is(getScopeNodeLabel(dbg, 5), "Window");
     56 
     57  info("Resuming the thread");
     58  await resume(dbg);
     59  await onReloaded;
     60 });
     61 
     62 // Test scope nodes for anonymous functions display correctly.
     63 add_task(async function testAnonymousScopeNodes() {
     64  const dbg = await initDebuggerWithAbsoluteURL(
     65    "data:text/html;charset=utf8,<!DOCTYPE html><script>(function(){const x = 3; debugger;})()</script>"
     66  );
     67 
     68  info("Reload the page to hit the debugger statement while loading");
     69  const onReloaded = reload(dbg);
     70  await waitForPaused(dbg);
     71  ok(true, "We're paused");
     72 
     73  is(
     74    getScopeNodeLabel(dbg, 1),
     75    "<anonymous>",
     76    "The scope node for the anonymous function is displayed correctly"
     77  );
     78 
     79  info("Resuming the thread");
     80  await resume(dbg);
     81  await onReloaded;
     82 });
     83 
     84 // Test scope nodes for __proto__ arg and variable
     85 add_task(async function testProtoScopeNodes() {
     86  const dbg = await initDebuggerWithAbsoluteURL(
     87    `data:text/html;charset=utf8,<!DOCTYPE html>
     88      <script>
     89        function testArgName(__proto__) {
     90          debugger;
     91        }
     92        function testVarName(name) {
     93          const __proto__ = name;
     94          debugger;
     95        }
     96      </script>`
     97  );
     98 
     99  info("Pause in testArgName");
    100  invokeInTab("testArgName", "peach");
    101  await waitForPaused(dbg);
    102 
    103  is(getScopeNodeLabel(dbg, 1), "testArgName");
    104  is(getScopeNodeLabel(dbg, 2), "__proto__");
    105  is(getScopeNodeValue(dbg, 2), `"peach"`);
    106 
    107  info("Resuming the thread");
    108  await resume(dbg);
    109 
    110  info("Pause in testVarName");
    111  invokeInTab("testVarName", "watermelon");
    112  await waitForPaused(dbg);
    113 
    114  is(getScopeNodeLabel(dbg, 1), "testVarName");
    115  is(getScopeNodeLabel(dbg, 2), "__proto__");
    116  is(getScopeNodeValue(dbg, 2), `"watermelon"`);
    117 
    118  info("Resuming the thread");
    119  await resume(dbg);
    120 });