Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // When a recursive function has many frames on the stack, onStep may be set or |
michael@0 | 2 | // not independently on each frame. |
michael@0 | 3 | |
michael@0 | 4 | var g = newGlobal(); |
michael@0 | 5 | g.eval("function f(x) {\n" + |
michael@0 | 6 | " if (x > 0)\n" + |
michael@0 | 7 | " f(x - 1);\n" + |
michael@0 | 8 | " else\n" + |
michael@0 | 9 | " debugger;\n" + |
michael@0 | 10 | " return x;\n" + |
michael@0 | 11 | "}"); |
michael@0 | 12 | |
michael@0 | 13 | var dbg = Debugger(g); |
michael@0 | 14 | var seen = [0, 0, 0, 0, 0, 0, 0, 0]; |
michael@0 | 15 | function step() { |
michael@0 | 16 | seen[this.arguments[0]] = 1; |
michael@0 | 17 | } |
michael@0 | 18 | dbg.onEnterFrame = function (frame) { |
michael@0 | 19 | // Turn on stepping for even-numbered frames. |
michael@0 | 20 | var x = frame.arguments[0]; |
michael@0 | 21 | if (x % 2 === 0) |
michael@0 | 22 | frame.onStep = step; |
michael@0 | 23 | }; |
michael@0 | 24 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 25 | // This is called with 8 call frames on the stack, 7 down to 0. |
michael@0 | 26 | // At this point we should have seen all the even-numbered frames. |
michael@0 | 27 | assertEq(seen.join(""), "10101010"); |
michael@0 | 28 | |
michael@0 | 29 | // Now reset seen to see which frames fire onStep on the way out. |
michael@0 | 30 | seen = [0, 0, 0, 0, 0, 0, 0, 0]; |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | g.f(7); |
michael@0 | 34 | assertEq(seen.join(""), "10101010"); |