js/src/jit-test/tests/debug/onEnterFrame-04.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // We detect and stop the runaway recursion caused by making onEnterFrame a
michael@0 2 // wrapper of a debuggee function.
michael@0 3
michael@0 4 // This is all a bit silly. In any reasonable design, both debugger re-entry
michael@0 5 // (the second onEnterFrame invocation) and debuggee re-entry (the call to g.f
michael@0 6 // from within the debugger, not via a Debugger invocation function) would raise
michael@0 7 // errors immediately. We have plans to do so, but in the mean time, we settle
michael@0 8 // for at least detecting the recursion.
michael@0 9
michael@0 10 load(libdir + 'asserts.js');
michael@0 11
michael@0 12 var g = newGlobal();
michael@0 13 g.eval("function f(frame) { n++; return 42; }");
michael@0 14 g.n = 0;
michael@0 15
michael@0 16 var dbg = Debugger();
michael@0 17 var gw = dbg.addDebuggee(g);
michael@0 18
michael@0 19 // Register the debuggee function as the onEnterFrame handler. When we first
michael@0 20 // call or eval in the debuggee:
michael@0 21 //
michael@0 22 // - The onEnterFrame call reporting that frame's creation is itself an event
michael@0 23 // that must be reported, so we call onEnterFrame again.
michael@0 24 //
michael@0 25 // - SpiderMonkey detects the out-of-control recursion, and generates a "too
michael@0 26 // much recursion" InternalError in the youngest onEnterFrame call.
michael@0 27 //
michael@0 28 // - We don't catch it, so the onEnterFrame handler call itself throws.
michael@0 29 //
michael@0 30 // - Since the Debugger doesn't have an uncaughtExceptionHook (it can't; such a
michael@0 31 // hook would itself raise a "too much recursion" exception), Spidermonkey
michael@0 32 // reports the exception immediately and terminates the debuggee --- which is
michael@0 33 // the next-older onEnterFrame call.
michael@0 34 //
michael@0 35 // - This termination propagates all the way out to the initial attempt to
michael@0 36 // create a frame in the debuggee.
michael@0 37 dbg.onEnterFrame = g.f;
michael@0 38
michael@0 39 // Get a Debugger.Object instance referring to f.
michael@0 40 var debuggeeF = gw.makeDebuggeeValue(g.f);
michael@0 41
michael@0 42 // Using f.call allows us to catch the termination.
michael@0 43 assertEq(debuggeeF.call(), null);
michael@0 44
michael@0 45 // We should never actually begin execution of the function.
michael@0 46 assertEq(g.n, 0);
michael@0 47
michael@0 48 // When an error is reported, the shell usually exits with a nonzero exit code.
michael@0 49 // If we get here, the test passed, so override that behavior.
michael@0 50 quit(0);

mercurial