/js/src/jit-test/tests/debug/Script-01.js

http://github.com/zpao/v8monkey · JavaScript · 71 lines · 48 code · 10 blank · 13 comment · 4 complexity · 40487ff24e5d069c747e70d2ccab5ae2 MD5 · raw file

  1. // |jit-test| debug
  2. // We get the same Debugger.Script object instance each time we ask.
  3. var global = newGlobal('new-compartment');
  4. global.eval('function f() { debugger; }');
  5. global.eval('function g() { debugger; }');
  6. var debug = new Debugger(global);
  7. function evalAndNoteScripts(prog) {
  8. var scripts = {};
  9. debug.onDebuggerStatement = function(frame) {
  10. if (frame.type == "call")
  11. assertEq(frame.script, frame.callee.script);
  12. scripts.frame = frame.script;
  13. if (frame.arguments[0])
  14. scripts.argument = frame.arguments[0].script;
  15. };
  16. global.eval(prog);
  17. return scripts;
  18. }
  19. // If we create a frame for a function and pass it as a value, those should
  20. // both yield the same Debugger.Script instance.
  21. var scripts = evalAndNoteScripts('f(f)');
  22. assertEq(scripts.frame, scripts.argument);
  23. var fScript = scripts.argument;
  24. // If we call a second time, we should still get the same instance.
  25. scripts = evalAndNoteScripts('f(f)');
  26. assertEq(scripts.frame, fScript);
  27. assertEq(scripts.argument, fScript);
  28. // If we call with a different argument, we should get a different Debugger.Script.
  29. scripts = evalAndNoteScripts('f(g)');
  30. assertEq(scripts.frame !== scripts.argument, true);
  31. assertEq(scripts.frame, fScript);
  32. var gScript = scripts.argument;
  33. // See if we can get g via the frame.
  34. scripts = evalAndNoteScripts('g(f)');
  35. assertEq(scripts.frame !== scripts.argument, true);
  36. assertEq(scripts.frame, gScript);
  37. assertEq(scripts.argument, fScript);
  38. // Different closures made from the same 'function' expression should yield
  39. // the same script.
  40. global.eval('function gen1(x) { return function clo(y) { return x+y; }; }');
  41. global.eval('var clo1 = gen1(42);');
  42. global.eval('var clo2 = gen1("smoot");');
  43. var scripts1 = evalAndNoteScripts('f(clo1)');
  44. var scripts2 = evalAndNoteScripts('f(clo2)');
  45. assertEq(scripts1.argument, scripts2.argument);
  46. // Different closures made from the same 'function' declaration should yield
  47. // the same script.
  48. global.eval('function gen2(x) { function clo(y) { return x+y; }; return clo; }');
  49. global.eval('var clo1 = gen2(42);');
  50. global.eval('var clo2 = gen2("smoot");');
  51. var scripts1 = evalAndNoteScripts('f(clo1)');
  52. var scripts2 = evalAndNoteScripts('f(clo2)');
  53. assertEq(scripts1.argument, scripts2.argument);
  54. // Different closures made from the same 'function' statement should yield
  55. // the same script.
  56. global.eval('function gen3(x) { if (true) { function clo(y) { return x+y; }; return clo; } }');
  57. global.eval('var clo1 = gen3(42);');
  58. global.eval('var clo2 = gen3("smoot");');
  59. var scripts1 = evalAndNoteScripts('f(clo1)');
  60. var scripts2 = evalAndNoteScripts('f(clo2)');
  61. assertEq(scripts1.argument, scripts2.argument);