Web Inspector: console.table with columnName filter for non-existent property should...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 22:27:19 +0000 (22:27 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Feb 2015 22:27:19 +0000 (22:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141066

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-02-04
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/ConsoleMessage.cpp:
(Inspector::ConsoleMessage::addToFrontend):
When a user provides a second argument, e.g. console.table(..., columnNames),
then pass that second argument to the frontend.

* inspector/InjectedScriptSource.js:
Add a FIXME about the old, unused path now.

Source/WebInspectorUI:

* UserInterface/Views/ConsoleMessageImpl.js:
(WebInspector.ConsoleMessageImpl.prototype._appendPropertyPreviews):
(WebInspector.ConsoleMessageImpl.prototype._userProvidedColumnNames):
(WebInspector.ConsoleMessageImpl.prototype._formatParameterAsTable):
If a second argument was provided to console.table, try to extract a list
of string names to use for the object properties. Output a table with
the provided column names, in the specified order. Also, use this
opportunity to mark missing properties with an em dash.

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/ConsoleMessage.cpp
Source/JavaScriptCore/inspector/InjectedScriptSource.js
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js

index cb1778f..e3f0041 100644 (file)
@@ -1,3 +1,18 @@
+2015-02-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: console.table with columnName filter for non-existent property should still show column
+        https://bugs.webkit.org/show_bug.cgi?id=141066
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/ConsoleMessage.cpp:
+        (Inspector::ConsoleMessage::addToFrontend):
+        When a user provides a second argument, e.g. console.table(..., columnNames),
+        then pass that second argument to the frontend.
+
+        * inspector/InjectedScriptSource.js:
+        Add a FIXME about the old, unused path now.
+
 2015-02-04  Saam Barati  <saambarati1@gmail.com>
 
         TypeSet can use 1 byte instead of 4 bytes for its m_seenTypes member variable
index 3b985e2..50e1148 100644 (file)
@@ -208,6 +208,8 @@ void ConsoleMessage::addToFrontend(InspectorConsoleFrontendDispatcher* consoleFr
                     return;
                 }
                 jsonArgs->addItem(inspectorValue.copyRef());
+                if (m_arguments->argumentCount() > 1)
+                    jsonArgs->addItem(injectedScript.wrapObject(columns, ASCIILiteral("console"), true));
             } else {
                 for (unsigned i = 0; i < m_arguments->argumentCount(); ++i) {
                     RefPtr<Inspector::Protocol::Runtime::RemoteObject> inspectorValue = injectedScript.wrapObject(m_arguments->argumentAt(i), ASCIILiteral("console"), generatePreview);
index 5df30be..c88403e 100644 (file)
@@ -102,6 +102,10 @@ InjectedScript.prototype = {
         if (!canAccessInspectedGlobalObject)
             return this._fallbackWrapper(table);
 
+        // FIXME: Currently columns are ignored. Instead, the frontend filters all
+        // properties based on the provided column names and in the provided order.
+        // Should we filter here too?
+
         var columnNames = null;
         if (typeof columns === "string")
             columns = [columns];
index 60997ad..815d93f 100644 (file)
@@ -1,3 +1,19 @@
+2015-02-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: console.table with columnName filter for non-existent property should still show column
+        https://bugs.webkit.org/show_bug.cgi?id=141066
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Views/ConsoleMessageImpl.js:
+        (WebInspector.ConsoleMessageImpl.prototype._appendPropertyPreviews):
+        (WebInspector.ConsoleMessageImpl.prototype._userProvidedColumnNames):
+        (WebInspector.ConsoleMessageImpl.prototype._formatParameterAsTable):
+        If a second argument was provided to console.table, try to extract a list
+        of string names to use for the object properties. Output a table with
+        the provided column names, in the specified order. Also, use this
+        opportunity to mark missing properties with an em dash.
+
 2015-02-02  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: CSS Autocompletion: Autodetect many color supporting properties
index aa33b04..c350572 100644 (file)
@@ -372,7 +372,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
 
             if (i > 0)
                 element.appendChild(document.createTextNode(", "));
-    
+
             if (!isArray || property.name != i) {
                 element.createChild("span", "name").textContent = property.name;
                 element.appendChild(document.createTextNode(": "));
@@ -447,6 +447,31 @@ WebInspector.ConsoleMessageImpl.prototype = {
         arr.getOwnProperties(this._printArray.bind(this, arr, elem));
     },
 
+    _userProvidedColumnNames: function(columnNamesArgument)
+    {
+        if (!columnNamesArgument)
+            return null;
+
+        var remoteObject = WebInspector.RemoteObject.fromPayload(columnNamesArgument);
+
+        // Single primitive argument.
+        if (remoteObject.type === "string" || remoteObject.type === "number")
+            return [String(columnNamesArgument.value)];
+
+        // Ignore everything that is not an array with property previews.
+        if (remoteObject.type !== "object" || remoteObject.subtype !== "array" || !remoteObject.preview || !remoteObject.preview.properties)
+            return null;
+
+        // Array. Look into the preview and get string values.
+        var extractedColumnNames = [];
+        for (var propertyPreview of remoteObject.preview.properties) {
+            if (propertyPreview.type === "string" || propertyPreview.type === "number")
+                extractedColumnNames.push(String(propertyPreview.value));
+        }
+
+        return extractedColumnNames.length ? extractedColumnNames : null;
+    },
+
     _formatParameterAsTable: function(parameters)
     {
         var element = document.createElement("span");
@@ -458,6 +483,14 @@ WebInspector.ConsoleMessageImpl.prototype = {
         var columnNames = [];
         var flatValues = [];
         var preview = table.preview;
+        var userProvidedColumnNames = false;
+
+        // User provided columnNames.
+        var extractedColumnNames = this._userProvidedColumnNames(parameters[1]);
+        if (extractedColumnNames) {
+            userProvidedColumnNames = true;
+            columnNames = extractedColumnNames;
+        }
 
         // Check first for valuePreviews in the properties meaning this was an array of objects.
         for (var i = 0; i < preview.properties.length; ++i) {
@@ -472,7 +505,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
                 var cellProperty = rowPreview.properties[j];
                 var columnRendered = columnNames.contains(cellProperty.name);
                 if (!columnRendered) {
-                    if (columnNames.length === maxColumnsToRender)
+                    if (userProvidedColumnNames || columnNames.length === maxColumnsToRender)
                         continue;
                     columnRendered = true;
                     columnNames.push(cellProperty.name);
@@ -485,13 +518,19 @@ WebInspector.ConsoleMessageImpl.prototype = {
 
         // If there were valuePreviews, convert to a flat list.
         if (rows.length) {
+            const emDash = "\u2014";
             columnNames.unshift(WebInspector.UIString("(Index)"));
             for (var i = 0; i < rows.length; ++i) {
                 var rowName = rows[i][0];
                 var rowValue = rows[i][1];
                 flatValues.push(rowName);
-                for (var j = 1; j < columnNames.length; ++j)
-                    flatValues.push(rowValue[columnNames[j]]);
+                for (var j = 1; j < columnNames.length; ++j) {
+                    var columnName = columnNames[j];
+                    if (!(columnName in rowValue))
+                        flatValues.push(emDash);
+                    else
+                        flatValues.push(rowValue[columnName]);
+                }
             }
         }