Title: [180624] trunk/Source/WebInspectorUI
Revision
180624
Author
[email protected]
Date
2015-02-25 07:03:48 -0800 (Wed, 25 Feb 2015)

Log Message

Web Inspector: Improve PropertyPath display strings for getters / values
https://bugs.webkit.org/show_bug.cgi?id=142008

Patch by Joseph Pecoraro <[email protected]> on 2015-02-25
Reviewed by Timothy Hatcher.

* UserInterface/Base/Utilities.js:
(doubleQuotedString):
Helper to double quote a string and escape double quotes with-in it.

* UserInterface/Models/PropertyPath.js:
(WebInspector.PropertyPath.prototype.get reducedPath):
Compute the path eliminating unnecessary __proto__s. Note we don't
property handle the case where a .__proto__.x is override earlier
by a .x, but that case is rare.

(WebInspector.PropertyPath.prototype.displayPath):
Helper for choosing fullPath or reducedPath display strings.

(WebInspector.PropertyPath.prototype.appendPropertyName):
(WebInspector.PropertyPath.prototype.appendGetterPropertyName):
(WebInspector.PropertyPath.prototype.appendSetterPropertyName):
(WebInspector.PropertyPath.prototype.appendPropertyDescriptor):
When appending a descriptor, specify if it is for a getter/setter or value.
For getters / setters the actual function can be directly fetched via
__lookupGetter__/__lookupSetter__. Continue to use the property name for values.

* UserInterface/Views/FormattedValue.js:
(WebInspector.FormattedValue.createElementForTypesAndValue):

* UserInterface/Views/ObjectTreePropertyTreeElement.js:
(WebInspector.ObjectTreePropertyTreeElement.prototype._propertyPathType):
(WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValuePropertyPath):
(WebInspector.ObjectTreePropertyTreeElement.prototype._thisPropertyPath):
(WebInspector.ObjectTreePropertyTreeElement.prototype):

Modified Paths

Diff

Modified: trunk/Source/WebInspectorUI/ChangeLog (180623 => 180624)


--- trunk/Source/WebInspectorUI/ChangeLog	2015-02-25 10:53:57 UTC (rev 180623)
+++ trunk/Source/WebInspectorUI/ChangeLog	2015-02-25 15:03:48 UTC (rev 180624)
@@ -1,3 +1,40 @@
+2015-02-25  Joseph Pecoraro  <[email protected]>
+
+        Web Inspector: Improve PropertyPath display strings for getters / values
+        https://bugs.webkit.org/show_bug.cgi?id=142008
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Base/Utilities.js:
+        (doubleQuotedString):
+        Helper to double quote a string and escape double quotes with-in it.
+
+        * UserInterface/Models/PropertyPath.js:
+        (WebInspector.PropertyPath.prototype.get reducedPath):
+        Compute the path eliminating unnecessary __proto__s. Note we don't
+        property handle the case where a .__proto__.x is override earlier
+        by a .x, but that case is rare.
+
+        (WebInspector.PropertyPath.prototype.displayPath):
+        Helper for choosing fullPath or reducedPath display strings.
+
+        (WebInspector.PropertyPath.prototype.appendPropertyName):
+        (WebInspector.PropertyPath.prototype.appendGetterPropertyName):
+        (WebInspector.PropertyPath.prototype.appendSetterPropertyName):
+        (WebInspector.PropertyPath.prototype.appendPropertyDescriptor):
+        When appending a descriptor, specify if it is for a getter/setter or value.
+        For getters / setters the actual function can be directly fetched via
+        __lookupGetter__/__lookupSetter__. Continue to use the property name for values.
+
+        * UserInterface/Views/FormattedValue.js:
+        (WebInspector.FormattedValue.createElementForTypesAndValue):
+
+        * UserInterface/Views/ObjectTreePropertyTreeElement.js:
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._propertyPathType):
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValuePropertyPath):
+        (WebInspector.ObjectTreePropertyTreeElement.prototype._thisPropertyPath):
+        (WebInspector.ObjectTreePropertyTreeElement.prototype):
+
 2015-02-24  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Eliminate console-formatted-* class names in favor of formatted-*

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (180623 => 180624)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-02-25 10:53:57 UTC (rev 180623)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2015-02-25 15:03:48 UTC (rev 180624)
@@ -1031,6 +1031,11 @@
     return str.endsWith("{\n    [native code]\n}");
 }
 
+function doubleQuotedString(str)
+{
+    return "\"" + str.replace(/"/g, "\\\"") + "\"";
+}
+
 function clamp(min, value, max)
 {
     return Math.min(Math.max(min, value), max);

Modified: trunk/Source/WebInspectorUI/UserInterface/Models/PropertyPath.js (180623 => 180624)


--- trunk/Source/WebInspectorUI/UserInterface/Models/PropertyPath.js	2015-02-25 10:53:57 UTC (rev 180623)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/PropertyPath.js	2015-02-25 15:03:48 UTC (rev 180624)
@@ -50,6 +50,12 @@
     GetterPropertyName: "@getter",
 };
 
+WebInspector.PropertyPath.Type = {
+    Value: "value",
+    Getter: "getter",
+    Setter: "setter",
+};
+
 WebInspector.PropertyPath.prototype = {
     constructor: WebInspector.PropertyPath,
     __proto__: WebInspector.Object.prototype,
@@ -107,6 +113,35 @@
         return components.join("");
     },
 
+    get reducedPath()
+    {
+        // The display path for a value should not include __proto__.
+        // The path for "foo.__proto__.bar.__proto__.x" is better shown as "foo.bar.x".
+        // FIXME: We should keep __proto__ if this property was overridden.
+        var components = [];
+
+        var p = this;
+
+        // Include trailing __proto__s.
+        for (; p && p.isPrototype; p = p.parent)
+            components.push(p.pathComponent);
+
+        // Skip other __proto__s.
+        for (; p && p.pathComponent; p = p.parent) {
+            if (p.isPrototype)
+                continue;
+            components.push(p.pathComponent);
+        }
+
+        components.reverse();
+        return components.join("");        
+    },
+
+    displayPath: function(type)
+    {
+        return type === WebInspector.PropertyPath.Type.Value ? this.reducedPath : this.fullPath;
+    },
+
     isRoot: function()
     {
         return !this._parent;
@@ -131,7 +166,7 @@
     appendPropertyName: function(object, propertyName)
     {
         var isPrototype = propertyName === "__proto__";
-        var component = this._canPropertyNameBeDotAccess(propertyName) ? "." + propertyName : "[\"" + propertyName.replace(/"/, "\\\"") + "\"]";
+        var component = this._canPropertyNameBeDotAccess(propertyName) ? "." + propertyName : "[" + doubleQuotedString(propertyName) + "]";
         return new WebInspector.PropertyPath(object, component, this, isPrototype);
     },
 
@@ -147,6 +182,18 @@
         return new WebInspector.PropertyPath(object, component, this);
     },
 
+    appendGetterPropertyName: function(object, propertyName)
+    {
+        var component = ".__lookupGetter__(" + doubleQuotedString(propertyName) + ")";
+        return new WebInspector.PropertyPath(object, component, this);
+    },
+
+    appendSetterPropertyName: function(object, propertyName)
+    {
+        var component = ".__lookupSetter__(" + doubleQuotedString(propertyName) + ")";
+        return new WebInspector.PropertyPath(object, component, this);
+    },
+
     appendArrayIndex: function(object, indexString)
     {
         var component = "[" + indexString + "]";
@@ -159,11 +206,18 @@
         return new WebInspector.PropertyPath(object, component, this);
     },
 
-    appendPropertyDescriptor: function(object, descriptor)
+    appendPropertyDescriptor: function(object, descriptor, type)
     {
         if (descriptor.isInternalProperty)
             return this.appendInternalPropertyName(object, descriptor.name);
 
+        if (type === WebInspector.PropertyPath.Type.Getter)
+            return this.appendGetterPropertyName(object, descriptor.name);
+        if (type === WebInspector.PropertyPath.Type.Setter)
+            return this.appendSetterPropertyName(object, descriptor.name);
+
+        console.assert(type === WebInspector.PropertyPath.Type.Value);
+
         // FIXME: We don't yet have Symbol descriptors.
 
         if (this._object.subtype === "array" && !isNaN(parseInt(descriptor.name)))

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/FormattedValue.js (180623 => 180624)


--- trunk/Source/WebInspectorUI/UserInterface/Views/FormattedValue.js	2015-02-25 10:53:57 UTC (rev 180623)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/FormattedValue.js	2015-02-25 15:03:48 UTC (rev 180624)
@@ -82,7 +82,7 @@
 
     // String: quoted and replace newlines as nice unicode symbols.
     if (type === "string") {
-        span.textContent = "\"" + displayString.replace(/\n/g, "\u21B5").replace(/"/g, "\\\"") + "\"";
+        span.textContent = doubleQuotedString(displayString.replace(/\n/g, "\u21B5"));
         return span;
     }
 

Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js (180623 => 180624)


--- trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js	2015-02-25 10:53:57 UTC (rev 180623)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js	2015-02-25 15:03:48 UTC (rev 180624)
@@ -101,23 +101,31 @@
         return null;
     },
 
+    _propertyPathType: function()
+    {
+        if (this._getterValue || this._property.hasValue())
+            return WebInspector.PropertyPath.Type.Value;
+        if (this._property.hasGetter())
+            return WebInspector.PropertyPath.Type.Getter;
+        if (this._property.hasSetter())
+            return WebInspector.PropertyPath.Type.Setter;
+        return WebInspector.PropertyPath.Type.Value;
+    },
+
     _resolvedValuePropertyPath: function()
     {
-        // FIXME: We could make a better path here.
-        // If this getter was not overridden, then <this._propertyPath.lastNonPrototypeObject>[<this._property.name>] is a valid path.
-        // However, we cannot easily determine from here if this getter was overridden or not.
         if (this._getterValue)
-            return new WebInspector.PropertyPath(this._getterValue, WebInspector.PropertyPath.SpecialPathComponent.GetterPropertyName);
+            return this._propertyPath.appendPropertyDescriptor(this._getterValue, this._property, WebInspector.PropertyPath.Type.Value);
 
         if (this._property.hasValue())
-            return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property);
+            return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
 
         return null;
     },
 
     _thisPropertyPath: function()
     {
-        return this._propertyPath.appendPropertyDescriptor(null, this._property);
+        return this._propertyPath.appendPropertyDescriptor(null, this._property, this._propertyPathType());
     },
 
     _updateHasChildren: function()
@@ -374,7 +382,7 @@
         if (propertyPath.isFullPathImpossible())
             return WebInspector.UIString("Unable to determine path to property from root");
 
-        return propertyPath.fullPath;
+        return propertyPath.displayPath(this._propertyPathType());
     },
 
     _updateChildren: function()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to