test_watchpoint-02.js (6757B)
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 Test that debugger advances instead of pausing twice on the 9 same line when encountering both a watchpoint and a breakpoint. 10 */ 11 12 add_task( 13 threadFrontTest(async args => { 14 await testBreakpointAndSetWatchpoint(args); 15 await testBreakpointAndGetWatchpoint(args); 16 await testLoops(args); 17 }) 18 ); 19 20 // Test that we advance to the next line when a location 21 // has both a breakpoint and set watchpoint. 22 async function testBreakpointAndSetWatchpoint({ 23 commands, 24 threadFront, 25 debuggee, 26 }) { 27 async function evaluateJS(input) { 28 const { result } = await commands.scriptCommand.execute(input, { 29 frameActor: packet.frame.actorID, 30 }); 31 return result; 32 } 33 34 function evaluateTestCode(debuggee) { 35 /* eslint-disable */ 36 Cu.evalInSandbox( 37 ` // 1 38 function stopMe(obj) { // 2 39 debugger; // 3 40 obj.a = 2; // 4 41 debugger; // 5 42 } // 43 stopMe({a: 1})`, 44 debuggee, 45 "1.8", 46 "test_watchpoint-02.js" 47 ); 48 /* eslint-disable */ 49 } 50 51 const packet = await executeOnNextTickAndWaitForPause( 52 () => evaluateTestCode(debuggee), 53 threadFront 54 ); 55 56 info("Test that we pause on the debugger statement."); 57 Assert.equal(packet.frame.where.line, 3); 58 Assert.equal(packet.why.type, "debuggerStatement"); 59 60 info("Add set watchpoint."); 61 const args = packet.frame.arguments; 62 const obj = args[0]; 63 const objClient = threadFront.pauseGrip(obj); 64 await objClient.addWatchpoint("a", "obj.a", "set"); 65 66 info("Add breakpoint."); 67 const source = await getSourceById(threadFront, packet.frame.where.actor); 68 69 const location = { 70 sourceUrl: source.url, 71 line: 4, 72 }; 73 74 threadFront.setBreakpoint(location, {}); 75 76 info("Test that pause occurs on breakpoint."); 77 const packet2 = await resumeAndWaitForPause(threadFront); 78 Assert.equal(packet2.frame.where.line, 4); 79 Assert.equal(packet2.why.type, "breakpoint"); 80 81 const packet3 = await resumeAndWaitForPause(threadFront); 82 83 info("Test that we pause on the second debugger statement."); 84 Assert.equal(packet3.frame.where.line, 5); 85 Assert.equal(packet3.why.type, "debuggerStatement"); 86 87 info("Test that the value has updated."); 88 const result = await evaluateJS("obj.a"); 89 Assert.equal(result, 2); 90 91 info("Remove breakpoint and finish."); 92 threadFront.removeBreakpoint(location, {}); 93 94 await resume(threadFront); 95 } 96 97 // Test that we advance to the next line when a location 98 // has both a breakpoint and get watchpoint. 99 async function testBreakpointAndGetWatchpoint({ threadFront, debuggee }) { 100 function evaluateTestCode(debuggee) { 101 /* eslint-disable */ 102 Cu.evalInSandbox( 103 ` // 1 104 function stopMe(obj) { // 2 105 debugger; // 3 106 obj.a + 4; // 4 107 debugger; // 5 108 } // 109 stopMe({a: 1})`, 110 debuggee, 111 "1.8", 112 "test_watchpoint-02.js" 113 ); 114 /* eslint-disable */ 115 } 116 117 const packet = await executeOnNextTickAndWaitForPause( 118 () => evaluateTestCode(debuggee), 119 threadFront 120 ); 121 122 info("Test that we pause on the debugger statement."); 123 Assert.equal(packet.frame.where.line, 3); 124 125 info("Add get watchpoint."); 126 const args = packet.frame.arguments; 127 const obj = args[0]; 128 const objClient = threadFront.pauseGrip(obj); 129 await objClient.addWatchpoint("a", "obj.a", "get"); 130 131 info("Add breakpoint."); 132 const source = await getSourceById(threadFront, packet.frame.where.actor); 133 134 const location = { 135 sourceUrl: source.url, 136 line: 4, 137 }; 138 139 threadFront.setBreakpoint(location, {}); 140 141 info("Test that pause occurs on breakpoint."); 142 const packet2 = await resumeAndWaitForPause(threadFront); 143 Assert.equal(packet2.frame.where.line, 4); 144 Assert.equal(packet2.why.type, "breakpoint"); 145 146 const packet3 = await resumeAndWaitForPause(threadFront); 147 148 info("Test that we pause on the second debugger statement."); 149 Assert.equal(packet3.frame.where.line, 5); 150 Assert.equal(packet3.why.type, "debuggerStatement"); 151 152 info("Remove breakpoint and finish."); 153 threadFront.removeBreakpoint(location, {}); 154 155 await resume(threadFront); 156 } 157 158 // Test that we can pause multiple times 159 // on the same line for a watchpoint. 160 async function testLoops({ commands, threadFront, debuggee }) { 161 async function evaluateJS(input) { 162 const { result } = await commands.scriptCommand.execute(input, { 163 frameActor: packet.frame.actorID, 164 }); 165 return result; 166 } 167 168 function evaluateTestCode(debuggee) { 169 /* eslint-disable */ 170 Cu.evalInSandbox( 171 ` // 1 172 function stopMe(obj) { // 2 173 let i = 0; // 3 174 debugger; // 4 175 while (i++ < 2) { // 5 176 obj.a = 2; // 6 177 } // 7 178 debugger; // 8 179 } // 180 stopMe({a: 1})`, 181 debuggee, 182 "1.8", 183 "test_watchpoint-02.js" 184 ); 185 /* eslint-disable */ 186 } 187 188 const packet = await executeOnNextTickAndWaitForPause( 189 () => evaluateTestCode(debuggee), 190 threadFront 191 ); 192 193 info("Test that we pause on the debugger statement."); 194 Assert.equal(packet.frame.where.line, 4); 195 Assert.equal(packet.why.type, "debuggerStatement"); 196 197 info("Add set watchpoint."); 198 const args = packet.frame.arguments; 199 const obj = args[0]; 200 const objClient = threadFront.pauseGrip(obj); 201 await objClient.addWatchpoint("a", "obj.a", "set"); 202 203 info("Test that watchpoint triggers pause on set."); 204 const packet2 = await resumeAndWaitForPause(threadFront); 205 Assert.equal(packet2.frame.where.line, 6); 206 Assert.equal(packet2.why.type, "setWatchpoint"); 207 let result = await evaluateJS("obj.a"); 208 Assert.equal(result, 1); 209 210 info("Test that watchpoint triggers pause on set (2nd time)."); 211 const packet3 = await resumeAndWaitForPause(threadFront); 212 Assert.equal(packet3.frame.where.line, 6); 213 Assert.equal(packet3.why.type, "setWatchpoint"); 214 let result2 = await evaluateJS("obj.a"); 215 Assert.equal(result2, 2); 216 217 info("Test that we pause on second debugger statement."); 218 const packet4 = await resumeAndWaitForPause(threadFront); 219 Assert.equal(packet4.frame.where.line, 8); 220 Assert.equal(packet4.why.type, "debuggerStatement"); 221 222 await resume(threadFront); 223 }