|
1 // Check whether we respect resumption values when toggling debug mode on->off |
|
2 // from various points with live scripts on the stack. |
|
3 |
|
4 var g = newGlobal(); |
|
5 var dbg = new Debugger; |
|
6 |
|
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 } |
|
16 |
|
17 g.eval("" + function f(d) { |
|
18 return g(d); |
|
19 }); |
|
20 |
|
21 g.eval("" + function g(d) { |
|
22 debugger; |
|
23 return d; |
|
24 }); |
|
25 |
|
26 function testResumptionValues(handlerSetter) { |
|
27 // Test normal return. |
|
28 reset(); |
|
29 handlerSetter(undefined); |
|
30 assertEq(g.eval("(" + function test() { return f(42); } + ")();"), 42); |
|
31 |
|
32 // Test forced return. |
|
33 reset(); |
|
34 handlerSetter({ return: "not 42" }); |
|
35 assertEq(g.eval("(" + function test() { return f(42); } + ")();"), "not 42"); |
|
36 |
|
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 } |
|
46 |
|
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 }); |
|
58 |
|
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 }); |
|
72 |
|
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 }); |
|
80 |
|
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 }); |