| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 print('Test for Debugger.getPossibleBreakpoints'); | 5 print("Test for Debugger.getPossibleBreakpoints"); |
| 6 | 6 |
| 7 Protocol.Runtime.enable(); | 7 Protocol.Runtime.enable(); |
| 8 Protocol.Debugger.enable(); | 8 Protocol.Debugger.enable(); |
| 9 | 9 |
| 10 InspectorTest.runTestSuite([ | 10 InspectorTest.runTestSuite([ |
| 11 | 11 |
| 12 function getPossibleBreakpointsInRange(next) { | 12 function getPossibleBreakpointsInRange(next) { |
| 13 var source = 'function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n'; | 13 var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n"; |
| 14 var scriptId; | 14 var scriptId; |
| 15 compileScript(source) | 15 compileScript(source) |
| 16 .then(id => scriptId = id) | 16 .then(id => scriptId = id) |
| 17 .then(() => InspectorTest.log('Test start.scriptId != end.scriptId.')) | 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' }})) | 18 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
0, scriptId: scriptId + "0" }})) |
| 19 .then(message => dumpAllLocations(message, source)) | 19 .then(InspectorTest.logMessage) |
| 20 .then(() => InspectorTest.log('Test not existing scriptId.')) | 20 .then(() => InspectorTest.log("Test not existing scriptId.")) |
| 21 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: '-1' }})) | 21 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: "-1" }})) |
| 22 .then(message => dumpAllLocations(message, source)) | 22 .then(InspectorTest.logMessage) |
| 23 .then(() => InspectorTest.log('Test end < start.')) | 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 }})) | 24 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
0, scriptId: scriptId }})) |
| 25 .then(message => dumpAllLocations(message, source)) | 25 .then(InspectorTest.logMessage) |
| 26 .then(() => InspectorTest.log('Test empty range in first line.')) | 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 }})) | 27 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
16, scriptId: scriptId }})) |
| 28 .then(message => dumpAllLocations(message, source)) | 28 .then(InspectorTest.logMessage) |
| 29 .then(() => InspectorTest.log('Test one character range in first line.')) | 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 }})) | 30 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
17, scriptId: scriptId }})) |
| 31 .then(message => dumpAllLocations(message, source)) | 31 .then(InspectorTest.logMessage) |
| 32 .then(() => InspectorTest.log('Test empty range in not first line.')) | 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 }})) | 33 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
16, scriptId: scriptId }})) |
| 34 .then(message => dumpAllLocations(message, source)) | 34 .then(InspectorTest.logMessage) |
| 35 .then(() => InspectorTest.log('Test one character range in not first line.
')) | 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 }})) | 36 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
17, scriptId: scriptId }})) |
| 37 .then(message => dumpAllLocations(message, source)) | 37 .then(InspectorTest.logMessage) |
| 38 .then(() => InspectorTest.log('Test end is undefined')) | 38 .then(() => InspectorTest.log("Test end is undefined")) |
| 39 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) | 39 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 40 .then(message => dumpAllLocations(message, source)) | 40 .then(InspectorTest.logMessage) |
| 41 .then(() => InspectorTest.log('Test end.lineNumber > scripts.lineCount()')
) | 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 }})) | 42 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber:
0, scriptId: scriptId }})) |
| 43 .then(message => dumpAllLocations(message, source)) | 43 .then(InspectorTest.logMessage) |
| 44 .then(() => InspectorTest.log('Test one string')) | 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 }})) | 45 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
0, scriptId: scriptId }})) |
| 46 .then(message => dumpAllLocations(message, source)) | 46 .then(InspectorTest.logMessage) |
| 47 .then(() => InspectorTest.log('Test end.columnNumber > end.line.length(),
should be the same as previous.')) | 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 }})) | 48 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber:
256, scriptId: scriptId }})) |
| 49 .then(message => dumpAllLocations(message, source)) | 49 .then(InspectorTest.logMessage) |
| 50 .then(next); | 50 .then(next); |
| 51 }, | 51 }, |
| 52 | 52 |
| 53 function getPossibleBreakpointsInArrow(next) { | 53 function getPossibleBreakpointsInArrow(next) { |
| 54 var source = 'function foo() { return Promise.resolve().then(() => 239).then
(() => 42).then(() => () => 42) }'; | 54 var source = "function foo() { return Promise.resolve().then(() => 239).then
(() => 42).then(() => () => 42) }"; |
| 55 var scriptId; | 55 var scriptId; |
| 56 compileScript(source) | 56 compileScript(source) |
| 57 .then(id => scriptId = id) | 57 .then(id => scriptId = id) |
| 58 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) | 58 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 59 .then(message => dumpAllLocations(message, source)) | 59 .then(InspectorTest.logMessage) |
| 60 .then(next); | 60 .then(next); |
| 61 }, | 61 }, |
| 62 | 62 |
| 63 function arrowFunctionFirstLine(next) { | 63 function arrowFunctionFirstLine(next) { |
| 64 Protocol.Debugger.onPaused(message => dumpBreakLocationInSourceAndResume(mes
sage, source)); | 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 }); |
| 65 | 69 |
| 66 var source = `function foo1() { Promise.resolve().then(() => 42) } | 70 var source = `function foo1() { Promise.resolve().then(() => 42) } |
| 67 function foo2() { Promise.resolve().then(() => 42) }`; | 71 function foo2() { Promise.resolve().then(() => 42) }`; |
| 68 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, { lin
eNumber: 1, columnNumber: 0 }) | 72 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, { lin
eNumber: 1, columnNumber: 0 }) |
| 69 .then(message => dumpAllLocations(message, source)) | 73 .then(InspectorTest.logMessage) |
| 70 .then(setAllBreakpoints) | 74 .then(setAllBreakpoints) |
| 71 .then(() => Protocol.Runtime.evaluate({ expression: 'foo1(); foo2()'})) | 75 .then(() => Protocol.Runtime.evaluate({ expression: "foo1(); foo2()"})) |
| 72 .then(next); | 76 .then(next); |
| 73 }, | 77 }, |
| 74 | 78 |
| 75 function arrowFunctionOnPause(next) { | 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 |
| 76 var source = `debugger; function foo3() { Promise.resolve().then(() => 42) } | 86 var source = `debugger; function foo3() { Promise.resolve().then(() => 42) } |
| 77 function foo4() { Promise.resolve().then(() => 42) };\nfoo3();\nfoo4();`; | 87 function foo4() { Promise.resolve().then(() => 42) };\nfoo3();\nfoo4();`; |
| 78 waitForPossibleBreakpointsOnPause(source, { lineNumber: 0, columnNumber: 0 }
, undefined, next) | 88 waitForPossibleBreakpointsOnPause(source, { lineNumber: 0, columnNumber: 0 }
, undefined, next) |
| 79 .then(message => dumpAllLocations(message, source)) | 89 .then(InspectorTest.logMessage) |
| 80 .then(setAllBreakpoints) | 90 .then(setAllBreakpoints) |
| 81 .then(() => Protocol.Debugger.onPaused(message => dumpBreakLocationInSourc
eAndResume(message, source))) | 91 .then(() => Protocol.Debugger.onPaused(dumpAndResume)) |
| 82 .then(() => Protocol.Debugger.resume()); | 92 .then(() => Protocol.Debugger.resume()); |
| 83 }, | 93 }, |
| 84 | 94 |
| 85 function getPossibleBreakpointsInRangeWithOffset(next) { | 95 function getPossibleBreakpointsInRangeWithOffset(next) { |
| 86 var source = 'function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n'; | 96 var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ r
eturn Promise.resolve().then(() => 42); }\n\n"; |
| 87 var scriptId; | 97 var scriptId; |
| 88 compileScript(source, { name: 'with-offset.js', line_offset: 1, column_offse
t: 1 }) | 98 compileScript(source, { name: "with-offset.js", line_offset: 1, column_offse
t: 1 }) |
| 89 .then(id => scriptId = id) | 99 .then(id => scriptId = id) |
| 90 .then(() => InspectorTest.log('Test empty range in first line.')) | 100 .then(() => InspectorTest.log("Test empty range in first line.")) |
| 91 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
17, scriptId: scriptId }})) | 101 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
17, scriptId: scriptId }})) |
| 92 .then(message => dumpAllLocations(message, source, 1, 1)) | 102 .then(InspectorTest.logMessage) |
| 93 .then(() => InspectorTest.log('Test one character range in first line.')) | 103 .then(() => InspectorTest.log("Test one character range in first line.")) |
| 94 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
18, scriptId: scriptId }})) | 104 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 17, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
18, scriptId: scriptId }})) |
| 95 .then(message => dumpAllLocations(message, source, 1, 1)) | 105 .then(InspectorTest.logMessage) |
| 96 .then(() => InspectorTest.log('Test empty range in not first line.')) | 106 .then(() => InspectorTest.log("Test empty range in not first line.")) |
| 97 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
16, scriptId: scriptId }})) | 107 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
16, scriptId: scriptId }})) |
| 98 .then(message => dumpAllLocations(message, source, 1, 1)) | 108 .then(InspectorTest.logMessage) |
| 99 .then(() => InspectorTest.log('Test one character range in not first line.
')) | 109 .then(() => InspectorTest.log("Test one character range in not first line.
")) |
| 100 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
17, scriptId: scriptId }})) | 110 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 2, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
17, scriptId: scriptId }})) |
| 101 .then(message => dumpAllLocations(message, source, 1, 1)) | 111 .then(InspectorTest.logMessage) |
| 102 .then(() => InspectorTest.log('Test end is undefined')) | 112 .then(() => InspectorTest.log("Test end is undefined")) |
| 103 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) | 113 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }})) |
| 104 .then(message => dumpAllLocations(message, source, 1, 1)) | 114 .then(InspectorTest.logMessage) |
| 105 .then(() => InspectorTest.log('Test end.lineNumber > scripts.lineCount()')
) | 115 .then(() => InspectorTest.log("Test end.lineNumber > scripts.lineCount()")
) |
| 106 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber:
0, scriptId: scriptId }})) | 116 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber:
0, scriptId: scriptId }})) |
| 107 .then(message => dumpAllLocations(message, source, 1, 1)) | 117 .then(InspectorTest.logMessage) |
| 108 .then(() => InspectorTest.log('Test one string')) | 118 .then(() => InspectorTest.log("Test one string")) |
| 109 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
0, scriptId: scriptId }})) | 119 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 2, columnNumber:
0, scriptId: scriptId }})) |
| 110 .then(message => dumpAllLocations(message, source, 1, 1)) | 120 .then(InspectorTest.logMessage) |
| 111 .then(() => InspectorTest.log('Test end.columnNumber > end.line.length(),
should be the same as previous.')) | 121 .then(() => InspectorTest.log("Test end.columnNumber > end.line.length(),
should be the same as previous.")) |
| 112 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
256, scriptId: scriptId }})) | 122 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber
: 1, columnNumber: 1, scriptId: scriptId }, end: { lineNumber: 1, columnNumber:
256, scriptId: scriptId }})) |
| 113 .then(message => dumpAllLocations(message, source, 1, 1)) | 123 .then(InspectorTest.logMessage) |
| 114 .then(next); | 124 .then(next); |
| 115 }, | 125 }, |
| 116 | 126 |
| 117 function withOffset(next) { | 127 function withOffset(next) { |
| 118 Protocol.Debugger.onPaused(message => dumpBreakLocationInSourceAndResume(mes
sage, source, 3, 18)); | 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 }); |
| 119 | 133 |
| 120 var source = `function foo5() { Promise.resolve().then(() => 42) } | 134 var source = `function foo5() { Promise.resolve().then(() => 42) } |
| 121 function foo6() { Promise.resolve().then(() => 42) }`; | 135 function foo6() { Promise.resolve().then(() => 42) }`; |
| 122 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, undef
ined, { name: 'with-offset.js', line_offset: 3, column_offset: 18 }) | 136 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, undef
ined, { name: "with-offset.js", line_offset: 3, column_offset: 18 }) |
| 123 .then(message => dumpAllLocations(message, source, 3, 18)) | 137 .then(InspectorTest.logMessage) |
| 124 .then(setAllBreakpoints) | 138 .then(setAllBreakpoints) |
| 125 .then(() => Protocol.Runtime.evaluate({ expression: 'foo5(); foo6()'})) | 139 .then(() => Protocol.Runtime.evaluate({ expression: "foo5(); foo6()"})) |
| 126 .then(next); | 140 .then(next); |
| 127 }, | 141 }, |
| 128 | 142 |
| 129 function arrowFunctionReturn(next) { | 143 function arrowFunctionReturn(next) { |
| 130 function checkSource(source, location) { | 144 waitForPossibleBreakpoints("() => 239\n", { lineNumber: 0, columnNumber: 0 }
) |
| 131 return waitForPossibleBreakpoints(source, location) | 145 .then(InspectorTest.logMessage) |
| 132 .then(message => dumpAllLocations(message, source)); | 146 .then(() => waitForPossibleBreakpoints("function foo() { function boo() {
return 239 } }\n", { lineNumber: 0, columnNumber: 0 })) |
| 133 } | 147 .then(InspectorTest.logMessage) |
| 134 | 148 .then(() => waitForPossibleBreakpoints("() => { 239 }\n", { lineNumber: 0,
columnNumber: 0 })) |
| 135 checkSource('() => 239\n', { lineNumber: 0, columnNumber: 0 }) | 149 .then(InspectorTest.logMessage) |
| 136 .then(() => checkSource('function foo() { function boo() { return 239 } }
\n', { lineNumber: 0, columnNumber: 0 })) | 150 // TODO(kozyatinskiy): lineNumber for return position should be 21 instead
of 22. |
| 137 .then(() => checkSource('() => { 239 }\n', { lineNumber: 0, columnNumber:
0 })) | 151 .then(() => waitForPossibleBreakpoints("function foo() { 239 }\n", { lineN
umber: 0, columnNumber: 0 })) |
| 138 .then(() => checkSource('function foo() { 239 }\n', { lineNumber: 0, colum
nNumber: 0 })) | 152 .then(InspectorTest.logMessage) |
| 139 // TODO(kozyatinskiy): lineNumber for return position should be only 9, no
t 8. | 153 // TODO(kozyatinskiy): lineNumber for return position should be only 9, no
t 8. |
| 140 .then(() => checkSource('() => 239', { lineNumber: 0, columnNumber: 0 })) | 154 .then(() => waitForPossibleBreakpoints("() => 239", { lineNumber: 0, colum
nNumber: 0 })) |
| 141 .then(() => checkSource('() => { return 239 }', { lineNumber: 0, columnNum
ber: 0 })) | 155 .then(InspectorTest.logMessage) |
| 142 .then(next); | 156 // TODO(kozyatinskiy): lineNumber for return position should be only 19, n
ot 20. |
| 143 }, | 157 .then(() => waitForPossibleBreakpoints("() => { return 239 }", { lineNumbe
r: 0, columnNumber: 0 })) |
| 144 | 158 .then(InspectorTest.logMessage) |
| 145 function argumentsAsCalls(next) { | 159 .then(next) |
| 146 var source = 'function foo(){}\nfunction boo(){}\nfunction main(f1,f2){}\nma
in(foo(), boo());\n'; | |
| 147 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }) | |
| 148 .then(message => dumpAllLocations(message, source)) | |
| 149 .then(next); | |
| 150 } | 160 } |
| 151 ]); | 161 ]); |
| 152 | 162 |
| 153 function compileScript(source, origin) { | 163 function compileScript(source, origin) { |
| 154 var promise = Protocol.Debugger.onceScriptParsed().then(message => message.par
ams.scriptId); | 164 var promise = Protocol.Debugger.onceScriptParsed().then(message => message.par
ams.scriptId); |
| 155 if (!origin) origin = { name: '', line_offset: 0, column_offset: 0 }; | 165 if (!origin) origin = { name: "", line_offset: 0, column_offset: 0 }; |
| 156 compileAndRunWithOrigin(source, origin.name, origin.line_offset, origin.column
_offset, false); | 166 compileAndRunWithOrigin(source, origin.name, origin.line_offset, origin.column
_offset, false); |
| 157 return promise; | 167 return promise; |
| 158 } | 168 } |
| 159 | 169 |
| 160 function waitForPossibleBreakpoints(source, start, end, origin) { | 170 function waitForPossibleBreakpoints(source, start, end, origin) { |
| 161 return compileScript(source, origin) | 171 return compileScript(source, origin) |
| 162 .then(scriptId => { (start || {}).scriptId = scriptId; (end || {}).scriptId
= scriptId }) | 172 .then(scriptId => { (start || {}).scriptId = scriptId; (end || {}).scriptId
= scriptId }) |
| 163 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); | 173 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); |
| 164 } | 174 } |
| 165 | 175 |
| 166 function waitForPossibleBreakpointsOnPause(source, start, end, next) { | 176 function waitForPossibleBreakpointsOnPause(source, start, end, next) { |
| 167 var promise = Protocol.Debugger.oncePaused() | 177 var promise = Protocol.Debugger.oncePaused() |
| 168 .then(msg => { (start || {}).scriptId = msg.params.callFrames[0].location.sc
riptId; (end || {}).scriptId = msg.params.callFrames[0].location.scriptId }) | 178 .then(msg => { (start || {}).scriptId = msg.params.callFrames[0].location.sc
riptId; (end || {}).scriptId = msg.params.callFrames[0].location.scriptId }) |
| 169 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); | 179 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en
d })); |
| 170 Protocol.Runtime.evaluate({ expression: source }).then(next); | 180 Protocol.Runtime.evaluate({ expression: source }).then(next); |
| 171 return promise; | 181 return promise; |
| 172 } | 182 } |
| 173 | 183 |
| 174 function setAllBreakpoints(message) { | 184 function setAllBreakpoints(message) { |
| 175 var promises = []; | 185 var promises = []; |
| 176 for (var location of message.result.locations) | 186 for (var location of message.result.locations) |
| 177 promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(c
heckBreakpoint)); | 187 promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(c
heckBreakpointAndDump)); |
| 178 return Promise.all(promises); | 188 return Promise.all(promises); |
| 179 } | 189 } |
| 180 | 190 |
| 181 function checkBreakpoint(message) { | 191 function checkBreakpointAndDump(message) { |
| 182 if (message.error) { | 192 if (message.error) { |
| 183 InspectorTest.log('FAIL: error in setBreakpoint'); | 193 InspectorTest.log("FAIL: error in setBreakpoint"); |
| 184 InspectorTest.logMessage(message); | 194 InspectorTest.logMessage(message); |
| 185 return; | 195 return; |
| 186 } | 196 } |
| 187 var id_data = message.result.breakpointId.split(':'); | 197 var id_data = message.result.breakpointId.split(":"); |
| 188 if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parse
Int(id_data[2]) !== message.result.actualLocation.columnNumber) { | 198 if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parse
Int(id_data[2]) !== message.result.actualLocation.columnNumber) { |
| 189 InspectorTest.log('FAIL: possible breakpoint was resolved in another locatio
n'); | 199 InspectorTest.log("FAIL: possible breakpoint was resolved in another locatio
n"); |
| 200 InspectorTest.logMessage(message); |
| 190 } | 201 } |
| 202 InspectorTest.logMessage(message); |
| 191 } | 203 } |
| 192 | |
| 193 function dumpAllLocations(message, source, lineOffset, columnOffset) { | |
| 194 if (message.error) { | |
| 195 InspectorTest.logMessage(message); | |
| 196 return; | |
| 197 } | |
| 198 | |
| 199 lineOffset = lineOffset || 0; | |
| 200 columnOffset = columnOffset || 0; | |
| 201 | |
| 202 var sourceLines = source.split('\n') | |
| 203 var lineOffsets = Array(sourceLines.length).fill(0); | |
| 204 for (var location of message.result.locations) { | |
| 205 var lineNumber = location.lineNumber - lineOffset; | |
| 206 var columnNumber = lineNumber !== 0 ? location.columnNumber : location.colum
nNumber - columnOffset; | |
| 207 var line = sourceLines[lineNumber] || ''; | |
| 208 var offset = lineOffsets[lineNumber]; | |
| 209 line = line.slice(0, columnNumber + offset) + '#' + line.slice(columnNumber
+ offset); | |
| 210 ++lineOffsets[lineNumber]; | |
| 211 sourceLines[lineNumber] = line; | |
| 212 } | |
| 213 InspectorTest.log(sourceLines.join('\n')); | |
| 214 return message; | |
| 215 } | |
| 216 | |
| 217 function dumpBreakLocationInSourceAndResume(message, source, lineOffset, columnO
ffset) { | |
| 218 lineOffset = lineOffset || 0; | |
| 219 columnOffset = columnOffset || 0; | |
| 220 | |
| 221 InspectorTest.log('paused in ' + message.params.callFrames[0].functionName); | |
| 222 var location = message.params.callFrames[0].location; | |
| 223 var sourceLines = source.split('\n') | |
| 224 | |
| 225 var lineNumber = location.lineNumber - lineOffset; | |
| 226 var columnNumber = lineNumber !== 0 ? location.columnNumber : location.columnN
umber - columnOffset; | |
| 227 | |
| 228 var line = sourceLines[lineNumber]; | |
| 229 line = line.slice(0, columnNumber) + '^' + line.slice(columnNumber); | |
| 230 sourceLines[lineNumber] = line; | |
| 231 InspectorTest.log(sourceLines.join('\n')); | |
| 232 Protocol.Debugger.resume(); | |
| 233 } | |
| OLD | NEW |