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: * Make sure that setting a breakpoint twice in a line without bytecodes works michael@0: * as expected. michael@0: */ michael@0: michael@0: const NUM_BREAKPOINTS = 10; michael@0: var gDebuggee; michael@0: var gClient; michael@0: var gThreadClient; michael@0: var gPath = getFilePath('test_breakpoint-12.js'); michael@0: var gBpActor; michael@0: var gCount = 1; michael@0: michael@0: function run_test() michael@0: { michael@0: initTestDebuggerServer(); michael@0: gDebuggee = addTestGlobal("test-stack"); michael@0: gClient = new DebuggerClient(DebuggerServer.connectPipe()); michael@0: gClient.connect(function () { michael@0: attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) { michael@0: gThreadClient = aThreadClient; michael@0: test_child_skip_breakpoint(); michael@0: }); michael@0: }); michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function test_child_skip_breakpoint() michael@0: { michael@0: gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: let location = { url: gPath, line: gDebuggee.line0 + 3}; michael@0: gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { michael@0: // Check that the breakpoint has properly skipped forward one line. michael@0: do_check_eq(aResponse.actualLocation.url, location.url); michael@0: do_check_eq(aResponse.actualLocation.line, location.line + 1); michael@0: gBpActor = aResponse.actor; michael@0: michael@0: // Set more breakpoints at the same location. michael@0: set_breakpoints(location); michael@0: }); michael@0: michael@0: }); michael@0: michael@0: gDebuggee.eval("var line0 = Error().lineNumber;\n" + michael@0: "function foo() {\n" + // line0 + 1 michael@0: " this.a = 1;\n" + // line0 + 2 michael@0: " // A comment.\n" + // line0 + 3 michael@0: " this.b = 2;\n" + // line0 + 4 michael@0: "}\n" + // line0 + 5 michael@0: "debugger;\n" + // line0 + 6 michael@0: "foo();\n"); // line0 + 7 michael@0: } michael@0: michael@0: // Set many breakpoints at the same location. michael@0: function set_breakpoints(location) { michael@0: do_check_neq(gCount, NUM_BREAKPOINTS); michael@0: gThreadClient.setBreakpoint(location, function (aResponse, bpClient) { michael@0: // Check that the breakpoint has properly skipped forward one line. michael@0: do_check_eq(aResponse.actualLocation.url, location.url); michael@0: do_check_eq(aResponse.actualLocation.line, location.line + 1); michael@0: // Check that the same breakpoint actor was returned. michael@0: do_check_eq(aResponse.actor, gBpActor); michael@0: michael@0: if (++gCount < NUM_BREAKPOINTS) { michael@0: set_breakpoints(location); michael@0: return; michael@0: } michael@0: michael@0: // After setting all the breakpoints, check that only one has effectively michael@0: // remained. michael@0: gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: // Check the return value. michael@0: do_check_eq(aPacket.type, "paused"); michael@0: do_check_eq(aPacket.frame.where.url, gPath); michael@0: do_check_eq(aPacket.frame.where.line, location.line + 1); michael@0: do_check_eq(aPacket.why.type, "breakpoint"); michael@0: do_check_eq(aPacket.why.actors[0], bpClient.actor); michael@0: // Check that the breakpoint worked. michael@0: do_check_eq(gDebuggee.a, 1); michael@0: do_check_eq(gDebuggee.b, undefined); michael@0: michael@0: gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) { michael@0: // We don't expect any more pauses after the breakpoint was hit once. michael@0: do_check_true(false); michael@0: }); michael@0: gThreadClient.resume(function () { michael@0: // Give any remaining breakpoints a chance to trigger. michael@0: do_timeout(1000, finishClient.bind(null, gClient)); michael@0: }); michael@0: michael@0: }); michael@0: // Continue until the breakpoint is hit. michael@0: gThreadClient.resume(); michael@0: }); michael@0: michael@0: }