tor-browser

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

Script-getChildScripts-01.js (1083B)


      1 // Basic getChildScripts tests.
      2 
      3 var g = newGlobal({newCompartment: true});
      4 var dbg = new Debugger(g);
      5 var log;
      6 function note(s) {
      7    assertEq(s instanceof Debugger.Script, true);
      8    log += 'S';
      9    var c = s.getChildScripts();
     10    if (c.length > 0) {
     11        log += '[';
     12        for (var i = 0; i < c.length; i++)
     13            note(c[i]);
     14        log += ']';
     15    }
     16 }
     17 dbg.onDebuggerStatement = function (frame) { note(frame.script); };
     18 
     19 function test(code, expected) {
     20    log = '';
     21    g.eval(code);
     22    assertEq(log, expected);
     23 }
     24 
     25 test("debugger;",
     26     "S");
     27 test("function f() {} debugger;",
     28     "S[S]");
     29 test("function g() { function h() { function k() {} return k; } return h; } debugger;",
     30     "S[S[S[S]]]");
     31 test("function q() {} function qq() {} debugger;",
     32     "S[SS]");
     33 test("[0].map(function id(a) { return a; }); debugger;",
     34     "S[S]");
     35 test("Function('return 2+2;')(); debugger;",
     36     "S");
     37 test("var obj = {get x() { return 0; }, set x(v) {}}; debugger;",
     38     "S[SS]");
     39 test("function* qux(n) { for (var i = 0; i < n; i++) yield i; } debugger;",
     40     "S[S]");