mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
commit-queue@webkit.org | 0c88cda | 2015-08-06 21:17:03 +0000 | [diff] [blame] | 3 | <script src="../../http/tests/inspector/resources/protocol-test.js"></script> |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 4 | <script> |
| 5 | // Put this here instead of on <body onload> to prevent an extra Debugger.scriptParsed event. |
| 6 | window.onload = runTest; |
| 7 | |
| 8 | function test() |
| 9 | { |
| 10 | // This test sets a breakpoint on line:column in the <script> below. |
| 11 | // We set a breakpoint before evaluating 'sum += ...', and verify that |
| 12 | // call frame functionNames are what we expect. |
| 13 | |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 14 | InspectorProtocol.sendCommand("Debugger.enable", {}); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 15 | |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 16 | InspectorProtocol.eventHandler["Debugger.scriptParsed"] = function(messageObject) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 17 | { |
| 18 | if (/call-frame-function-name\.html$/.test(messageObject.params.url) && messageObject.params.startLine > 10) { |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 19 | ProtocolTest.log("Found <script>"); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 20 | var scriptIdentifier = messageObject.params.scriptId; |
| 21 | var lineNumber = messageObject.params.startLine + 6; |
| 22 | var columnNumber = 12; |
| 23 | var location = {scriptId: scriptIdentifier, lineNumber: lineNumber, columnNumber: columnNumber}; |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 24 | InspectorProtocol.sendCommand("Debugger.setBreakpoint", {location: location}, function() { |
| 25 | ProtocolTest.log("Running testFunction"); |
| 26 | InspectorProtocol.sendCommand("Runtime.evaluate", {expression: "testFunction()"}); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 27 | }); |
| 28 | } |
| 29 | } |
| 30 | |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 31 | InspectorProtocol.eventHandler["Debugger.paused"] = function(messageObject) |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 32 | { |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 33 | ProtocolTest.log("Hit Breakpoint!"); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 34 | var functionNames = [ ]; |
| 35 | var i; |
| 36 | for (i = 0; i < 3; i++) |
| 37 | functionNames[i] = messageObject.params.callFrames[i].functionName; |
| 38 | |
| 39 | function assertFunctionName(index, actual, expected) { |
| 40 | if (actual == expected) |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 41 | ProtocolTest.log('PASS: frame[' + index + '] "' + actual + '"'); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 42 | else |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 43 | ProtocolTest.log('FAIL: frame[' + index + '] expect "' + expected + '", actual "' + actual + '"'); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | // frame 0 should be the anonymous inner function. |
| 47 | assertFunctionName(0, functionNames[0], ""); |
| 48 | |
| 49 | // frame 1 should be "forEach" (an internal/host function). |
| 50 | assertFunctionName(1, functionNames[1], "forEach"); |
| 51 | |
| 52 | // frame 2 should be "testFunction". |
| 53 | assertFunctionName(2, functionNames[2], "testFunction"); |
| 54 | |
commit-queue@webkit.org | 6a3d0dc | 2015-08-11 18:28:31 +0000 | [diff] [blame] | 55 | ProtocolTest.completeTest(); |
mark.lam@apple.com | af032dd | 2013-10-05 00:51:31 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | </script> |
| 59 | </head> |
| 60 | <body> |
| 61 | <p>Debugger.setBreakpoint on line:column in <script></p> |
| 62 | <script>// Line 0 |
| 63 | function testFunction() { // Line 1 |
| 64 | try { // Line 2 |
| 65 | var array = [2, 5, 7]; // Line 3 |
| 66 | var sum = 0; // Line 4 |
| 67 | array.forEach(function(value) { // Line 5 |
| 68 | sum += array[value]; // Line 6 |
| 69 | }); |
| 70 | } catch (e) { |
| 71 | console.log("Exception: " + e); |
| 72 | } |
| 73 | } |
| 74 | </script> |
| 75 | </body> |
| 76 | </html> |