Chromium Code Reviews| 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 /** | |
| 12 * - collected script | |
|
dgozman
2016/11/03 21:13:13
Remove?
kozy
2016/11/03 22:17:13
Removed.
| |
| 13 * - on paused | |
| 14 */ | |
| 15 | |
| 16 InspectorTest.runTestSuite([ | |
| 17 function getPossibleBreakpointsInRange(next) { | |
| 18 var source = "function foo(){ return Promise.resolve(); }\nfunction boo(){ r eturn Promise.resolve().then(() => 42); }\n\n"; | |
| 19 var scriptId; | |
| 20 compileScript(source) | |
| 21 .then(id => scriptId = id) | |
| 22 .then(() => InspectorTest.log("Test start.scriptId != end.scriptId.")) | |
| 23 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 0, scriptId: scriptId + "0" }})) | |
| 24 .then(InspectorTest.logMessage) | |
| 25 .then(() => InspectorTest.log("Test not existing scriptId.")) | |
| 26 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: "-1" }})) | |
| 27 .then(InspectorTest.logMessage) | |
| 28 .then(() => InspectorTest.log("Test end < start.")) | |
| 29 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 1, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 0, scriptId: scriptId }})) | |
| 30 .then(InspectorTest.logMessage) | |
| 31 .then(() => InspectorTest.log("Test empty range in first line.")) | |
| 32 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 16, scriptId: scriptId }})) | |
| 33 .then(InspectorTest.logMessage) | |
| 34 .then(() => InspectorTest.log("Test one character range in first line.")) | |
| 35 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 17, scriptId: scriptId }})) | |
| 36 .then(InspectorTest.logMessage) | |
| 37 .then(() => InspectorTest.log("Test empty range in not first line.")) | |
| 38 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 16, scriptId: scriptId }})) | |
| 39 .then(InspectorTest.logMessage) | |
| 40 .then(() => InspectorTest.log("Test one character range in not first line. ")) | |
| 41 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 1, columnNumber: 16, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 17, scriptId: scriptId }})) | |
| 42 .then(InspectorTest.logMessage) | |
| 43 .then(() => InspectorTest.log("Test end is undefined")) | |
| 44 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }})) | |
| 45 .then(InspectorTest.logMessage) | |
| 46 .then(() => InspectorTest.log("Test end.lineNumber > scripts.lineCount()") ) | |
| 47 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 5, columnNumber: 0, scriptId: scriptId }})) | |
| 48 .then(InspectorTest.logMessage) | |
| 49 .then(() => InspectorTest.log("Test one string")) | |
| 50 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 1, columnNumber: 0, scriptId: scriptId }})) | |
| 51 .then(InspectorTest.logMessage) | |
| 52 .then(() => InspectorTest.log("Test end.columnNumber > end.line.length(), should be the same as previous.")) | |
| 53 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }, end: { lineNumber: 0, columnNumber: 256, scriptId: scriptId }})) | |
| 54 .then(InspectorTest.logMessage) | |
| 55 .then(next); | |
| 56 }, | |
| 57 | |
| 58 function getPossibleBreakpointsInArrow(next) { | |
| 59 var source = "function foo() { return Promise.resolve().then(() => 239).then (() => 42).then(() => () => 42) }"; | |
| 60 var scriptId; | |
| 61 compileScript(source) | |
| 62 .then(id => scriptId = id) | |
| 63 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber : 0, columnNumber: 0, scriptId: scriptId }})) | |
| 64 .then(InspectorTest.logMessage) | |
| 65 .then(next); | |
| 66 }, | |
| 67 | |
| 68 function arrowFunctionFirstLine(next) { | |
| 69 Protocol.Debugger.onPaused(message => { | |
| 70 InspectorTest.log("paused in " + message.params.callFrames[0].functionName ); | |
| 71 InspectorTest.logMessage(message.params.callFrames[0].location); | |
| 72 Protocol.Debugger.resume(); | |
| 73 }); | |
| 74 | |
| 75 var source = `function foo1() { Promise.resolve().then(() => 42) } | |
| 76 function foo2() { Promise.resolve().then(() => 42) }`; | |
| 77 waitForPossibleBreakpoints(source, { lineNumber: 0, columnNumber: 0 }, { lin eNumber: 1, columnNumber: 0 }) | |
| 78 .then(InspectorTest.logMessage) | |
| 79 .then(setAllBreakpoints) | |
| 80 .then(() => Protocol.Runtime.evaluate({ expression: "foo1(); foo2()"})) | |
| 81 .then(next); | |
| 82 }, | |
| 83 | |
| 84 function arrowFunctionOnPause(next) { | |
| 85 function dumpAndResume(message) { | |
| 86 InspectorTest.log("paused in " + message.params.callFrames[0].functionName ); | |
| 87 InspectorTest.logMessage(message.params.callFrames[0].location); | |
| 88 Protocol.Debugger.resume(); | |
| 89 } | |
| 90 | |
| 91 // TODO(kozyatinskiy): where pauses before foo3 and foo4 calls?! | |
|
dgozman
2016/11/03 21:13:13
?!?!!11!111!!!?
kozy
2016/11/03 22:17:13
Removed.
| |
| 92 var source = `debugger; function foo3() { Promise.resolve().then(() => 42) } | |
| 93 function foo4() { Promise.resolve().then(() => 42) };\nfoo3();\nfoo4();`; | |
| 94 waitForPossibleBreakpointsOnPause(source, { lineNumber: 0, columnNumber: 0 } , undefined, next) | |
| 95 .then(InspectorTest.logMessage) | |
| 96 .then(setAllBreakpoints) | |
| 97 .then(() => Protocol.Debugger.onPaused(dumpAndResume)) | |
| 98 .then(() => Protocol.Debugger.resume()); | |
| 99 } | |
| 100 | |
| 101 ]); | |
| 102 | |
| 103 function compileScript(source) { | |
| 104 var promise = Protocol.Debugger.onceScriptParsed().then(message => message.par ams.scriptId); | |
| 105 Protocol.Runtime.compileScript({ expression: source, sourceURL: "", persistScr ipt: true }); | |
| 106 return promise; | |
| 107 } | |
| 108 | |
| 109 function waitForPossibleBreakpoints(source, start, end) { | |
| 110 var promise = Protocol.Debugger.onceScriptParsed() | |
| 111 .then(msg => { (start || {}).scriptId = msg.params.scriptId; (end || {}).scr iptId = msg.params.scriptId }) | |
| 112 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en d })); | |
| 113 Protocol.Runtime.evaluate({ expression: source }); | |
| 114 return promise; | |
| 115 } | |
| 116 | |
| 117 function waitForPossibleBreakpointsOnPause(source, start, end, next) { | |
| 118 var promise = Protocol.Debugger.oncePaused() | |
| 119 .then(msg => { (start || {}).scriptId = msg.params.callFrames[0].location.sc riptId; (end || {}).scriptId = msg.params.callFrames[0].location.scriptId }) | |
| 120 .then(() => Protocol.Debugger.getPossibleBreakpoints({ start: start, end: en d })); | |
| 121 Protocol.Runtime.evaluate({ expression: source }).then(next); | |
| 122 return promise; | |
| 123 } | |
| 124 | |
| 125 function setAllBreakpoints(message) { | |
| 126 var promises = []; | |
| 127 for (var location of message.result.locations) | |
| 128 promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(c heckBreakpointAndDump)); | |
| 129 return Promise.all(promises); | |
| 130 } | |
| 131 | |
| 132 function checkBreakpointAndDump(message) { | |
| 133 if (message.error) { | |
| 134 InspectorTest.log("FAIL: error in setBreakpoint"); | |
| 135 InspectorTest.logMessage(message); | |
| 136 return; | |
| 137 } | |
| 138 var id_data = message.result.breakpointId.split(":"); | |
| 139 if (id_data[1] * 1 !== message.result.actualLocation.lineNumber || id_data[2] * 1 !== message.result.actualLocation.columnNumber) { | |
|
dgozman
2016/11/03 21:13:13
parseInt
kozy
2016/11/03 22:17:13
Done.
| |
| 140 InspectorTest.log("FAIL: possible breakpoint was resolved in another locatio n"); | |
| 141 InspectorTest.logMessage(message); | |
| 142 } | |
| 143 InspectorTest.logMessage(message); | |
| 144 } | |
| OLD | NEW |