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 continue stepping when a single original source's line michael@0: * corresponds to multiple generated js lines. 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: define_code(); 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 runTest() {\n"), michael@0: // A bunch of js lines map to the same original source line. michael@0: new SourceNode(2, 0, "a.js", " debugger;\n"), michael@0: new SourceNode(2, 0, "a.js", " var sum = 0;\n"), michael@0: new SourceNode(2, 0, "a.js", " for (var i = 0; i < 5; i++) {\n"), michael@0: new SourceNode(2, 0, "a.js", " sum += i;\n"), michael@0: new SourceNode(2, 0, "a.js", " }\n"), michael@0: // And now we have a new line in the original source that we should stop at. michael@0: new SourceNode(3, 0, "a.js", " sum;\n"), michael@0: new SourceNode(3, 0, "a.js", "}\n"), michael@0: ])).toStringWithSourceMap({ michael@0: file: "abc.js", michael@0: sourceRoot: "http://example.com/" 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/abc.js", 1); michael@0: michael@0: run_code(); michael@0: } michael@0: michael@0: function run_code() { michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: do_check_eq(aPacket.why.type, "debuggerStatement"); michael@0: step_in(); michael@0: }); michael@0: gDebuggee.runTest(); michael@0: } michael@0: michael@0: function step_in() { michael@0: gClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: do_check_eq(aPacket.why.type, "resumeLimit"); michael@0: let { frame: { environment, where: { url, line } } } = aPacket; michael@0: // Stepping should have moved us to the next source mapped line. michael@0: do_check_eq(url, "http://example.com/a.js"); michael@0: do_check_eq(line, 3); michael@0: // Which should have skipped over the for loop in the generated js and sum michael@0: // should be calculated. michael@0: do_check_eq(environment.bindings.variables.sum.value, 10); michael@0: finishClient(gClient); michael@0: }); michael@0: gThreadClient.stepIn(); michael@0: } michael@0: