blob: dc96b5bc9ea2413addd5be50f6ee6fea8ee5cb1e [file] [log] [blame]
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +00001<html>
2<head>
commit-queue@webkit.org0c88cda2015-08-06 21:17:03 +00003<script src="../../http/tests/inspector/resources/protocol-test.js"></script>
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +00004<script>
5// Put this here instead of on <body onload> to prevent an extra Debugger.scriptParsed event.
6window.onload = runTest;
7
8function 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.org6a3d0dc2015-08-11 18:28:31 +000014 InspectorProtocol.sendCommand("Debugger.enable", {});
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000015
commit-queue@webkit.org6a3d0dc2015-08-11 18:28:31 +000016 InspectorProtocol.eventHandler["Debugger.scriptParsed"] = function(messageObject)
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000017 {
18 if (/call-frame-function-name\.html$/.test(messageObject.params.url) && messageObject.params.startLine > 10) {
commit-queue@webkit.org6a3d0dc2015-08-11 18:28:31 +000019 ProtocolTest.log("Found <script>");
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000020 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.org6a3d0dc2015-08-11 18:28:31 +000024 InspectorProtocol.sendCommand("Debugger.setBreakpoint", {location: location}, function() {
25 ProtocolTest.log("Running testFunction");
26 InspectorProtocol.sendCommand("Runtime.evaluate", {expression: "testFunction()"});
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000027 });
28 }
29 }
30
commit-queue@webkit.org6a3d0dc2015-08-11 18:28:31 +000031 InspectorProtocol.eventHandler["Debugger.paused"] = function(messageObject)
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000032 {
commit-queue@webkit.org6a3d0dc2015-08-11 18:28:31 +000033 ProtocolTest.log("Hit Breakpoint!");
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000034 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.org6a3d0dc2015-08-11 18:28:31 +000041 ProtocolTest.log('PASS: frame[' + index + '] "' + actual + '"');
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000042 else
commit-queue@webkit.org6a3d0dc2015-08-11 18:28:31 +000043 ProtocolTest.log('FAIL: frame[' + index + '] expect "' + expected + '", actual "' + actual + '"');
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000044 }
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.org6a3d0dc2015-08-11 18:28:31 +000055 ProtocolTest.completeTest();
mark.lam@apple.comaf032dd2013-10-05 00:51:31 +000056 }
57}
58</script>
59</head>
60<body>
61<p>Debugger.setBreakpoint on line:column in &lt;script&gt;</p>
62<script>// Line 0
63function 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>