js/src/jit-test/tests/debug/Frame-identity-03.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial