OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 let {session, contextGroup, Protocol} = |
| 6 InspectorTest.start('Tests breakable locations in for-of loops.'); |
| 7 |
| 8 let source = ` |
| 9 function testFunction() { |
| 10 var obj = {a : 1}; |
| 11 var arr = [1]; |
| 12 var all = []; |
| 13 for (var k in arr) { all.push(k); } |
| 14 for (var k of arr) { all.push(k); } |
| 15 for (var k in obj) { all.push(k); } |
| 16 for (let k in arr) { all.push(k); } |
| 17 for (let k of arr) { all.push(k); } |
| 18 for (let k in obj) { all.push(k); } |
| 19 |
| 20 var iterable = { |
| 21 [Symbol.iterator]() { |
| 22 return { |
| 23 i: 0, |
| 24 next() { |
| 25 if (this.i < 1) { |
| 26 return { value: this.i++, done: false }; |
| 27 } |
| 28 return { value: undefined, done: true }; |
| 29 } |
| 30 }; |
| 31 } |
| 32 }; |
| 33 for (var k of iterable) { all.push(k); } |
| 34 iterable.i = 0; |
| 35 for (let k of iterable) { all.push(k); } |
| 36 } |
| 37 //# sourceURL=test.js`; |
| 38 |
| 39 contextGroup.addScript(source); |
| 40 session.setupScriptMap(); |
| 41 |
| 42 InspectorTest.runAsyncTestSuite([ |
| 43 async function testBreakLocations() { |
| 44 Protocol.Debugger.enable(); |
| 45 let {params:{scriptId}} = await Protocol.Debugger.onceScriptParsed(); |
| 46 let {result:{locations}} = await Protocol.Debugger.getPossibleBreakpoints({ |
| 47 start: {lineNumber: 0, columnNumber : 0, scriptId}}); |
| 48 dumpAllLocations(locations); |
| 49 }, |
| 50 |
| 51 async function testStepInto() { |
| 52 Protocol.Debugger.pause(); |
| 53 let fin = Protocol.Runtime.evaluate({ |
| 54 expression: 'testFunction()//# sourceURL=expr.js'}).then(() => false); |
| 55 let result; |
| 56 while (result = await Promise.race([fin, Protocol.Debugger.oncePaused()])) { |
| 57 let {params:{callFrames}} = result; |
| 58 session.logCallFrames(callFrames); |
| 59 session.logSourceLocation(callFrames[0].location); |
| 60 Protocol.Debugger.stepInto(); |
| 61 } |
| 62 Protocol.Runtime.evaluate({expression: '42'}); |
| 63 await Protocol.Debugger.oncePaused(); |
| 64 await Protocol.Debugger.resume(); |
| 65 }, |
| 66 |
| 67 async function testStepIntoAfterBreakpoint() { |
| 68 Protocol.Debugger.setBreakpointByUrl({lineNumber: 25, url: 'test.js'}); |
| 69 Protocol.Runtime.evaluate({ |
| 70 expression: 'testFunction()//# sourceURL=expr.js'}); |
| 71 await awaitPausedAndDump(); |
| 72 Protocol.Debugger.stepInto(); |
| 73 await awaitPausedAndDump(); |
| 74 await Protocol.Debugger.resume(); |
| 75 |
| 76 async function awaitPausedAndDump() { |
| 77 let {params:{callFrames}} = await Protocol.Debugger.oncePaused(); |
| 78 session.logCallFrames(callFrames); |
| 79 session.logSourceLocation(callFrames[0].location); |
| 80 } |
| 81 } |
| 82 ]); |
| 83 |
| 84 function dumpAllLocations(locations) { |
| 85 var lines = source.split('\n'); |
| 86 var locations = locations.sort((loc1, loc2) => { |
| 87 if (loc2.lineNumber !== loc1.lineNumber) return loc2.lineNumber - loc1.lineN
umber; |
| 88 return loc2.columnNumber - loc1.columnNumber; |
| 89 }); |
| 90 for (var location of locations) { |
| 91 var line = lines[location.lineNumber]; |
| 92 line = line.slice(0, location.columnNumber) + locationMark(location.type) +
line.slice(location.columnNumber); |
| 93 lines[location.lineNumber] = line; |
| 94 } |
| 95 lines = lines.filter(line => line.indexOf('//# sourceURL=') === -1); |
| 96 InspectorTest.log(lines.join('\n') + '\n'); |
| 97 } |
| 98 |
| 99 function locationMark(type) { |
| 100 if (type === 'return') return '|R|'; |
| 101 if (type === 'call') return '|C|'; |
| 102 if (type === 'debuggerStatement') return '|D|'; |
| 103 return '|_|'; |
| 104 } |
OLD | NEW |