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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/onEnterFrame-04.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +// We detect and stop the runaway recursion caused by making onEnterFrame a
     1.5 +// wrapper of a debuggee function.
     1.6 +
     1.7 +// This is all a bit silly. In any reasonable design, both debugger re-entry
     1.8 +// (the second onEnterFrame invocation) and debuggee re-entry (the call to g.f
     1.9 +// from within the debugger, not via a Debugger invocation function) would raise
    1.10 +// errors immediately. We have plans to do so, but in the mean time, we settle
    1.11 +// for at least detecting the recursion.
    1.12 +
    1.13 +load(libdir + 'asserts.js');
    1.14 +
    1.15 +var g = newGlobal();
    1.16 +g.eval("function f(frame) { n++; return 42; }");
    1.17 +g.n = 0;
    1.18 +
    1.19 +var dbg = Debugger();
    1.20 +var gw = dbg.addDebuggee(g);
    1.21 +
    1.22 +// Register the debuggee function as the onEnterFrame handler. When we first
    1.23 +// call or eval in the debuggee:
    1.24 +//
    1.25 +// - The onEnterFrame call reporting that frame's creation is itself an event
    1.26 +//   that must be reported, so we call onEnterFrame again.
    1.27 +//
    1.28 +// - SpiderMonkey detects the out-of-control recursion, and generates a "too
    1.29 +//   much recursion" InternalError in the youngest onEnterFrame call.
    1.30 +//
    1.31 +// - We don't catch it, so the onEnterFrame handler call itself throws.
    1.32 +//
    1.33 +// - Since the Debugger doesn't have an uncaughtExceptionHook (it can't; such a
    1.34 +//   hook would itself raise a "too much recursion" exception), Spidermonkey
    1.35 +//   reports the exception immediately and terminates the debuggee --- which is
    1.36 +//   the next-older onEnterFrame call.
    1.37 +//
    1.38 +// - This termination propagates all the way out to the initial attempt to
    1.39 +//   create a frame in the debuggee.
    1.40 +dbg.onEnterFrame = g.f;
    1.41 +
    1.42 +// Get a Debugger.Object instance referring to f.
    1.43 +var debuggeeF = gw.makeDebuggeeValue(g.f);
    1.44 +
    1.45 +// Using f.call allows us to catch the termination.
    1.46 +assertEq(debuggeeF.call(), null);
    1.47 +
    1.48 +// We should never actually begin execution of the function.
    1.49 +assertEq(g.n, 0);
    1.50 +
    1.51 +// When an error is reported, the shell usually exits with a nonzero exit code.
    1.52 +// If we get here, the test passed, so override that behavior.
    1.53 +quit(0);

mercurial