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 | // Check whether we respect resumption values when toggling debug mode on->off |
michael@0 | 2 | // from various points with live scripts on the stack. |
michael@0 | 3 | |
michael@0 | 4 | var g = newGlobal(); |
michael@0 | 5 | var dbg = new Debugger; |
michael@0 | 6 | |
michael@0 | 7 | function reset() { |
michael@0 | 8 | dbg.onEnterFrame = undefined; |
michael@0 | 9 | dbg.onDebuggerStatement = undefined; |
michael@0 | 10 | dbg.addDebuggee(g); |
michael@0 | 11 | g.eval("(" + function test() { |
michael@0 | 12 | for (i = 0; i < 5; i++) |
michael@0 | 13 | f(42); |
michael@0 | 14 | } + ")();"); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | g.eval("" + function f(d) { |
michael@0 | 18 | return g(d); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | g.eval("" + function g(d) { |
michael@0 | 22 | debugger; |
michael@0 | 23 | return d; |
michael@0 | 24 | }); |
michael@0 | 25 | |
michael@0 | 26 | function testResumptionValues(handlerSetter) { |
michael@0 | 27 | // Test normal return. |
michael@0 | 28 | reset(); |
michael@0 | 29 | handlerSetter(undefined); |
michael@0 | 30 | assertEq(g.eval("(" + function test() { return f(42); } + ")();"), 42); |
michael@0 | 31 | |
michael@0 | 32 | // Test forced return. |
michael@0 | 33 | reset(); |
michael@0 | 34 | handlerSetter({ return: "not 42" }); |
michael@0 | 35 | assertEq(g.eval("(" + function test() { return f(42); } + ")();"), "not 42"); |
michael@0 | 36 | |
michael@0 | 37 | // Test throw. |
michael@0 | 38 | reset(); |
michael@0 | 39 | handlerSetter({ throw: "thrown 42" }); |
michael@0 | 40 | try { |
michael@0 | 41 | g.eval("(" + function test() { return f(42); } + ")();");; |
michael@0 | 42 | } catch (e) { |
michael@0 | 43 | assertEq(e, "thrown 42"); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | // Turn off from within the prologue. |
michael@0 | 48 | testResumptionValues(function (resumptionVal) { |
michael@0 | 49 | dbg.onEnterFrame = function (frame) { |
michael@0 | 50 | if (frame.older) { |
michael@0 | 51 | if (frame.older.older) { |
michael@0 | 52 | dbg.removeDebuggee(g); |
michael@0 | 53 | return resumptionVal; |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | }; |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | // Turn off from within the epilogue. |
michael@0 | 60 | testResumptionValues(function (resumptionVal) { |
michael@0 | 61 | dbg.onEnterFrame = function (frame) { |
michael@0 | 62 | if (frame.older) { |
michael@0 | 63 | if (frame.older.older) { |
michael@0 | 64 | frame.onPop = function () { |
michael@0 | 65 | dbg.removeDebuggee(g); |
michael@0 | 66 | return resumptionVal; |
michael@0 | 67 | }; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | }; |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | // Turn off from within debugger statement handler. |
michael@0 | 74 | testResumptionValues(function (resumptionVal) { |
michael@0 | 75 | dbg.onDebuggerStatement = function (frame) { |
michael@0 | 76 | dbg.removeDebuggee(g); |
michael@0 | 77 | return resumptionVal; |
michael@0 | 78 | }; |
michael@0 | 79 | }); |
michael@0 | 80 | |
michael@0 | 81 | // Turn off from within debug trap handler. |
michael@0 | 82 | testResumptionValues(function (resumptionVal) { |
michael@0 | 83 | dbg.onEnterFrame = function (frame) { |
michael@0 | 84 | if (frame.older) { |
michael@0 | 85 | if (frame.older.older) { |
michael@0 | 86 | frame.onStep = function () { |
michael@0 | 87 | dbg.removeDebuggee(g); |
michael@0 | 88 | return resumptionVal; |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | }; |
michael@0 | 93 | }); |