michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Check that we source map frame locations returned by "frames" requests. michael@0: */ michael@0: michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; michael@0: michael@0: Components.utils.import('resource:///modules/devtools/SourceMap.jsm'); michael@0: michael@0: function run_test() { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = addTestGlobal("test-source-map"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function() { michael@0: attachTestTabAndResume(gClient, "test-source-map", function(aResponse, aTabClient, aThreadClient) { michael@0: gThreadClient = aThreadClient; michael@0: promise.resolve(define_code()) michael@0: .then(run_code) michael@0: .then(test_frames) michael@0: .then(null, error => { michael@0: dump(error + "\n"); michael@0: dump(error.stack); michael@0: do_check_true(false); michael@0: }) michael@0: .then(() => { michael@0: finishClient(gClient); michael@0: }); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function define_code() { michael@0: let { code, map } = (new SourceNode(null, null, null, [ michael@0: new SourceNode(1, 0, "a.js", "function a() {\n"), michael@0: new SourceNode(2, 0, "a.js", " b();\n"), michael@0: new SourceNode(3, 0, "a.js", "}\n"), michael@0: new SourceNode(1, 0, "b.js", "function b() {\n"), michael@0: new SourceNode(2, 0, "b.js", " c();\n"), michael@0: new SourceNode(3, 0, "b.js", "}\n"), michael@0: new SourceNode(1, 0, "c.js", "function c() {\n"), michael@0: new SourceNode(2, 0, "c.js", " debugger;\n"), michael@0: new SourceNode(3, 0, "c.js", "}\n"), michael@0: ])).toStringWithSourceMap({ michael@0: file: "abc.js", michael@0: sourceRoot: "http://example.com/www/js/" michael@0: }); michael@0: michael@0: code += "//# sourceMappingURL=data:text/json," + map.toString(); michael@0: michael@0: Components.utils.evalInSandbox(code, gDebuggee, "1.8", michael@0: "http://example.com/www/js/abc.js", 1); michael@0: } michael@0: michael@0: function run_code() { michael@0: const d = promise.defer(); michael@0: gClient.addOneTimeListener("paused", function () { michael@0: gThreadClient.getFrames(0, 3, function (aResponse) { michael@0: d.resolve(aResponse); michael@0: gThreadClient.resume(); michael@0: }) michael@0: }); michael@0: gDebuggee.a(); michael@0: return d.promise; michael@0: } michael@0: michael@0: function test_frames({ error, frames }) { michael@0: do_check_true(!error); michael@0: do_check_eq(frames.length, 3); michael@0: check_frame(frames[0], "http://example.com/www/js/c.js"); michael@0: check_frame(frames[1], "http://example.com/www/js/b.js"); michael@0: check_frame(frames[2], "http://example.com/www/js/a.js"); michael@0: } michael@0: michael@0: function check_frame({ where: { url, line, column } }, aExpectedUrl) { michael@0: do_check_eq(url, aExpectedUrl); michael@0: do_check_eq(line, 2); michael@0: do_check_eq(column, 0); michael@0: }