Web Inspector: Create Separate Model and View Objects for RemoteObjects / ObjectPrevi...
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ConsoleMessageImpl.js
index e58f31c..e3a0ae9 100644 (file)
@@ -247,7 +247,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
                 span.textContent = parameters[i].description;
                 formattedResult.appendChild(span);
             } else
-                formattedResult.appendChild(this._formatParameter(parameters[i], false, true));
+                formattedResult.appendChild(this._formatParameter(parameters[i], false));
 
             if (i < parameters.length - 1 && !this._isExpandable(parameters[i]))
                 formattedResult.appendChild(document.createTextNode(" "));
@@ -266,7 +266,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
         return remoteObject.hasChildren;
     },
 
-    _formatParameter: function(output, forceObjectFormat, includePreview)
+    _formatParameter: function(output, forceObjectFormat)
     {
         var type;
         if (forceObjectFormat)
@@ -288,7 +288,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
         if (this._isExpandable(output))
             span.classList.add("expandable");
 
-        formatter.call(this, output, span, includePreview);
+        formatter.call(this, output, span, forceObjectFormat);
         return span;
     },
 
@@ -297,123 +297,21 @@ WebInspector.ConsoleMessageImpl.prototype = {
         elem.appendChild(document.createTextNode(val));
     },
 
-    _formatParameterAsObject: function(obj, elem, includePreview)
+    _formatParameterAsObject: function(obj, elem, forceExpansion)
     {
-        var titleElement = document.createElement("span");
-        if (includePreview && obj.preview) {
-            titleElement.classList.add("console-object-preview");
-
-            // COMPATIBILITY (iOS 8): iOS 7 and 8 did not have type/subtype/description on
-            // Runtime.ObjectPreview. Copy them over from the RemoteObject.
-            var preview = obj.preview;
-            if (!preview.type) {
-                preview.type = obj.type;
-                preview.subtype = obj.subtype;
-                preview.description = obj.description;
-            }
-
-            var lossless = this._appendPreview(titleElement, preview);
-            if (lossless) {
-                titleElement.classList.add("console-object-preview-lossless");
-                elem.appendChild(titleElement);
-                return;
-            }
-        } else
-            titleElement.appendChild(document.createTextNode(obj.description || ""));
-
-        var section = new WebInspector.ObjectPropertiesSection(obj, titleElement);
-        elem.appendChild(section.element);
-    },
-
-    _appendPreview: function(element, preview)
-    {
-        if (preview.type === "object" && preview.subtype !== "null" && preview.subtype !== "array") {
-            var previewObjectNameElement = document.createElement("span");
-            previewObjectNameElement.classList.add("console-object-preview-name");
-            if (preview.description === "Object")
-                previewObjectNameElement.classList.add("console-object-preview-name-Object");
-
-            previewObjectNameElement.textContent = preview.description + " ";
-            element.appendChild(previewObjectNameElement);
-        }
-
-        var bodyElement = element.createChild("span", "console-object-preview-body");
-        if (preview.entries)
-            return this._appendEntryPreviews(bodyElement, preview);
-        if (preview.properties)
-            return this._appendPropertyPreviews(bodyElement, preview);
-        return this._appendValuePreview(bodyElement, preview);
-    },
-
-    _appendEntryPreviews: function(element, preview)
-    {
-        var lossless = preview.lossless && !preview.properties.length;
-
-        element.appendChild(document.createTextNode("{"));
-
-        for (var i = 0; i < preview.entries.length; ++i) {
-            if (i > 0)
-                element.appendChild(document.createTextNode(", "));
-
-            var entry = preview.entries[i];
-            if (entry.key) {
-                this._appendPreview(element, entry.key);
-                element.appendChild(document.createTextNode(" => "));
-            }
-
-            this._appendPreview(element, entry.value);
-        }
-
-        if (preview.overflow)
-            element.createChild("span").textContent = "\u2026";
-        element.appendChild(document.createTextNode("}"));
-
-        return lossless;
-    },
-
-    _appendPropertyPreviews: function(element, preview)
-    {
-        var isArray = preview.subtype === "array";
-
-        element.appendChild(document.createTextNode(isArray ? "[" : "{"));
-
-        for (var i = 0; i < preview.properties.length; ++i) {
-            var property = preview.properties[i];
-
-            // FIXME: Better handle getter/setter accessors. Should we show getters in previews?
-            if (property.type === "accessor")
-                continue;
-
-            // Constructor name is often already visible, so don't show it as a property.
-            if (property.name === "constructor")
-                continue;
-
-            if (i > 0)
-                element.appendChild(document.createTextNode(", "));
-
-            if (!isArray || property.name != i) {
-                element.createChild("span", "name").textContent = property.name;
-                element.appendChild(document.createTextNode(": "));
-            }
-
-            element.appendChild(this._propertyPreviewElement(property));
-        }
-
-        if (preview.overflow)
-            element.createChild("span").textContent = "\u2026";
-
-        element.appendChild(document.createTextNode(isArray ? "]" : "}"));
-
-        return preview.lossless;
+        var objectTree = new WebInspector.ObjectTreeView(obj, WebInspector.ObjectTreeView.Mode.Properties, forceExpansion);
+        elem.appendChild(objectTree.element);
     },
 
     _propertyPreviewElement: function(property)
     {
+        // FIXME: Used by console.table. We should be able to eliminate this in favor of ObjectPreview.
+
         var span = document.createElement("span");
-        span.classList.add("console-formatted-" + property.type);
+        span.classList.add(WebInspector.ObjectTreeView.classNameForObject(property));
 
         if (property.type === "string") {
-            span.textContent = "\"" + property.value.replace(/\n/g, "\u21B5") + "\"";
+            span.textContent = "\"" + property.value.replace(/\n/g, "\u21B5").replace(/"/g, "\\\"") + "\"";
             return span;
         }
 
@@ -422,22 +320,10 @@ WebInspector.ConsoleMessageImpl.prototype = {
             return span;
         }
 
-        if (property.type === "object") {
-            if (property.subtype === "node")
-                span.classList.add("console-formatted-preview-node");
-            else if (property.subtype === "regexp")
-                span.classList.add("console-formatted-regexp");
-        }
-
         span.textContent = property.value;
         return span;
     },
 
-    _appendValuePreview: function(element, preview)
-    {
-        element.appendChild(document.createTextNode(preview.description));
-    },
-
     _formatParameterAsNode: function(object, elem)
     {
         function printNode(nodeId)
@@ -445,7 +331,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
             if (!nodeId) {
                 // Sometimes DOM is loaded after the sync message is being formatted, so we get no
                 // nodeId here. So we fall back to object formatting here.
-                this._formatParameterAsObject(object, elem, false);
+                this._formatParameterAsObject(object, elem, true);
                 return;
             }
             var treeOutline = new WebInspector.DOMTreeOutline(false, false, true);
@@ -571,7 +457,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
 
         // If lossless or not table data, output the object so full data can be gotten.
         if (!preview.lossless || !flatValues.length) {
-            element.appendChild(this._formatParameter(table, true, false));
+            element.appendChild(this._formatParameter(table, true));
             if (!flatValues.length)
                 return element;
         }
@@ -589,10 +475,10 @@ WebInspector.ConsoleMessageImpl.prototype = {
         var span = document.createElement("span");
         span.className = "console-formatted-string source-code";
         span.appendChild(document.createTextNode("\""));
-        span.appendChild(WebInspector.linkifyStringAsFragment(output.description));
+        span.appendChild(WebInspector.linkifyStringAsFragment(output.description.replace(/"/g, "\\\"")));
         span.appendChild(document.createTextNode("\""));
 
-        elem.classList.remove("console-formatted-string");        
+        elem.classList.remove("console-formatted-string");
         elem.appendChild(span);
     },
 
@@ -644,7 +530,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
     _formatAsArrayEntry: function(output)
     {
         // Prevent infinite expansion of cross-referencing arrays.
-        return this._formatParameter(output, output.subtype && output.subtype === "array", false);
+        return this._formatParameter(output, output.subtype && output.subtype === "array");
     },
 
     _formatWithSubstitutionString: function(parameters, formattedResult)
@@ -653,7 +539,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
 
         function parameterFormatter(force, obj)
         {
-            return this._formatParameter(obj, force, false);
+            return this._formatParameter(obj, force);
         }
 
         function stringFormatter(obj)