tor-browser

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

Frame-identity-03.js (1327B)


      1 // Test that we create new Debugger.Frames and reuse old ones correctly with recursion.
      2 
      3 var g = newGlobal({newCompartment: true});
      4 g.debuggeeGlobal = this;
      5 g.eval("(" + function () {
      6        function id(f) {
      7            return ("id" in f) ? f.id : (f.id = nextid++);
      8        }
      9 
     10        var dbg = new Debugger(debuggeeGlobal);
     11        dbg.onDebuggerStatement = function (frame) {
     12            var a = [];
     13            for (; frame; frame = frame.older)
     14                a.push(frame);
     15            var s = '';
     16            while (a.length)
     17                s += id(a.pop());
     18            results.push(s);
     19        };
     20    } + ")();");
     21 
     22 function cons(a, b) {
     23    debugger;
     24    return [a, b];
     25 }
     26 
     27 function tree(n) {
     28    if (n < 2)
     29        return n;
     30    return cons(tree(n - 1), tree(n - 2));
     31 }
     32 
     33 g.eval("results = []; nextid = 0;");
     34 debugger;
     35 assertEq(g.results.join(","), "0");
     36 assertEq(g.nextid, 1);
     37 
     38 g.eval("results = [];");
     39 tree(2);
     40 assertEq(g.results.join(","), "012"); // 0=global, 1=tree, 2=cons
     41 
     42 g.eval("results = []; nextid = 1;");
     43 tree(3);
     44 assertEq(g.results.join(","), "0123,014"); //0=global, 1=tree(3), 2=tree(2), 3=cons, 4=cons
     45 
     46 g.eval("results = []; nextid = 1;");
     47 tree(4);
     48 // 0=global, 1=tree(4), 2=tree(3), 3=tree(2), 4=cons, tree(1), 5=cons, 6=tree(2), 7=cons, 8=cons
     49 assertEq(g.results.join(","), "01234,0125,0167,018");