test_breakpoint-14.js (3214B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint-disable no-shadow */ 4 5 "use strict"; 6 7 /** 8 * Check that a breakpoint or a debugger statement cause execution to pause even 9 * in a stepped-over function. 10 */ 11 12 add_task( 13 threadFrontTest(async ({ threadFront, debuggee }) => { 14 const packet = await executeOnNextTickAndWaitForPause( 15 () => evaluateTestCode(debuggee), 16 threadFront 17 ); 18 const source = await getSourceById(threadFront, packet.frame.where.actor); 19 const location = { 20 sourceUrl: source.url, 21 line: debuggee.line0 + 2, 22 }; 23 24 //Pause at debugger statement. 25 Assert.equal(packet.frame.where.line, debuggee.line0 + 4); 26 Assert.equal(packet.why.type, "debuggerStatement"); 27 28 threadFront.setBreakpoint(location, {}); 29 30 const testCallbacks = [ 31 function (packet) { 32 // Check that the stepping worked. 33 Assert.equal(packet.frame.where.line, debuggee.line0 + 5); 34 Assert.equal(packet.why.type, "resumeLimit"); 35 }, 36 function (packet) { 37 // Reached the breakpoint. 38 Assert.equal(packet.frame.where.line, location.line); 39 Assert.equal(packet.why.type, "breakpoint"); 40 Assert.notEqual(packet.why.type, "resumeLimit"); 41 }, 42 function (packet) { 43 // The frame is about to be popped while stepping. 44 Assert.equal(packet.frame.where.line, debuggee.line0 + 3); 45 Assert.notEqual(packet.why.type, "breakpoint"); 46 Assert.equal(packet.why.type, "resumeLimit"); 47 Assert.equal(packet.why.frameFinished.return.type, "undefined"); 48 }, 49 function (packet) { 50 // Check that the debugger statement wasn't the reason for this pause. 51 Assert.equal(debuggee.a, 1); 52 Assert.equal(debuggee.b, undefined); 53 Assert.equal(packet.frame.where.line, debuggee.line0 + 6); 54 Assert.notEqual(packet.why.type, "debuggerStatement"); 55 Assert.equal(packet.why.type, "resumeLimit"); 56 }, 57 function (packet) { 58 // Check that the debugger statement wasn't the reason for this pause. 59 Assert.equal(packet.frame.where.line, debuggee.line0 + 7); 60 Assert.notEqual(packet.why.type, "debuggerStatement"); 61 Assert.equal(packet.why.type, "resumeLimit"); 62 }, 63 ]; 64 65 for (const callback of testCallbacks) { 66 const waiter = waitForPause(threadFront); 67 threadFront.stepOver(); 68 const packet = await waiter; 69 callback(packet); 70 } 71 72 // Remove the breakpoint and finish. 73 threadFront.removeBreakpoint(location); 74 75 await threadFront.resume(); 76 }) 77 ); 78 79 function evaluateTestCode(debuggee) { 80 // prettier-ignore 81 Cu.evalInSandbox("var line0 = Error().lineNumber;\n" + 82 "function foo() {\n" + // line0 + 1 83 " this.a = 1;\n" + // line0 + 2 <-- Breakpoint is set here. 84 "}\n" + // line0 + 3 85 "debugger;\n" + // line0 + 4 86 "foo();\n" + // line0 + 5 87 "debugger;\n" + // line0 + 6 88 "var b = 2;\n", // line0 + 7 89 debuggee); 90 }