test_breakpoint-21.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Bug 1122064 - make sure that scripts introduced via onNewScripts
  5. * properly populate the `ScriptStore` with all there nested child
  6. * scripts, so you can set breakpoints on deeply nested scripts
  7. */
  8. var gDebuggee;
  9. var gClient;
  10. var gThreadClient;
  11. var gCallback;
  12. function run_test()
  13. {
  14. run_test_with_server(DebuggerServer, function () {
  15. run_test_with_server(WorkerDebuggerServer, do_test_finished);
  16. });
  17. do_test_pending();
  18. }
  19. function run_test_with_server(aServer, aCallback)
  20. {
  21. gCallback = aCallback;
  22. initTestDebuggerServer(aServer);
  23. gDebuggee = addTestGlobal("test-breakpoints", aServer);
  24. gClient = new DebuggerClient(aServer.connectPipe());
  25. gClient.connect().then(function () {
  26. attachTestTabAndResume(gClient,
  27. "test-breakpoints",
  28. function (aResponse, aTabClient, aThreadClient) {
  29. gThreadClient = aThreadClient;
  30. test();
  31. });
  32. });
  33. }
  34. const test = Task.async(function* () {
  35. // Populate the `ScriptStore` so that we only test that the script
  36. // is added through `onNewScript`
  37. yield getSources(gThreadClient);
  38. let packet = yield executeOnNextTickAndWaitForPause(evalCode, gClient);
  39. let source = gThreadClient.source(packet.frame.where.source);
  40. let location = {
  41. line: gDebuggee.line0 + 8
  42. };
  43. let [res, bpClient] = yield setBreakpoint(source, location);
  44. ok(!res.error);
  45. yield resume(gThreadClient);
  46. packet = yield waitForPause(gClient);
  47. do_check_eq(packet.type, "paused");
  48. do_check_eq(packet.why.type, "breakpoint");
  49. do_check_eq(packet.why.actors[0], bpClient.actor);
  50. do_check_eq(packet.frame.where.source.actor, source.actor);
  51. do_check_eq(packet.frame.where.line, location.line);
  52. yield resume(gThreadClient);
  53. finishClient(gClient);
  54. });
  55. function evalCode() {
  56. // Start a new script
  57. Components.utils.evalInSandbox(
  58. "var line0 = Error().lineNumber;\n(" + function () {
  59. debugger;
  60. var a = (function () {
  61. return (function () {
  62. return (function () {
  63. return (function () {
  64. return (function () {
  65. var x = 10; // This line gets a breakpoint
  66. return 1;
  67. })();
  68. })();
  69. })();
  70. })();
  71. })();
  72. } + ")()",
  73. gDebuggee
  74. );
  75. }