OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 // Flags: --expose-gc |
| 5 |
| 6 print("Test for Debugger.getPossibleBreakpoints"); |
| 7 |
| 8 Protocol.Runtime.enable(); |
| 9 Protocol.Debugger.enable(); |
| 10 |
| 11 InspectorTest.runTestSuite([ |
| 12 function getPossibleBreakpointsInRange(next) { |
| 13 var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n"; |
| 14 var scriptId; |
| 15 compileScript(source) |
| 16 .then(id => scriptId = id) |
| 17 .then(() => InspectorTest.log("Test start.scriptId != end.scriptId.")) |
| 18 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
0, scriptId: scriptId + "0" }})) |
| 19 .then(InspectorTest.logMessage) |
| 20 .then(() => InspectorTest.log("Test not existing scriptId.")) |
| 21 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: "-1" }})) |
| 22 .then(InspectorTest.logMessage) |
| 23 .then(() => InspectorTest.log("Test end < start.")) |
| 24 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
0, scriptId: scriptId }})) |
| 25 .then(InspectorTest.logMessage) |
| 26 .then(() => InspectorTest.log("Test empty range in first line.")) |
| 27 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
16, scriptId: scriptId }})) |
| 28 .then(InspectorTest.logMessage) |
| 29 .then(() => InspectorTest.log("Test one character range in first line.")) |
| 30 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
17, scriptId: scriptId }})) |
| 31 .then(InspectorTest.logMessage) |
| 32 .then(() => InspectorTest.log("Test empty range in not first line.")) |
| 33 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
16, scriptId: scriptId }})) |
| 34 .then(InspectorTest.logMessage) |
| 35 .then(() => InspectorTest.log("Test one character range in not first line.
")) |
| 36 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
17, scriptId: scriptId }})) |
| 37 .then(InspectorTest.logMessage) |
| 38 .then(() => InspectorTest.log("Test end is undefined")) |
| 39 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 40 .then(InspectorTest.logMessage) |
| 41 .then(() => InspectorTest.log("Test end.lineNumber > scripts.lineCount()")
) |
| 42 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber:
0, scriptId: scriptId }})) |
| 43 .then(InspectorTest.logMessage) |
| 44 .then(() => InspectorTest.log("Test one string")) |
| 45 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
0, scriptId: scriptId }})) |
| 46 .then(InspectorTest.logMessage) |
| 47 .then(() => InspectorTest.log("Test end.columnNumber > end.line.length(),
should be the same as previous.")) |
| 48 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
256, scriptId: scriptId }})) |
| 49 .then(InspectorTest.logMessage) |
| 50 .then(next); |
| 51 }, |
| 52 |
| 53 function getPossibleBreakpointsInArrow(next) { |
| 54 var source = "function foo() { return Promise.resolve().then(() => 239).then
(() => 42).then(() => () => 42) }"; |
| 55 var scriptId; |
| 56 compileScript(source) |
| 57 .then(id => scriptId = id) |
| 58 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 59 .then(InspectorTest.logMessage) |
| 60 .then(next); |
| 61 }, |
| 62 |
| 63 function arrowFunctionFirstLine(next) { |
| 64 Protocol.Debugger.onPaused(message => { |
| 65 InspectorTest.log("paused in " + message.params.callFrames[0].functionName
); |
| 66 InspectorTest.logMessage(message.params.callFrames[0].location); |
| 67 Protocol.Debugger.resume(); |
| 68 }); |
| 69 |
| 70 var source = `function foo1() { Promise.resolve().then(() => 42) } |
| 71 function foo2() { Promise.resolve().then(() => 42) }`; |
| 72 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, { lin
eNumber: 1, columnNumber: 0 }) |
| 73 .then(InspectorTest.logMessage) |
| 74 .then(setAllBreakpoints) |
| 75 .then(() => Protocol.Runtime.evaluate({ expression: "foo1(); foo2()"})) |
| 76 .then(next); |
| 77 }, |
| 78 |
| 79 function arrowFunctionOnPause(next) { |
| 80 function dumpAndResume(message) { |
| 81 InspectorTest.log("paused in " + message.params.callFrames[0].functionName
); |
| 82 InspectorTest.logMessage(message.params.callFrames[0].location); |
| 83 Protocol.Debugger.resume(); |
| 84 } |
| 85 |
| 86 var source = `debugger; function foo3() { Promise.resolve().then(() => 42) } |
| 87 function foo4() { Promise.resolve().then(() => 42) };\nfoo3();\nfoo4();`; |
| 88 waitForPossibleBreakpointsOnPause(source, { lineNumber: 0, columnNumber: 0 }
, undefined, next) |
| 89 .then(InspectorTest.logMessage) |
| 90 .then(setAllBreakpoints) |
| 91 .then(() => Protocol.Debugger.onPaused(dumpAndResume)) |
| 92 .then(() => Protocol.Debugger.resume()); |
| 93 }, |
| 94 |
| 95 function getPossibleBreakpointsInRangeWithOffset(next) { |
| 96 var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n"; |
| 97 var scriptId; |
| 98 compileScript(source, { name: "with-offset.js", line_offset: 1, column_offse
t: 1 }) |
| 99 .then(id => scriptId = id) |
| 100 .then(() => InspectorTest.log("Test empty range in first line.")) |
| 101 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
17, scriptId: scriptId }})) |
| 102 .then(InspectorTest.logMessage) |
| 103 .then(() => InspectorTest.log("Test one character range in first line.")) |
| 104 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
18, scriptId: scriptId }})) |
| 105 .then(InspectorTest.logMessage) |
| 106 .then(() => InspectorTest.log("Test empty range in not first line.")) |
| 107 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
16, scriptId: scriptId }})) |
| 108 .then(InspectorTest.logMessage) |
| 109 .then(() => InspectorTest.log("Test one character range in not first line.
")) |
| 110 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
17, scriptId: scriptId }})) |
| 111 .then(InspectorTest.logMessage) |
| 112 .then(() => InspectorTest.log("Test end is undefined")) |
| 113 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 114 .then(InspectorTest.logMessage) |
| 115 .then(() => InspectorTest.log("Test end.lineNumber > scripts.lineCount()")
) |
| 116 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber:
0, scriptId: scriptId }})) |
| 117 .then(InspectorTest.logMessage) |
| 118 .then(() => InspectorTest.log("Test one string")) |
| 119 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
0, scriptId: scriptId }})) |
| 120 .then(InspectorTest.logMessage) |
| 121 .then(() => InspectorTest.log("Test end.columnNumber > end.line.length(),
should be the same as previous.")) |
| 122 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
256, scriptId: scriptId }})) |
| 123 .then(InspectorTest.logMessage) |
| 124 .then(next); |
| 125 }, |
| 126 |
| 127 function withOffset(next) { |
| 128 Protocol.Debugger.onPaused(message => { |
| 129 InspectorTest.log("paused in " + message.params.callFrames[0].functionName
); |
| 130 InspectorTest.logMessage(message.params.callFrames[0].location); |
| 131 Protocol.Debugger.resume(); |
| 132 }); |
| 133 |
| 134 var source = `function foo5() { Promise.resolve().then(() => 42) } |
| 135 function foo6() { Promise.resolve().then(() => 42) }`; |
| 136 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, undef
ined, { name: "with-offset.js", line_offset: 3, column_offset: 18 }) |
| 137 .then(InspectorTest.logMessage) |
| 138 .then(setAllBreakpoints) |
| 139 .then(() => Protocol.Runtime.evaluate({ expression: "foo5(); foo6()"})) |
| 140 .then(next); |
| 141 } |
| 142 |
| 143 ]); |
| 144 |
| 145 function compileScript(source, origin) { |
| 146 var promise = Protocol.Debugger.onceScriptParsed().then(message => message.par
ams.scriptId); |
| 147 if (!origin) origin = { name: "", line_offset: 0, column_offset: 0 }; |
| 148 compileAndRunWithOrigin(source, origin.name, origin.line_offset, origin.column
_offset); |
| 149 return promise; |
| 150 } |
| 151 |
| 152 function waitForPossibleBreakpoints(source, start, end, origin) { |
| 153 return compileScript(source, origin) |
| 154 .then(scriptId => { (start || {}).scriptId = scriptId; (end || {}).scriptId
= scriptId }) |
| 155 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); |
| 156 } |
| 157 |
| 158 function waitForPossibleBreakpointsOnPause(source, start, end, next) { |
| 159 var promise = Protocol.Debugger.oncePaused() |
| 160 .then(msg => { (start || {}).scriptId = msg.params.callFrames[0].location.sc
riptId; (end || {}).scriptId = msg.params.callFrames[0].location.scriptId }) |
| 161 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); |
| 162 Protocol.Runtime.evaluate({ expression: source }).then(next); |
| 163 return promise; |
| 164 } |
| 165 |
| 166 function setAllBreakpoints(message) { |
| 167 var promises = []; |
| 168 for (var location of message.result.locations) |
| 169 promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(c
heckBreakpointAndDump)); |
| 170 return Promise.all(promises); |
| 171 } |
| 172 |
| 173 function checkBreakpointAndDump(message) { |
| 174 if (message.error) { |
| 175 InspectorTest.log("FAIL: error in setBreakpoint"); |
| 176 InspectorTest.logMessage(message); |
| 177 return; |
| 178 } |
| 179 var id_data = message.result.breakpointId.split(":"); |
| 180 if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parse
Int(id_data[2]) !== message.result.actualLocation.columnNumber) { |
| 181 InspectorTest.log("FAIL: possible breakpoint was resolved in another locatio
n"); |
| 182 InspectorTest.logMessage(message); |
| 183 } |
| 184 InspectorTest.logMessage(message); |
| 185 } |
OLD | NEW |