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 var source = ` |
| 6 console.log(239); |
| 7 function test() { |
| 8 return 42; |
| 9 }`; |
| 10 |
| 11 var longPrefix = new Array(512).join(';'); |
| 12 var sourceWithLongLines = ` |
| 13 function test() { |
| 14 ${longPrefix}console.log(1); |
| 15 ${longPrefix}console.log(2); |
| 16 return 42; |
| 17 }`; |
| 18 |
| 19 var sourceWithLongLinesEdited = ` |
| 20 function test() { |
| 21 ${longPrefix}console.log(3); |
| 22 ${longPrefix}console.log(1); |
| 23 ${longPrefix}console.log(2); |
| 24 return 42; |
| 25 }`; |
| 26 |
| 27 InspectorTest.setupScriptMap(); |
| 28 Protocol.Debugger.enable(); |
| 29 |
| 30 InspectorTest.runTestSuite([ |
| 31 function trivial(next) { |
| 32 runTest({ |
| 33 lineNumber: 8, |
| 34 url: 'test1.js', |
| 35 sourceBefore: source, |
| 36 sourceAfter: generateNewLines(9) + source, |
| 37 lineOffset: 5, |
| 38 columnOffset: 4 }).then(next); |
| 39 }, |
| 40 |
| 41 function dontCheckMoreThenNLines(next) { |
| 42 runTest({ |
| 43 lineNumber: 8, |
| 44 url: 'test2.js', |
| 45 sourceBefore: source, |
| 46 sourceAfter: generateNewLines(17) + source, |
| 47 lineOffset: 5, |
| 48 columnOffset: 4 }).then(next); |
| 49 }, |
| 50 |
| 51 function dontStoreLongStrings(next) { |
| 52 runTest({ |
| 53 lineNumber: 14, |
| 54 url: 'test3.js', |
| 55 sourceBefore: sourceWithLongLines, |
| 56 sourceAfter: sourceWithLongLinesEdited, |
| 57 lineOffset: 12, |
| 58 columnOffset: 0 }).then(next); |
| 59 } |
| 60 ]); |
| 61 |
| 62 function runTest(test) { |
| 63 let isBefore = true; |
| 64 Protocol.Debugger.onPaused(message => { |
| 65 InspectorTest.logCallFrames([ message.params.callFrames[0] ]); |
| 66 var source = isBefore ? test.sourceBefore : test.sourceAfter; |
| 67 source += '\n//# sourceURL=' + test.url; |
| 68 isBefore = false; |
| 69 var lineNumber = message.params.callFrames[0].location.lineNumber - test.lin
eOffset; |
| 70 var lineText = source.split('\n')[lineNumber]; |
| 71 InspectorTest.log('break at\'' + lineText.substr(Math.max(lineText.length -
32, 0)) + '\''); |
| 72 Protocol.Debugger.resume(); |
| 73 }); |
| 74 Protocol.Debugger.onBreakpointResolved(InspectorTest.logMessage); |
| 75 |
| 76 let breakpointId; |
| 77 InspectorTest.addScript(test.sourceBefore + '\n//# sourceURL=' + test.url, tes
t.lineOffset, test.columnOffset); |
| 78 return InspectorTest.waitPendingTasks() |
| 79 .then(() => Protocol.Debugger.setBreakpointByUrl({ lineNumber: test.lineNumb
er, url: test.url })) |
| 80 .then(InspectorTest.logMessage) |
| 81 .then(message => breakpointId = message.result.breakpointId) |
| 82 .then(() => Protocol.Runtime.evaluate({ expression: 'test()' })) |
| 83 .then(() => InspectorTest.addScript(test.sourceAfter + '\n//# sourceURL=' +
test.url, test.lineOffset, test.columnOffset )) |
| 84 .then(() => InspectorTest.waitPendingTasks()) |
| 85 .then(() => Protocol.Runtime.evaluate({ expression: 'test()' })) |
| 86 .then(() => Protocol.Debugger.removeBreakpoint({ breakpointId: breakpointId
})) |
| 87 } |
| 88 |
| 89 function generateNewLines(n) { |
| 90 return new Array(n + 1).join('\n'); |
| 91 } |
OLD | NEW |