test_watchpoint-01.js (5906B)
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 - Tests adding set and get watchpoints. 9 - Tests removing a watchpoint. 10 - Tests removing all watchpoints. 11 */ 12 13 add_task( 14 threadFrontTest( 15 async args => { 16 await testSetWatchpoint(args); 17 await testGetWatchpoint(args); 18 await testRemoveWatchpoint(args); 19 await testRemoveWatchpoints(args); 20 }, 21 // For some reason, using a content principal introduces Xraywrapper exception within WatchPoint codebase 22 { principal: systemPrincipal } 23 ) 24 ); 25 26 async function testSetWatchpoint({ commands, threadFront, debuggee }) { 27 async function evaluateJS(input) { 28 const { result } = await commands.scriptCommand.execute(input, { 29 thread: threadFront.actor, 30 frameActor: packet.frame.actorID, 31 }); 32 return result; 33 } 34 35 function evaluateTestCode(debuggee) { 36 /* eslint-disable */ 37 Cu.evalInSandbox( 38 ` // 1 39 function stopMe(obj) { // 2 40 debugger; // 3 41 obj.a = 2; // 4 42 } // 43 stopMe({a: { b: 1 }})`, 44 debuggee, 45 "1.8", 46 "test_watchpoint-01.js" 47 ); 48 /* eslint-disable */ 49 } 50 51 const packet = await executeOnNextTickAndWaitForPause( 52 () => evaluateTestCode(debuggee), 53 threadFront 54 ); 55 56 info("Test that we paused on the debugger statement"); 57 Assert.equal(packet.frame.where.line, 3); 58 59 info("Add set watchpoint"); 60 const args = packet.frame.arguments; 61 const obj = args[0]; 62 const objClient = threadFront.pauseGrip(obj); 63 await objClient.addWatchpoint("a", "obj.a", "set"); 64 65 let result = await evaluateJS("obj.a"); 66 Assert.equal(result.getGrip().preview.ownProperties.b.value, 1); 67 68 result = await evaluateJS("obj.a.b"); 69 Assert.equal(result, 1); 70 71 info("Test that watchpoint triggers pause on set"); 72 const packet2 = await resumeAndWaitForPause(threadFront); 73 Assert.equal(packet2.frame.where.line, 4); 74 Assert.equal(packet2.why.type, "setWatchpoint"); 75 Assert.equal(obj.preview.ownProperties.a.value.ownPropertyLength, 1); 76 77 await resume(threadFront); 78 } 79 80 async function testGetWatchpoint({ threadFront, debuggee }) { 81 function evaluateTestCode(debuggee) { 82 /* eslint-disable */ 83 Cu.evalInSandbox( 84 ` // 1 85 function stopMe(obj) { // 2 86 debugger; // 3 87 obj.a + 4; // 4 88 } // 89 stopMe({a: 1})`, 90 debuggee, 91 "1.8", 92 "test_watchpoint-01.js" 93 ); 94 /* eslint-disable */ 95 } 96 97 const packet = await executeOnNextTickAndWaitForPause( 98 () => evaluateTestCode(debuggee), 99 threadFront 100 ); 101 102 info("Test that we paused on the debugger statement"); 103 Assert.equal(packet.frame.where.line, 3); 104 105 info("Add get watchpoint."); 106 const args = packet.frame.arguments; 107 const obj = args[0]; 108 const objClient = threadFront.pauseGrip(obj); 109 await objClient.addWatchpoint("a", "obj.a", "get"); 110 111 info("Test that watchpoint triggers pause on get."); 112 const packet2 = await resumeAndWaitForPause(threadFront); 113 Assert.equal(packet2.frame.where.line, 4); 114 Assert.equal(packet2.why.type, "getWatchpoint"); 115 Assert.equal(obj.preview.ownProperties.a.value, 1); 116 117 await resume(threadFront); 118 } 119 120 async function testRemoveWatchpoint({ threadFront, debuggee }) { 121 function evaluateTestCode(debuggee) { 122 /* eslint-disable */ 123 Cu.evalInSandbox( 124 ` // 1 125 function stopMe(obj) { // 2 126 debugger; // 3 127 obj.a = 2; // 4 128 debugger; // 5 129 } // 130 131 stopMe({a: 1})`, 132 debuggee, 133 "1.8", 134 "test_watchpoint-01.js" 135 ); 136 /* eslint-disable */ 137 } 138 139 const packet = await executeOnNextTickAndWaitForPause( 140 () => evaluateTestCode(debuggee), 141 threadFront 142 ); 143 144 info(`Test that we paused on the debugger statement`); 145 Assert.equal(packet.frame.where.line, 3); 146 147 info(`Add set watchpoint`); 148 const args = packet.frame.arguments; 149 const obj = args[0]; 150 const objClient = threadFront.pauseGrip(obj); 151 await objClient.addWatchpoint("a", "obj.a", "set"); 152 153 info(`Remove set watchpoint`); 154 await objClient.removeWatchpoint("a"); 155 156 info(`Test that we do not pause on set`); 157 const packet2 = await resumeAndWaitForPause(threadFront); 158 Assert.equal(packet2.frame.where.line, 5); 159 160 await resume(threadFront); 161 } 162 163 async function testRemoveWatchpoints({ threadFront, debuggee }) { 164 function evaluateTestCode(debuggee) { 165 /* eslint-disable */ 166 Cu.evalInSandbox( 167 ` // 1 168 function stopMe(obj) { // 2 169 debugger; // 3 170 obj.a = 2; // 4 171 debugger; // 5 172 } // 173 stopMe({a: 1})`, 174 debuggee, 175 "1.8", 176 "test_watchpoint-01.js" 177 ); 178 /* eslint-disable */ 179 } 180 181 const packet = await executeOnNextTickAndWaitForPause( 182 () => evaluateTestCode(debuggee), 183 threadFront 184 ); 185 186 info("Test that we paused on the debugger statement"); 187 Assert.equal(packet.frame.where.line, 3); 188 189 info("Add and then remove set watchpoint"); 190 const args = packet.frame.arguments; 191 const obj = args[0]; 192 const objClient = threadFront.pauseGrip(obj); 193 await objClient.addWatchpoint("a", "obj.a", "set"); 194 await objClient.removeWatchpoints(); 195 196 info("Test that we do not pause on set"); 197 const packet2 = await resumeAndWaitForPause(threadFront); 198 Assert.equal(packet2.frame.where.line, 5); 199 200 await resume(threadFront); 201 }