tor-browser

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

test_nesting-04.js (2783B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Verify that we never pause while being already paused.
      8 * i.e. we don't support more than one nested event loops.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(async ({ commands, threadFront, debuggee }) => {
     13    await threadFront.setBreakpoint({ sourceUrl: "nesting-04.js", line: 2 });
     14 
     15    const packet = await executeOnNextTickAndWaitForPause(
     16      () => evalCode(debuggee),
     17      threadFront
     18    );
     19 
     20    Assert.equal(packet.frame.where.line, 5);
     21    Assert.equal(packet.why.type, "debuggerStatement");
     22 
     23    info("Test calling interrupt");
     24    const onPaused = waitForPause(threadFront);
     25    await threadFront.interrupt();
     26    // interrupt() doesn't return anything, but bailout while emitting a paused packet
     27    // But we don't pause again, the reason prove it so
     28    const paused = await onPaused;
     29    equal(paused.why.type, "alreadyPaused");
     30 
     31    info("Test by evaluating code via the console");
     32    const { result } = await commands.scriptCommand.execute(
     33      "debugger; functionWithDebuggerStatement()",
     34      {
     35        frameActor: packet.frame.actorID,
     36      }
     37    );
     38    // The fact that it returned immediately means that we did not pause
     39    equal(result, 42);
     40 
     41    info("Test by calling code from chrome context");
     42    // This should be equivalent to any actor somehow triggering some page's JS
     43    const rv = debuggee.functionWithDebuggerStatement();
     44    // The fact that it returned immediately means that we did not pause
     45    equal(rv, 42);
     46 
     47    info("Test by stepping over a function that breaks");
     48    // This will only step over the debugger; statement we just break on
     49    const step1 = await stepOver(threadFront);
     50    equal(step1.why.type, "resumeLimit");
     51    equal(step1.frame.where.line, 6);
     52 
     53    // stepOver will actually resume and re-pause on the breakpoint
     54    const step2 = await stepOver(threadFront);
     55    equal(step2.why.type, "breakpoint");
     56    equal(step2.frame.where.line, 2);
     57 
     58    // Sanity check to ensure that the functionWithDebuggerStatement really pauses
     59    info("Resume and pause on the breakpoint");
     60    const pausedPacket = await resumeAndWaitForPause(threadFront);
     61    Assert.equal(pausedPacket.frame.where.line, 2);
     62    // The breakpoint takes over the debugger statement
     63    Assert.equal(pausedPacket.why.type, "breakpoint");
     64 
     65    await threadFront.resume();
     66  })
     67 );
     68 
     69 function evalCode(debuggee) {
     70  /* eslint-disable */
     71  Cu.evalInSandbox(
     72    `function functionWithDebuggerStatement() {
     73      debugger;
     74      return 42;
     75    }
     76    debugger;
     77    functionWithDebuggerStatement();
     78    var a = 1;
     79    functionWithDebuggerStatement();`,
     80    debuggee,
     81    "1.8",
     82    "nesting-04.js",
     83    1
     84  );
     85  /* eslint-enable */
     86 }