Title: [179635] trunk/Source
Revision
179635
Author
commit-qu...@webkit.org
Date
2015-02-04 14:27:19 -0800 (Wed, 04 Feb 2015)

Log Message

Web Inspector: console.table with columnName filter for non-existent property should still show column
https://bugs.webkit.org/show_bug.cgi?id=141066

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

Source/_javascript_Core:

* 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.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (179634 => 179635)


--- trunk/Source/_javascript_Core/ChangeLog	2015-02-04 22:25:02 UTC (rev 179634)
+++ trunk/Source/_javascript_Core/ChangeLog	2015-02-04 22:27:19 UTC (rev 179635)
@@ -1,3 +1,18 @@
+2015-02-04  Joseph Pecoraro  <pecor...@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  <saambara...@gmail.com>
 
         TypeSet can use 1 byte instead of 4 bytes for its m_seenTypes member variable

Modified: trunk/Source/_javascript_Core/inspector/ConsoleMessage.cpp (179634 => 179635)


--- trunk/Source/_javascript_Core/inspector/ConsoleMessage.cpp	2015-02-04 22:25:02 UTC (rev 179634)
+++ trunk/Source/_javascript_Core/inspector/ConsoleMessage.cpp	2015-02-04 22:27:19 UTC (rev 179635)
@@ -208,6 +208,8 @@
                     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);

Modified: trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js (179634 => 179635)


--- trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2015-02-04 22:25:02 UTC (rev 179634)
+++ trunk/Source/_javascript_Core/inspector/InjectedScriptSource.js	2015-02-04 22:27:19 UTC (rev 179635)
@@ -102,6 +102,10 @@
         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];

Modified: trunk/Source/WebInspectorUI/ChangeLog (179634 => 179635)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-02-04 22:25:02 UTC (rev 179634)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-02-04 22:27:19 UTC (rev 179635)
@@ -1,3 +1,19 @@
+2015-02-04  Joseph Pecoraro  <pecor...@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  <pecor...@apple.com>
 
         Web Inspector: CSS Autocompletion: Autodetect many color supporting properties

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js (179634 => 179635)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js	2015-02-04 22:25:02 UTC (rev 179634)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ConsoleMessageImpl.js	2015-02-04 22:27:19 UTC (rev 179635)
@@ -372,7 +372,7 @@
 
             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 @@
         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,7 +483,15 @@
         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) {
             var rowProperty = preview.properties[i];
@@ -472,7 +505,7 @@
                 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 @@
 
         // 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]);
+                }
             }
         }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to