Web Inspector: Stack trace view doesn't properly display lines without function names
authornvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Oct 2015 06:01:30 +0000 (06:01 +0000)
committernvasilyev@apple.com <nvasilyev@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Oct 2015 06:01:30 +0000 (06:01 +0000)
https://bugs.webkit.org/show_bug.cgi?id=149922

Source/WebInspectorUI:

Reviewed by Timothy Hatcher.

* UserInterface/Models/StackTrace.js:
(WebInspector.StackTrace._parseStackTrace):
(WebInspector.StackTrace._parseLocation): Added.

LayoutTests:

Test an anomymous function.

Reviewed by Timothy Hatcher.

* inspector/debugger/js-stacktrace-expected.txt: Also, rebaseline one old test.
* inspector/debugger/js-stacktrace.html:

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

LayoutTests/ChangeLog
LayoutTests/inspector/debugger/js-stacktrace-expected.txt
LayoutTests/inspector/debugger/js-stacktrace.html
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Models/StackTrace.js

index 452faa9..549c3bb 100644 (file)
@@ -1,3 +1,15 @@
+2015-10-08  Nikita Vasilyev  <nvasilyev@apple.com>
+
+        Web Inspector: Stack trace view doesn't properly display lines without function names
+        https://bugs.webkit.org/show_bug.cgi?id=149922
+
+        Test an anomymous function.
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/debugger/js-stacktrace-expected.txt: Also, rebaseline one old test.
+        * inspector/debugger/js-stacktrace.html:
+
 2015-10-08  Brian Burg  <bburg@apple.com>
 
         http/tests/media/media-source/SourceBuffer-abort-updating.html is flaky
index 0c97e90..8595550 100644 (file)
@@ -71,8 +71,24 @@ Error object:
     {
         "functionName": "testWithNativeCallInBetween",
         "url": "/inspector/debugger/js-stacktrace.html",
-        "lineNumber": "23",
-        "columnNumber": "20"
+        "lineNumber": 23,
+        "columnNumber": 20
+    }
+]
+
+Error object:
+[
+    {
+        "functionName": "",
+        "url": "/inspector/debugger/js-stacktrace.html",
+        "lineNumber": 31,
+        "columnNumber": 33
+    },
+    {
+        "functionName": "global code",
+        "url": "/inspector/debugger/js-stacktrace.html",
+        "lineNumber": 35,
+        "columnNumber": 3
     }
 ]
 
index 369cf3c..71e22a5 100644 (file)
@@ -23,6 +23,21 @@ function testWithNativeCallInBetween()
     return [42].map(typeError)[0];
 }
 
+var _anonymousFunctionError = null;
+
+(function() {
+    var object = {};
+    try {
+        object.methodDoesntExist();
+    } catch (e) {
+        _anonymousFunctionError = e.stack;
+    }
+})();
+
+function getAnonymousFunctionError() {
+    return _anonymousFunctionError;
+}
+
 
 function test()
 {
@@ -71,6 +86,19 @@ function test()
         InspectorTest.completeTest();
     });
 
+    InspectorTest.evaluateInPage("getAnonymousFunctionError()", function(error, result) {
+        InspectorTest.log("\nError object:");
+
+        if (error)
+            InspectorTest.log(error);
+
+        var stackTrace = stripPayloadAfterEval(WebInspector.StackTrace._parseStackTrace(result.value));
+        stackTrace = stripFilePaths(stackTrace);
+
+        InspectorTest.log(JSON.stringify(stackTrace, null, 4));
+        InspectorTest.completeTest();
+    });
+
     function stripFilePaths(stackTrace)
     {
         for (var frame of stackTrace) {
index 3fcaec5..d83b348 100644 (file)
@@ -1,5 +1,16 @@
 2015-10-08  Nikita Vasilyev  <nvasilyev@apple.com>
 
+        Web Inspector: Stack trace view doesn't properly display lines without function names
+        https://bugs.webkit.org/show_bug.cgi?id=149922
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Models/StackTrace.js:
+        (WebInspector.StackTrace._parseStackTrace):
+        (WebInspector.StackTrace._parseLocation): Added.
+
+2015-10-08  Nikita Vasilyev  <nvasilyev@apple.com>
+
         Web Inspector: An error view doesn't get expanded by clicking on the expand arrow
         https://bugs.webkit.org/show_bug.cgi?id=149917
 
index d4c645b..6d3b19d 100644 (file)
@@ -58,24 +58,14 @@ WebInspector.StackTrace = class StackTrace extends WebInspector.Object
             var url = "";
             var lineNumber = 0;
             var columnNumber = 0;
-
-            var index = line.indexOf("@");
-            if (index !== -1) {
-                functionName = line.slice(0, index);
-                url = line.slice(index + 1);
-
-                var columnIndex = url.lastIndexOf(":");
-                if (columnIndex !== -1) {
-                    columnNumber = parseInt(url.slice(columnIndex + 1));
-
-                    url = url.slice(0, columnIndex);
-                    var lineIndex = url.lastIndexOf(":", columnIndex);
-                    if (lineIndex !== -1) {
-                        lineNumber = parseInt(url.slice(lineIndex + 1, columnIndex));
-                        url = url.slice(0, lineIndex);
-                    }
-                }
-            } else
+            var atIndex = line.indexOf("@");
+
+            if (atIndex !== -1) {
+                functionName = line.slice(0, atIndex);
+                ({url, lineNumber, columnNumber} = WebInspector.StackTrace._parseLocation(line.slice(atIndex + 1)));
+            } else if (line.includes("/"))
+                ({url, lineNumber, columnNumber} = WebInspector.StackTrace._parseLocation(line));
+            else
                 functionName = line;
 
             result.push({functionName, url, lineNumber, columnNumber});
@@ -84,6 +74,26 @@ WebInspector.StackTrace = class StackTrace extends WebInspector.Object
         return result;
     }
 
+    static _parseLocation(locationString)
+    {
+        var result = {url: "", lineNumber: 0, columnNumber: 0};
+        var locationRegEx = /(.+?)(?::(\d+)(?::(\d+))?)?$/;
+        var matched = locationString.match(locationRegEx);
+
+        if (!matched)
+            return result;
+
+        result.url = matched[1];
+
+        if (matched[2])
+            result.lineNumber = parseInt(matched[2]);
+
+        if (matched[3])
+            result.columnNumber = parseInt(matched[3]);
+
+        return result;
+    }
+
     // Public
 
     get callFrames()