/js/src/jit-test/tests/debug/Frame-onStep-04.js

http://github.com/zpao/v8monkey · JavaScript · 34 lines · 24 code · 4 blank · 6 comment · 1 complexity · ea7b136642d1dc3017171a5fefbf9b18 MD5 · raw file

  1. // When a recursive function has many frames on the stack, onStep may be set or
  2. // not independently on each frame.
  3. var g = newGlobal('new-compartment');
  4. g.eval("function f(x) {\n" +
  5. " if (x > 0)\n" +
  6. " f(x - 1);\n" +
  7. " else\n" +
  8. " debugger;\n" +
  9. " return x;\n" +
  10. "}");
  11. var dbg = Debugger(g);
  12. var seen = [0, 0, 0, 0, 0, 0, 0, 0];
  13. function step() {
  14. seen[this.arguments[0]] = 1;
  15. }
  16. dbg.onEnterFrame = function (frame) {
  17. // Turn on stepping for even-numbered frames.
  18. var x = frame.arguments[0];
  19. if (x % 2 === 0)
  20. frame.onStep = step;
  21. };
  22. dbg.onDebuggerStatement = function (frame) {
  23. // This is called with 8 call frames on the stack, 7 down to 0.
  24. // At this point we should have seen all the even-numbered frames.
  25. assertEq(seen.join(""), "10101010");
  26. // Now reset seen to see which frames fire onStep on the way out.
  27. seen = [0, 0, 0, 0, 0, 0, 0, 0];
  28. };
  29. g.f(7);
  30. assertEq(seen.join(""), "10101010");