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