michael@0: // Check whether we respect resumption values when toggling debug mode on->off michael@0: // from various points with live scripts on the stack. michael@0: michael@0: var g = newGlobal(); michael@0: var dbg = new Debugger; michael@0: michael@0: function reset() { michael@0: dbg.onEnterFrame = undefined; michael@0: dbg.onDebuggerStatement = undefined; michael@0: dbg.addDebuggee(g); michael@0: g.eval("(" + function test() { michael@0: for (i = 0; i < 5; i++) michael@0: f(42); michael@0: } + ")();"); michael@0: } michael@0: michael@0: g.eval("" + function f(d) { michael@0: return g(d); michael@0: }); michael@0: michael@0: g.eval("" + function g(d) { michael@0: debugger; michael@0: return d; michael@0: }); michael@0: michael@0: function testResumptionValues(handlerSetter) { michael@0: // Test normal return. michael@0: reset(); michael@0: handlerSetter(undefined); michael@0: assertEq(g.eval("(" + function test() { return f(42); } + ")();"), 42); michael@0: michael@0: // Test forced return. michael@0: reset(); michael@0: handlerSetter({ return: "not 42" }); michael@0: assertEq(g.eval("(" + function test() { return f(42); } + ")();"), "not 42"); michael@0: michael@0: // Test throw. michael@0: reset(); michael@0: handlerSetter({ throw: "thrown 42" }); michael@0: try { michael@0: g.eval("(" + function test() { return f(42); } + ")();");; michael@0: } catch (e) { michael@0: assertEq(e, "thrown 42"); michael@0: } michael@0: } michael@0: michael@0: // Turn off from within the prologue. michael@0: testResumptionValues(function (resumptionVal) { michael@0: dbg.onEnterFrame = function (frame) { michael@0: if (frame.older) { michael@0: if (frame.older.older) { michael@0: dbg.removeDebuggee(g); michael@0: return resumptionVal; michael@0: } michael@0: } michael@0: }; michael@0: }); michael@0: michael@0: // Turn off from within the epilogue. michael@0: testResumptionValues(function (resumptionVal) { michael@0: dbg.onEnterFrame = function (frame) { michael@0: if (frame.older) { michael@0: if (frame.older.older) { michael@0: frame.onPop = function () { michael@0: dbg.removeDebuggee(g); michael@0: return resumptionVal; michael@0: }; michael@0: } michael@0: } michael@0: }; michael@0: }); michael@0: michael@0: // Turn off from within debugger statement handler. michael@0: testResumptionValues(function (resumptionVal) { michael@0: dbg.onDebuggerStatement = function (frame) { michael@0: dbg.removeDebuggee(g); michael@0: return resumptionVal; michael@0: }; michael@0: }); michael@0: michael@0: // Turn off from within debug trap handler. michael@0: testResumptionValues(function (resumptionVal) { michael@0: dbg.onEnterFrame = function (frame) { michael@0: if (frame.older) { michael@0: if (frame.older.older) { michael@0: frame.onStep = function () { michael@0: dbg.removeDebuggee(g); michael@0: return resumptionVal; michael@0: } michael@0: } michael@0: } michael@0: }; michael@0: });