test_sourcemaps-11.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Check that we source map frame locations returned by "frames" requests.
  5. */
  6. var gDebuggee;
  7. var gClient;
  8. var gThreadClient;
  9. const {SourceNode} = require("source-map");
  10. function run_test() {
  11. initTestDebuggerServer();
  12. gDebuggee = addTestGlobal("test-source-map");
  13. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  14. gClient.connect().then(function () {
  15. attachTestTabAndResume(gClient, "test-source-map", function (aResponse, aTabClient, aThreadClient) {
  16. gThreadClient = aThreadClient;
  17. promise.resolve(define_code())
  18. .then(run_code)
  19. .then(test_frames)
  20. .then(null, error => {
  21. dump(error + "\n");
  22. dump(error.stack);
  23. do_check_true(false);
  24. })
  25. .then(() => {
  26. finishClient(gClient);
  27. });
  28. });
  29. });
  30. do_test_pending();
  31. }
  32. function define_code() {
  33. let { code, map } = (new SourceNode(null, null, null, [
  34. new SourceNode(1, 0, "a.js", "function a() {\n"),
  35. new SourceNode(2, 0, "a.js", " b();\n"),
  36. new SourceNode(3, 0, "a.js", "}\n"),
  37. new SourceNode(1, 0, "b.js", "function b() {\n"),
  38. new SourceNode(2, 0, "b.js", " c();\n"),
  39. new SourceNode(3, 0, "b.js", "}\n"),
  40. new SourceNode(1, 0, "c.js", "function c() {\n"),
  41. new SourceNode(2, 0, "c.js", " debugger;\n"),
  42. new SourceNode(3, 0, "c.js", "}\n"),
  43. ])).toStringWithSourceMap({
  44. file: "abc.js",
  45. sourceRoot: "http://example.com/www/js/"
  46. });
  47. code += "//# sourceMappingURL=data:text/json," + map.toString();
  48. Components.utils.evalInSandbox(code, gDebuggee, "1.8",
  49. "http://example.com/www/js/abc.js", 1);
  50. }
  51. function run_code() {
  52. const d = promise.defer();
  53. gClient.addOneTimeListener("paused", function () {
  54. gThreadClient.getFrames(0, 3, function (aResponse) {
  55. d.resolve(aResponse);
  56. gThreadClient.resume();
  57. });
  58. });
  59. gDebuggee.a();
  60. return d.promise;
  61. }
  62. function test_frames({ error, frames }) {
  63. do_check_true(!error);
  64. do_check_eq(frames.length, 3);
  65. check_frame(frames[0], "http://example.com/www/js/c.js");
  66. check_frame(frames[1], "http://example.com/www/js/b.js");
  67. check_frame(frames[2], "http://example.com/www/js/a.js");
  68. }
  69. function check_frame({ where: { source, line, column } }, aExpectedUrl) {
  70. do_check_eq(source.url, aExpectedUrl);
  71. do_check_eq(line, 2);
  72. do_check_eq(column, 0);
  73. }