tor-browser

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

Script-startColumn.js (1836B)


      1 // Script.prototype.startColumn returns the correct column for all scripts.
      2 
      3 const g = newGlobal({newCompartment: true, useWindowProxy: true});
      4 const dbg = Debugger(g);
      5 const gw = dbg.addDebuggee(g);
      6 
      7 function test(f, expected) {
      8    const fw = gw.makeDebuggeeValue(f);
      9    assertEq(fw.callable, true);
     10    assertEq(fw.script.startColumn, expected);
     11 }
     12 
     13 g.eval(`
     14 function f1() { }
     15 `);
     16 test(g.f1, 12);
     17 
     18 g.eval(`
     19 var f2 = function({ a, b, c }, d, e, ...more) { };
     20 `);
     21 test(g.f2, 18);
     22 
     23 g.eval(`
     24 var f3 = function *() { };
     25 `);
     26 test(g.f3, 20);
     27 
     28 g.eval(`
     29 var f4 = async function
     30  () { };
     31 `);
     32 test(g.f4, 3);
     33 
     34 g.eval(`
     35 var f5 = (a, b) => a + b;
     36 `);
     37 test(g.f5, 10);
     38 
     39 g.eval(`
     40 var f6 = a => a + 1;
     41 `);
     42 test(g.f6, 10);
     43 
     44 g.eval(`
     45 var MyClass = class {
     46    method() { }
     47 };
     48 var myInstance = new MyClass();
     49 `);
     50 test(g.myInstance.method, 11);
     51 test(g.myInstance.constructor, 15);
     52 
     53 const g2 = newGlobal({newCompartment: true, useWindowProxy: true});
     54 const dbg2 = Debugger(g2);
     55 const g2Wrapped = dbg2.addDebuggee(g2);
     56 g2.evaluate(`
     57 function f7() { }
     58 `, {
     59  forceFullParse: true,
     60 });
     61 const f7w = g2Wrapped.makeDebuggeeValue(g2.f7);
     62 assertEq(f7w.callable, true);
     63 assertEq(f7w.script.startColumn, 12);
     64 
     65 g.eval(`
     66 function f8() {
     67    return function f8Inner() { }
     68 }
     69 `);
     70 test(g.f8, 12);
     71 test(g.f8(), 28);
     72 
     73 g.eval(`
     74 var f9 = new Function(\"\");
     75 `);
     76 test(g.f9, 1);
     77 
     78 let hit = 0;
     79 let column;
     80 dbg.onDebuggerStatement = function (frame) {
     81    column = frame.script.startColumn;
     82    hit += 1;
     83 };
     84 
     85 g.eval(`    debugger;`);
     86 assertEq(column, 1);
     87 assertEq(hit, 1);
     88 
     89 const location = { fileName: "column.js", lineNumber: 1, columnNumber: 1 };
     90 hit = 0;
     91 g.evaluate(`    debugger;`, location);
     92 assertEq(column, 1);
     93 assertEq(hit, 1);
     94 
     95 g.evaluate(`var f10 = function () { };`, location);
     96 test(g.f10, 20);
     97 
     98 g.evaluate(`
     99 var f11 = function () { };
    100 `, location);
    101 test(g.f11, 20);