tor-browser

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

Debugger-findScripts-32.js (9551B)


      1 // Debugger.prototype.findScripts can filter scripts by start and end line and column.
      2 load(libdir + "asserts.js");
      3 
      4 function assertThrowsTypeError(query) {
      5    assertThrowsInstanceOf(() => dbg.findScripts(query), TypeError);
      6 }
      7 function assertFound(query, scriptWrapper) {
      8    assertEq(dbg.findScripts(query).includes(scriptWrapper), true, `Script not found, but should be (query: ${JSON.stringify(query)})`);
      9 }
     10 function assertNotFound(query, scriptWrapper) {
     11    assertEq(dbg.findScripts(query).includes(scriptWrapper), false, `Script found but should not be (query: ${JSON.stringify(query)})`);
     12 }
     13 
     14 var g = newGlobal({newCompartment: true});
     15 var dbg = new Debugger();
     16 var gw = dbg.addDebuggee(g);
     17 
     18 var scriptname = scriptdir + 'Debugger-findScripts-32-script';
     19 g.load(scriptname);
     20 
     21 var gfw = gw.makeDebuggeeValue(g.f);
     22 var ggw = gw.makeDebuggeeValue(g.f());
     23 var ghw = gw.makeDebuggeeValue(g.h);
     24 var gjw = gw.makeDebuggeeValue(g.j);
     25 
     26 // actors/source.js uses {start: ..., end:...} for the query
     27 // {url:scriptName, start:{ line: 3, column: 0}, end:{line: 3, column: Infinity}}
     28 // NOTE: 'start.line' and 'end.line' are 1-origin, like 'line'
     29 // NOTE: 'start.column' and 'end.column' are 1-origin
     30 
     31 // 'start' correct types
     32 assertThrowsTypeError({url:scriptname, start:3, end: {line: 8}});
     33 assertThrowsTypeError({url:scriptname, start:"hi", end: {line: 8}});
     34 assertThrowsTypeError({url:scriptname, start: {line: .34}, end: {line: 8}});
     35 assertThrowsTypeError({url:scriptname, start: {line: -1}, end: {line: 8}});
     36 assertThrowsTypeError({url:scriptname, start: {line: {}}, end: {line: 8}});
     37 // 'end' correct types
     38 assertThrowsTypeError({url:scriptname, start: {line: 8}, end:3});
     39 assertThrowsTypeError({url:scriptname, start: {line: 8}, end:"hi"});
     40 assertThrowsTypeError({url:scriptname, start: {line: 8}, end: {line: .34}});
     41 assertThrowsTypeError({url:scriptname, start: {line: 8}, end: {line: -1}});
     42 assertThrowsTypeError({url:scriptname, start: {line: 8}, end: {line: {}}});
     43 // 'start' requires 'end'
     44 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 8}}), Error);
     45 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, line: 3, start: {line: 8}}), Error);
     46 // 'end' requires 'start'
     47 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, end: {line: 8}}), Error);
     48 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, line: 4, end: {line: 8}}), Error);
     49 // 'start'/'end' takes priority over 'line'
     50 assertNotFound({url:scriptname, line: 8, start: {line: 3}, end: {line: 3}}, gfw.script);
     51 assertFound({url:scriptname, line: 3, start: {line: 8}, end: {line: 8}}, gfw.script);
     52 
     53 // 'start'/'end' requires 'displayURL'/'url'/'source' like 'line'
     54 assertThrowsTypeError({start: {line: 8}, end: {line: 8}});
     55 assertFound({source:gfw.script.source, start: {line: 8}, end: {line: 8}}, gfw.script);
     56 // won't TypeError is the important thing here
     57 assertNotFound({displayURL:"f.js", start: {line: 8}, end: {line: 8}}, gfw.script);
     58 
     59 // 'start' and 'end'
     60 // 'start' after,  'end' after the function
     61 assertNotFound({url:scriptname, start: {line: 14}, end: {line: 16}}, gfw.script);
     62 // 'start' in,     'end' after
     63 assertFound({url:scriptname, start: {line: 8}, end: {line: 16}}, gfw.script);
     64 // 'start' in,     'end' in
     65 assertFound({url:scriptname, start: {line: 8}, end: {line: 11}}, gfw.script);
     66 // 'start' before, 'end' after
     67 assertFound({url:scriptname, start: {line: 6}, end: {line: 13}}, gfw.script);
     68 // 'start' before, 'end' in
     69 assertFound({url:scriptname, start: {line: 6}, end: {line: 10}}, gfw.script);
     70 // 'start' before, 'end' before
     71 assertNotFound({url:scriptname, start: {line: 4}, end: {line: 6}}, gfw.script);
     72 // 'start.line' and 'end.line' are inclusive
     73 assertFound({url:scriptname, start: {line: 6}, end: {line: 7}}, gfw.script);
     74 assertFound({url:scriptname, start: {line: 12}, end: {line: 12}}, gfw.script);
     75 assertFound({url:scriptname, start: {line: 20}, end: {line: 20}}, gjw.script);
     76 // 'start' after 'end'
     77 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 20}, end: {line: 7}}), Error);
     78 
     79 // innermost filter
     80 assertFound({url:scriptname, innermost: true, start: {line: 20}, end: {line: 20}}, gjw.script);
     81 assertFound({url:scriptname, innermost: true, start: {line: 6}, end: {line: 9}}, ggw.script);
     82 assertFound({url:scriptname, innermost: true, start: {line: 6}, end: {line: 13}}, ggw.script);
     83 assertFound({url:scriptname, innermost: true, start: {line: 11}, end: {line: 13}}, ggw.script);
     84 
     85 // Specifying a line range outside of all functions screens out all function scripts.
     86 assertNotFound({url:scriptname, start: {line: 4}, end: {line: 6}}, gfw.script);
     87 assertNotFound({url:scriptname, start: {line: 4}, end: {line: 6}}, ggw.script);
     88 assertNotFound({url:scriptname, start: {line: 4}, end: {line: 6}}, ghw.script);
     89 
     90 // A line range within a nested function selects all enclosing functions' scripts.
     91 assertFound({url:scriptname, start: {line: 10}, end: {line: 11}}, gfw.script);
     92 assertFound({url:scriptname, start: {line: 10}, end: {line: 11}}, ggw.script);
     93 assertNotFound({url:scriptname, start: {line: 10}, end: {line: 11}}, ghw.script);
     94 
     95 // A line range outside a non-nested function does not select that function.
     96 assertNotFound({url:scriptname, start: {line: 7}, end: {line: 8}}, ggw.script);
     97 
     98 // columns
     99 
    100 // 'start.column' correct types
    101 assertThrowsTypeError({url:scriptname, start: {line: 6, column: "hi"}, end: {line: 10}});
    102 assertThrowsTypeError({url:scriptname, start: {line: 6, column: {}}, end: {line: 10}});
    103 // 'start.column' correct range
    104 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6, column: .34}, end: {line: 10}}), RangeError);
    105 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6, column: -11}, end: {line: 10}}), RangeError);
    106 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6, column: 0}, end: {line: 10}}), RangeError);
    107 // Columns are limited to 31 bits; see JS::ColumnNumberOneOriginLimit
    108 const COLUMN_LIMIT = Math.pow(2,31) / 2 - 1;
    109 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6, column: COLUMN_LIMIT + 1}, end: {line: 10}}), RangeError);
    110 assertFound({url:scriptname, start: {line: 6, column: COLUMN_LIMIT}, end: {line: 10}}, gfw.script);
    111 // 'end.column' correct types
    112 assertThrowsTypeError({url:scriptname, start: {line: 6}, end: {line: 10, column: "hi"}});
    113 assertThrowsTypeError({url:scriptname, start: {line: 6}, end: {line: 10, column: {}}});
    114 // 'end.column' correct range
    115 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6}, end: {line: 10, column: .34}}), RangeError);
    116 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6}, end: {line: 10, column: -11}}), RangeError);
    117 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6}, end: {line: 10, column: 0}}), RangeError);
    118 assertThrowsInstanceOf(() => dbg.findScripts({url:scriptname, start: {line: 6}, end: {line: 10, column: COLUMN_LIMIT + 1}}), RangeError);
    119 assertFound({url:scriptname, start: {line: 6}, end: {line: 10, column: COLUMN_LIMIT}}, gfw.script);
    120 
    121 // 'start.column'
    122 assertFound({url:scriptname, start: {line: 19, column: 10}, end: {line: 20}}, gjw.script);
    123 assertFound({url:scriptname, start: {line: 19, column: 11}, end: {line: 20}}, gjw.script);
    124 assertFound({url:scriptname, start: {line: 19, column: 24}, end: {line: 20}}, gjw.script);
    125 assertFound({url:scriptname, start: {line: 19, column: 33}, end: {line: 20}}, gjw.script);
    126 
    127 assertFound({url:scriptname, start: {line: 20, column: 10}, end: {line: 20}}, gjw.script);
    128 assertFound({url:scriptname, start: {line: 20, column: 11}, end: {line: 20}}, gjw.script);
    129 assertFound({url:scriptname, start: {line: 20, column: 24}, end: {line: 20}}, gjw.script);
    130 // 'start.column' is past the end of the function
    131 assertNotFound({url:scriptname, start: {line: 20, column: 33}, end: {line: 20}}, gjw.script);
    132 assertFound({url:scriptname, start: {line: 20, column: 32}, end: {line: 20}}, gjw.script);
    133 assertNotFound({url:scriptname, start: {line: 11, column: 5}, end: {line: 13}}, ggw.script);
    134 assertFound({url:scriptname, start: {line: 11, column: 4}, end: {line: 13}}, ggw.script);
    135 
    136 assertFound({url:scriptname, start: {line: 20, column: 10}, end: {line: 21}}, gjw.script);
    137 assertFound({url:scriptname, start: {line: 20, column: 11}, end: {line: 21}}, gjw.script);
    138 assertFound({url:scriptname, start: {line: 20, column: 24}, end: {line: 21}}, gjw.script);
    139 
    140 // 'end.column' only considered when script.startLine == endLine
    141 assertFound({url:scriptname, start: {line: 6}, end: {line: 10, column: 5}}, gfw.script);
    142 assertFound({url:scriptname, start: {line: 7}, end: {line: 10, column: 5}}, gfw.script);
    143 assertFound({url:scriptname, start: {line: 6}, end: {line: 7, column: 11}}, gfw.script);
    144 assertNotFound({url:scriptname, start: {line: 6}, end: {line: 7, column: 5}}, gfw.script);
    145 assertNotFound({url:scriptname, start: {line: 19}, end: {line: 20, column: 10}}, gjw.script);
    146 assertFound({url:scriptname, start: {line: 19}, end: {line: 20, column: 11}}, gjw.script);
    147 
    148 // both 'start.column' and 'end.column'
    149 assertFound({url:scriptname, start: {line: 20, column: 11}, end: {line: 20, column: 23}}, gjw.script);
    150 assertNotFound({url:scriptname, start: {line: 20, column: 1}, end: {line: 20, column: 10}}, gjw.script);
    151 assertNotFound({url:scriptname, start: {line: 20, column: 33}, end: {line: 20, column: 35}}, gjw.script);
    152 // 'start.column' > 'end.column'
    153 assertNotFound({url:scriptname, start: {line: 20, column: 7}, end: {line: 20, column: 5}}, gfw.script);