| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/protocol-test.js"></script> |
| <script> |
| // Put this here instead of on <body onload> to prevent an extra Debugger.scriptParsed event. |
| window.onload = runTest; |
| |
| function test() |
| { |
| // This test sets a breakpoint on line:column in the <script> below. |
| // We set a breakpoint before evaluating 'sum += ...', and verify that |
| // call frame this values are what we expect. |
| |
| InspectorProtocol.sendCommand("Debugger.enable", {}); |
| InspectorProtocol.sendCommand("Debugger.setBreakpointsActive", {active: true}); |
| |
| InspectorProtocol.eventHandler["Debugger.scriptParsed"] = function(messageObject) |
| { |
| if (/call-frame-this-host\.html$/.test(messageObject.params.url) && messageObject.params.startLine > 10) { |
| ProtocolTest.log("Found <script>"); |
| var scriptIdentifier = messageObject.params.scriptId; |
| var lineNumber = messageObject.params.startLine + 6; |
| var columnNumber = 12; |
| var location = {scriptId: scriptIdentifier, lineNumber: lineNumber, columnNumber: columnNumber}; |
| InspectorProtocol.sendCommand("Debugger.setBreakpoint", {location: location}, function() { |
| ProtocolTest.log("Running testFunction"); |
| InspectorProtocol.sendCommand("Runtime.evaluate", {expression: "testFunction()"}); |
| }); |
| } |
| } |
| |
| InspectorProtocol.eventHandler["Debugger.paused"] = function(messageObject) |
| { |
| ProtocolTest.log("Hit Breakpoint!"); |
| InspectorProtocol.sendCommand("Debugger.disable"); |
| |
| var thisValues = [ ]; |
| var i; |
| for (i = 0; i < 3; i++) |
| thisValues[i] = messageObject.params.callFrames[i].this; |
| |
| function assertThisValue(index, actual, expected) { |
| var success = true; |
| if (actual.type != expected.type) { |
| ProtocolTest.log('FAIL: frame[' + index + '] expect type "' + expected.type + '", actual "' + actual.type + '"'); |
| success = false; |
| } |
| |
| if (actual.className != expected.className) { |
| ProtocolTest.log('FAIL: frame[' + index + '] expect className "' + expected.className + '", actual "' + actual.className + '"'); |
| success = false; |
| } |
| |
| if (success) |
| ProtocolTest.log('PASS: frame[' + index + '] type "' + actual.type + '" className "' + actual.className + '"'); |
| } |
| |
| // frame 0 should be the anonymous inner function. |
| assertThisValue(0, thisValues[0], { |
| "type": "object", |
| "className": "Window" |
| }); |
| |
| // frame 1 should be "forEach" (an internal/host function). |
| assertThisValue(1, thisValues[1], { |
| "type": "object", |
| "className": "Array" |
| }); |
| |
| // frame 2 should be "testFunction". |
| assertThisValue(2, thisValues[2], { |
| "type": "object", |
| "className": "Window" |
| }); |
| ProtocolTest.completeTest(); |
| } |
| } |
| </script> |
| </head> |
| <body> |
| <p>Debugger.setBreakpoint on line:column in <script></p> |
| <script>// Line 0 |
| function testFunction() { // Line 1 |
| try { // Line 2 |
| var array = [2, 5, 7]; // Line 3 |
| var sum = 0; // Line 4 |
| array.forEach(function(value) { // Line 5 |
| sum += array[value]; // Line 6 |
| }); |
| } catch (e) { |
| console.log("Exception: " + e); |
| } |
| } |
| </script> |
| </body> |
| </html> |