tor-browser

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

Script-getPossibleBreakpoints-02.js (3483B)


      1 var global = newGlobal({newCompartment: true});
      2 var dbg = Debugger(global);
      3 dbg.onDebuggerStatement = onDebuggerStatement;
      4 
      5 global.eval(`
      6  debugger;
      7  function f() {
      8    var o = {};         // 4
      9 
     10    o.a; o.a; o.a; o.a; // 6
     11    o.a; o.a;           // 7
     12    o.a; o.a; o.a;      // 8
     13    o.a;                // 9
     14  }                     // 10
     15 `);
     16 
     17 function onDebuggerStatement(frame) {
     18  const fScript = frame.script.getChildScripts()[0];
     19 
     20  const allBreakpoints = fScript.getPossibleBreakpoints();
     21  assertEq(allBreakpoints.length, 12);
     22 
     23  assertBPCount({ line: 4 }, 1);
     24  assertBPCount({ line: 5 }, 0);
     25  assertBPCount({ line: 6 }, 4);
     26  assertBPCount({ line: 7 }, 2);
     27  assertBPCount({ line: 8 }, 3);
     28  assertBPCount({ line: 9 }, 1);
     29  assertBPCount({ line: 10 }, 1);
     30 
     31  assertBPCount({ line: 6, minColumn: 8 }, 3);
     32  assertBPCount({ line: 6, maxColumn: 17 }, 3);
     33  assertBPCount({ line: 6, minColumn: 8, maxColumn: 17 }, 2);
     34  assertBPError({ line: 1, minLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
     35  assertBPError({ line: 1, maxLine: 1 }, "line", "not allowed alongside 'minLine'/'maxLine'");
     36  assertBPError({ line: "1" }, "line", "not an integer");
     37 
     38  assertBPCount({ minLine: 9 }, 2);
     39  assertBPCount({ minLine: 9, minColumn: 1 }, 2);
     40  assertBPCount({ minLine: 9, minColumn: 9 }, 1);
     41  assertBPError({ minLine: "1" }, "minLine", "not an integer");
     42  assertBPError({ minColumn: 2 }, "minColumn", "not allowed without 'line' or 'minLine'");
     43  assertBPError({ minLine: 1, minColumn: "2" }, "minColumn", "not a positive integer in valid range");
     44  assertBPError({ minLine: 1, minColumn: 0 }, "minColumn", "not a positive integer in valid range");
     45  assertBPError({ minLine: 1, minColumn: -1 }, "minColumn", "not a positive integer in valid range");
     46 
     47  assertBPCount({ maxLine: 7 }, 5);
     48  assertBPCount({ maxLine: 7, maxColumn: 1 }, 5);
     49  assertBPCount({ maxLine: 7, maxColumn: 9 }, 6);
     50  assertBPError({ maxLine: "1" }, "maxLine", "not an integer");
     51  assertBPError({ maxColumn: 2 }, "maxColumn", "not allowed without 'line' or 'maxLine'");
     52  assertBPError({ maxLine: 1, maxColumn: "2" }, "maxColumn", "not a positive integer in valid range");
     53  assertBPError({ maxLine: 1, maxColumn: 0 }, "maxColumn", "not a positive integer in valid range");
     54  assertBPError({ maxLine: 1, maxColumn: -1 }, "maxColumn", "not a positive integer in valid range");
     55 
     56  assertBPCount({ minLine: 6, maxLine: 8 }, 6);
     57  assertBPCount({ minLine: 6, minColumn: 9, maxLine: 8 }, 5);
     58  assertBPCount({ minLine: 6, maxLine: 8, maxColumn: 9 }, 7);
     59  assertBPCount({ minLine: 6, minColumn: 9, maxLine: 8, maxColumn: 9 }, 6);
     60 
     61  assertBPCount({
     62    minOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
     63  }, 8);
     64  assertBPError({ minOffset: "1" }, "minOffset", "not an integer");
     65  assertBPCount({
     66    maxOffset: fScript.getPossibleBreakpoints({ line: 6 })[3].offset,
     67  }, 4);
     68  assertBPError({ maxOffset: "1" }, "maxOffset", "not an integer");
     69  assertBPCount({
     70    minOffset: fScript.getPossibleBreakpoints({ line: 6 })[2].offset,
     71    maxOffset: fScript.getPossibleBreakpoints({ line: 7 })[1].offset,
     72  }, 3);
     73 
     74  function assertBPError(query, field, message) {
     75    try {
     76      fScript.getPossibleBreakpoints(query);
     77      assertEq(false, true);
     78    } catch (err) {
     79      assertEq(err.message, `getPossibleBreakpoints' '${field}' is ${message}`);
     80    }
     81  }
     82 
     83  function assertBPCount(query, count) {
     84    assertEq(fScript.getPossibleBreakpoints(query).length, count);
     85  }
     86 };