Web Inspector: debugger reports wrong sources when paused in inline script on page...
authoryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 17:03:16 +0000 (17:03 +0000)
committeryurys@chromium.org <yurys@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 1 Feb 2012 17:03:16 +0000 (17:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77548

Source/WebCore:

V8 returns treats each script source as ending with \n, now we take
this into account when reporting script line count to the inspector
front-end.

Reviewed by Vsevolod Vlasov.

Test: inspector/debugger/pause-in-inline-script.html

* bindings/js/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::dispatchDidParseSource):
* bindings/v8/DebuggerScript.js:

LayoutTests:

Reviewed by Vsevolod Vlasov.

* inspector/debugger/debugger-scripts-expected.txt:
* inspector/debugger/pause-in-inline-script-expected.txt: Added.
* inspector/debugger/pause-in-inline-script.html: Added.
* platform/chromium/inspector/debugger/debugger-scripts-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@106468 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/debugger-scripts-expected.txt
LayoutTests/inspector/debugger/pause-in-inline-script-expected.txt [new file with mode: 0644]
LayoutTests/inspector/debugger/pause-in-inline-script.html [new file with mode: 0644]
LayoutTests/platform/chromium/inspector/debugger/debugger-scripts-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/ScriptDebugServer.cpp
Source/WebCore/bindings/v8/DebuggerScript.js

index e3e130b..f6c50b9 100644 (file)
@@ -1,3 +1,15 @@
+2012-02-01  Yury Semikhatsky  <yurys@chromium.org>
+
+        Web Inspector: debugger reports wrong sources when paused in inline script on page reload
+        https://bugs.webkit.org/show_bug.cgi?id=77548
+
+        Reviewed by Vsevolod Vlasov.
+
+        * inspector/debugger/debugger-scripts-expected.txt:
+        * inspector/debugger/pause-in-inline-script-expected.txt: Added.
+        * inspector/debugger/pause-in-inline-script.html: Added.
+        * platform/chromium/inspector/debugger/debugger-scripts-expected.txt:
+
 2012-02-01  Shinya Kawanaka  <shinyak@google.com>
 
         Content element should be able to be dynamically added/removed/replaced in a shadow tree.
index 0747a0a..77508a6 100644 (file)
@@ -3,19 +3,19 @@ Tests that valid parsed script notifications are received by front-end. Bug 5272
 Debugger was enabled.
 script 1:
     start: 5:8
-    end: 37:2
+    end: 38:0
 script 2:
     start: 38:21
-    end: 41:2
+    end: 42:0
 script 3:
     start: 43:11
     end: 43:32
 script 4:
     start: 44:11
-    end: 44:28
+    end: 45:0
 script 5:
     start: 46:11
-    end: 47:20
+    end: 48:0
 script 6:
     start: 51:56
     end: 52:2
diff --git a/LayoutTests/inspector/debugger/pause-in-inline-script-expected.txt b/LayoutTests/inspector/debugger/pause-in-inline-script-expected.txt
new file mode 100644 (file)
index 0000000..153790e
--- /dev/null
@@ -0,0 +1,19 @@
+Tests that main resource script text is correct when paused in inline script on reload. Bug 77548.
+
+Debugger was enabled.
+Did load front-end
+Paused: false
+didPauseAfterReload
+Script execution paused.
+didShowScript
+Source strings corresponding to the call stack:
+Frame 0) line 6, content: </script><script>function f1() { debugger; }</script> (must be part of function 'f1')
+Frame 1) line 8, content: function f2() { return f1(); } (must be part of function 'f2')
+Frame 2) line 14, content:     return f2(); (must be part of function 'f3')
+Frame 3) line 16, content: f3(); (must be part of function '')
+Script execution resumed.
+didResume
+Page reloaded.
+didReload
+Debugger was disabled.
+
diff --git a/LayoutTests/inspector/debugger/pause-in-inline-script.html b/LayoutTests/inspector/debugger/pause-in-inline-script.html
new file mode 100644 (file)
index 0000000..da8f07b
--- /dev/null
@@ -0,0 +1,89 @@
+<html>
+<head>
+<script>function foo() { };
+</script>
+<script>
+function bar() { };
+</script><script>function f1() { debugger; }</script>
+<script>
+function f2() { return f1(); }
+</script>
+
+<script>
+function f3()
+{
+    return f2();
+}
+f3();
+</script>
+
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/debugger-test.js"></script>
+
+<script>
+
+var test = function()
+{
+    var testName = WebInspector.inspectedPageURL;
+    testName = testName.substring(testName.lastIndexOf('/') + 1);
+
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {
+        InspectorTest.addResult("Did load front-end");
+        InspectorTest.addResult("Paused: " + !!WebInspector.debuggerModel.debuggerPausedDetails);
+        InspectorTest.reloadPage(didReload.bind(this));
+        WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, didPauseAfterReload, this); 
+
+    }
+
+    function didReload()
+    {
+        InspectorTest.addResult("didReload");
+        InspectorTest.completeDebuggerTest();
+    }
+
+    function didPauseAfterReload(details)
+    {
+        InspectorTest.addResult("didPauseAfterReload");
+        InspectorTest.showScriptSource(testName, didShowScript.bind(this));
+    }
+
+    function didShowScript(sourceFrame)
+    {
+        InspectorTest.addResult("didShowScript");
+        var resourceText = sourceFrame._textModel.text;
+        var lines = resourceText.split("\n");
+        var callFrames = WebInspector.debuggerModel.callFrames;
+        InspectorTest.addResult("Source strings corresponding to the call stack:");
+        for (var i = 0; i < callFrames.length; i++) {
+            var frame = callFrames[i];
+            var lineNumber = frame.location.lineNumber;
+            InspectorTest.addResult("Frame " + i + ") line " + lineNumber + ", content: " + lines[lineNumber] + " (must be part of function '" + frame.functionName + "')");
+        }
+        InspectorTest.resumeExecution(didResume);
+    }
+
+    function uiSourceCodeAdded(uiSourceCode)
+    {
+        InspectorTest.addResult("uiSourceCodeAdded");
+    }
+
+    function didResume()
+    {
+        InspectorTest.addResult("didResume");
+    }
+};
+</script>
+
+</head>
+
+<body onload="runTest()">
+<p>
+Tests that main resource script text is correct when paused in inline script on reload.
+<a href="https://bugs.webkit.org/show_bug.cgi?id=77548">Bug 77548.</a>
+</p>
+
+</body>
+</html>
index 1135992..06ca7f7 100644 (file)
@@ -3,19 +3,19 @@ Tests that valid parsed script notifications are received by front-end. Bug 5272
 Debugger was enabled.
 script 1:
     start: 5:8
-    end: 37:2
+    end: 38:0
 script 2:
     start: 38:21
-    end: 41:2
+    end: 42:0
 script 3:
     start: 43:11
     end: 43:32
 script 4:
     start: 44:11
-    end: 44:28
+    end: 45:0
 script 5:
     start: 46:11
-    end: 47:20
+    end: 48:0
 script 6:
     start: 51:56
     end: 52:24
index 32c1f65..1542b5f 100644 (file)
@@ -1,3 +1,20 @@
+2012-02-01  Yury Semikhatsky  <yurys@chromium.org>
+
+        Web Inspector: debugger reports wrong sources when paused in inline script on page reload
+        https://bugs.webkit.org/show_bug.cgi?id=77548
+
+        V8 returns treats each script source as ending with \n, now we take
+        this into account when reporting script line count to the inspector
+        front-end.
+
+        Reviewed by Vsevolod Vlasov.
+
+        Test: inspector/debugger/pause-in-inline-script.html
+
+        * bindings/js/ScriptDebugServer.cpp:
+        (WebCore::ScriptDebugServer::dispatchDidParseSource):
+        * bindings/v8/DebuggerScript.js:
+
 2012-02-01  Shinya Kawanaka  <shinyak@google.com>
 
         Content element should be able to be dynamically added/removed/replaced in a shadow tree.
index e8aeb42..f0cf5d2 100644 (file)
@@ -242,7 +242,7 @@ void ScriptDebugServer::dispatchDidParseSource(const ListenerSet& listeners, Sou
     int sourceLength = script.source.length();
     int lineCount = 1;
     int lastLineStart = 0;
-    for (int i = 0; i < sourceLength - 1; ++i) {
+    for (int i = 0; i < sourceLength; ++i) {
         if (script.source[i] == '\n') {
             lineCount += 1;
             lastLineStart = i + 1;
index 79dda71..b4d0b91 100644 (file)
@@ -90,10 +90,16 @@ DebuggerScript._formatScript = function(script)
     var lineCount = lineEnds.length;
     var endLine = script.line_offset + lineCount - 1;
     var endColumn;
-    if (lineCount === 1)
-        endColumn = script.source.length + script.column_offset;
-    else
-        endColumn = script.source.length - (script.line_ends[lineCount - 2] + 1);
+    // V8 will not count last line if script source ends with \n.
+    if (script.source[script.source.length - 1] === '\n') {
+        endLine += 1;
+        endColumn = 0;
+    } else {
+        if (lineCount === 1)
+            endColumn = script.source.length + script.column_offset;
+        else
+            endColumn = script.source.length - (lineEnds[lineCount - 2] + 1);
+    }
 
     return {
         id: script.id,