tor-browser

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

test_breakpoint-03.js (2620B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* eslint-disable no-shadow, max-nested-callbacks */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Check that setting a breakpoint on a line without code will skip
      9 * forward when we know the script isn't GCed (the debugger is connected,
     10 * so it's kept alive).
     11 */
     12 
     13 var test_no_skip_breakpoint = async function (source, location, debuggee) {
     14  const [response, bpClient] = await source.setBreakpoint(
     15    Object.assign({}, location, { noSliding: true })
     16  );
     17 
     18  Assert.ok(!response.actualLocation);
     19  Assert.equal(bpClient.location.line, debuggee.line0 + 3);
     20  await bpClient.remove();
     21 };
     22 
     23 add_task(
     24  threadFrontTest(({ threadFront, debuggee }) => {
     25    return new Promise(resolve => {
     26      threadFront.once("paused", async function (packet) {
     27        const location = { line: debuggee.line0 + 3 };
     28        const source = await getSourceById(
     29          threadFront,
     30          packet.frame.where.actor
     31        );
     32        // First, make sure that we can disable sliding with the
     33        // `noSliding` option.
     34        await test_no_skip_breakpoint(source, location, debuggee);
     35 
     36        // Now make sure that the breakpoint properly slides forward one line.
     37        const [response, bpClient] = await source.setBreakpoint(location);
     38        Assert.ok(!!response.actualLocation);
     39        Assert.equal(response.actualLocation.source.actor, source.actor);
     40        Assert.equal(response.actualLocation.line, location.line + 1);
     41 
     42        threadFront.once("paused", function (packet) {
     43          // Check the return value.
     44          Assert.equal(packet.frame.where.actor, source.actor);
     45          Assert.equal(packet.frame.where.line, location.line + 1);
     46          Assert.equal(packet.why.type, "breakpoint");
     47          Assert.equal(packet.why.actors[0], bpClient.actor);
     48          // Check that the breakpoint worked.
     49          Assert.equal(debuggee.a, 1);
     50          Assert.equal(debuggee.b, undefined);
     51 
     52          // Remove the breakpoint.
     53          bpClient.remove(function () {
     54            threadFront.resume().then(resolve);
     55          });
     56        });
     57 
     58        threadFront.resume();
     59      });
     60 
     61      // Use `evalInSandbox` to make the debugger treat it as normal
     62      // globally-scoped code, where breakpoint sliding rules apply.
     63      // prettier-ignore
     64      Cu.evalInSandbox(
     65        "var line0 = Error().lineNumber;\n" +
     66        "debugger;\n" +      // line0 + 1
     67        "var a = 1;\n" +     // line0 + 2
     68        "// A comment.\n" +  // line0 + 3
     69        "var b = 2;",        // line0 + 4
     70        debuggee
     71      );
     72    });
     73  })
     74 );