test_breakpoint-09.js (2248B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint-disable no-shadow, max-nested-callbacks */ 4 5 "use strict"; 6 7 /** 8 * Check that removing a breakpoint works. 9 */ 10 11 let done = false; 12 13 add_task( 14 threadFrontTest(async ({ threadFront, client, debuggee }) => { 15 const packet = await executeOnNextTickAndWaitForPause( 16 () => evaluateTestCode(debuggee), 17 threadFront 18 ); 19 20 const source = await getSourceById(threadFront, packet.frame.where.actor); 21 const location = { sourceUrl: source.url, line: debuggee.line0 + 2 }; 22 23 //Pause at debugger statement. 24 Assert.equal(packet.frame.where.line, debuggee.line0 + 7); 25 Assert.equal(packet.why.type, "debuggerStatement"); 26 27 threadFront.setBreakpoint(location, {}); 28 await client.waitForRequestsToSettle(); 29 30 await resume(threadFront); 31 32 const packet2 = await waitForPause(threadFront); 33 34 // Check the return value. 35 Assert.equal(packet2.frame.where.actor, source.actorID); 36 Assert.equal(packet2.frame.where.line, location.line); 37 Assert.equal(packet2.why.type, "breakpoint"); 38 // Check that the breakpoint worked. 39 Assert.equal(debuggee.a, undefined); 40 41 // Remove the breakpoint. 42 threadFront.removeBreakpoint(location); 43 await client.waitForRequestsToSettle(); 44 45 done = true; 46 threadFront.once("paused", function () { 47 // The breakpoint should not be hit again. 48 threadFront.resume().then(function () { 49 Assert.ok(false); 50 }); 51 }); 52 53 await resume(threadFront); 54 }) 55 ); 56 57 function evaluateTestCode(debuggee) { 58 // prettier-ignore 59 Cu.evalInSandbox("var line0 = Error().lineNumber;\n" + 60 "function foo(stop) {\n" + // line0 + 1 61 " this.a = 1;\n" + // line0 + 2 62 " if (stop) return;\n" + // line0 + 3 63 " delete this.a;\n" + // line0 + 4 64 " foo(true);\n" + // line0 + 5 65 "}\n" + // line0 + 6 66 "debugger;\n" + // line0 + 7 67 "foo();\n", // line0 + 8 68 debuggee); 69 if (!done) { 70 Assert.ok(false); 71 } 72 }