tor-browser

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

test_breakpoint-11.js (2392B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Make sure that setting a breakpoint in a line with bytecodes in multiple
      8 * scripts, sets the breakpoint in all of them (bug 793214).
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async ({ threadFront, debuggee }) => {
     13    const packet = await executeOnNextTickAndWaitForPause(
     14      () => evaluateTestCode(debuggee),
     15      threadFront
     16    );
     17    const source = await getSourceById(threadFront, packet.frame.where.actor);
     18    const location = {
     19      sourceUrl: source.url,
     20      line: debuggee.line0 + 2,
     21      column: 8,
     22    };
     23 
     24    //Pause at debugger statement.
     25    Assert.equal(packet.frame.where.line, debuggee.line0 + 1);
     26    Assert.equal(packet.why.type, "debuggerStatement");
     27 
     28    threadFront.setBreakpoint(location, {});
     29    await resume(threadFront);
     30 
     31    const packet2 = await waitForPause(threadFront);
     32 
     33    // Check the return value.
     34    Assert.equal(packet2.why.type, "breakpoint");
     35    // Check that the breakpoint worked.
     36    Assert.equal(debuggee.a, undefined);
     37    // Check execution location
     38    Assert.equal(packet2.frame.where.line, debuggee.line0 + 2);
     39    Assert.equal(packet2.frame.where.column, 8);
     40 
     41    // Remove the breakpoint.
     42    threadFront.removeBreakpoint(location);
     43 
     44    const location2 = {
     45      sourceUrl: source.url,
     46      line: debuggee.line0 + 2,
     47      column: 32,
     48    };
     49    threadFront.setBreakpoint(location2, {});
     50 
     51    await resume(threadFront);
     52    const packet3 = await waitForPause(threadFront);
     53 
     54    // Check the return value.
     55    Assert.equal(packet3.why.type, "breakpoint");
     56    // Check that the breakpoint worked.
     57    Assert.equal(debuggee.a.b, 1);
     58    Assert.equal(debuggee.res, undefined);
     59    // Check execution location
     60    Assert.equal(packet3.frame.where.line, debuggee.line0 + 2);
     61    Assert.equal(packet3.frame.where.column, 32);
     62 
     63    // Remove the breakpoint.
     64    threadFront.removeBreakpoint(location2);
     65 
     66    await resume(threadFront);
     67  })
     68 );
     69 
     70 function evaluateTestCode(debuggee) {
     71  // prettier-ignore
     72  Cu.evalInSandbox("var line0 = Error().lineNumber;\n" +
     73                   "debugger;\n" +                      // line0 + 1
     74                   "var a = { b: 1, f: function() { return 2; } };\n" + // line0+2
     75                   "var res = a.f();\n",               // line0 + 3
     76                   debuggee);
     77 }