Web Inspector: ES6: Show Symbol properties on Objects
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ObjectTreeBaseTreeElement.js
index f40ebf9..7d11825 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ObjectTreeBaseTreeElement = function(representedObject, propertyPath, property)
+WebInspector.ObjectTreeBaseTreeElement = class ObjectTreeBaseTreeElement extends WebInspector.GeneralTreeElement
 {
-    console.assert(representedObject);
-    console.assert(propertyPath instanceof WebInspector.PropertyPath);
-    console.assert(!property || property instanceof WebInspector.PropertyDescriptor);
-
-    this._property = property;
-    this._propertyPath = propertyPath;
+    constructor(representedObject, propertyPath, property)
+    {
+        console.assert(representedObject);
+        console.assert(propertyPath instanceof WebInspector.PropertyPath);
+        console.assert(!property || property instanceof WebInspector.PropertyDescriptor);
 
-    WebInspector.GeneralTreeElement.call(this, null, null, null, representedObject, false);
+        super(null, null, null, representedObject, false);
 
-    this.small = true;
-    this.toggleOnClick = true;
-    this.selectable = false;
-    this.tooltipHandledSeparately = true;
-};
+        this._property = property;
+        this._propertyPath = propertyPath;
 
-WebInspector.ObjectTreeBaseTreeElement.prototype = {
-    constructor: WebInspector.ObjectTreeBaseTreeElement,
-    __proto__: WebInspector.GeneralTreeElement.prototype,
+        this.small = true;
+        this.toggleOnClick = true;
+        this.selectable = false;
+        this.tooltipHandledSeparately = true;
+    }
 
     // Public
 
     get property()
     {
         return this._property;
-    },
+    }
 
     get propertyPath()
     {
         return this._propertyPath;
-    },
+    }
 
     // Protected
 
     oncontextmenu(event)
     {
         this._contextMenuHandler(event);
-    },
+    }
 
     resolvedValue()
     {
@@ -71,7 +69,7 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasValue())
             return this._property.value;
         return null;
-    },
+    }
 
     resolvedValuePropertyPath()
     {
@@ -81,19 +79,19 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasValue())
             return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
         return null;
-    },
+    }
 
     thisPropertyPath()
     {
         console.assert(this._property);
         return this._propertyPath.appendPropertyDescriptor(null, this._property, this.propertyPathType());
-    },
+    }
 
     hadError()
     {
         console.assert(this._property);
         return this._property.wasThrown || this._getterHadError;
-    },
+    }
 
     propertyPathType()
     {
@@ -105,7 +103,7 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasSetter())
             return WebInspector.PropertyPath.Type.Setter;
         return WebInspector.PropertyPath.Type.Value;
-    },
+    }
 
     propertyPathString(propertyPath)
     {
@@ -113,14 +111,20 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
             return WebInspector.UIString("Unable to determine path to property from root");
 
         return propertyPath.displayPath(this.propertyPathType());
-    },
+    }
 
-    createInteractiveGetterElement()
+    createGetterElement(interactive)
     {
         var getterElement = document.createElement("img");
         getterElement.className = "getter";
-        getterElement.title = WebInspector.UIString("Invoke getter");
 
+        if (!interactive) {
+            getterElement.classList.add("disabled");
+            getterElement.title = WebInspector.UIString("Getter");
+            return getterElement;
+        }
+
+        getterElement.title = WebInspector.UIString("Invoke getter");
         getterElement.addEventListener("click", function(event) {
             event.stopPropagation();
             var lastNonPrototypeObject = this._propertyPath.lastNonPrototypeObject;
@@ -134,18 +138,32 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         }.bind(this));
 
         return getterElement;
-    },
+    }
 
-    createReadOnlyIconElement()
+    createSetterElement(interactive)
     {
-        var readOnlyElement = document.createElement("img");
-        readOnlyElement.className = "read-only";
-        readOnlyElement.title = WebInspector.UIString("Read only");
-        return readOnlyElement;
-    },
+        var setterElement = document.createElement("img");
+        setterElement.className = "setter";
+        setterElement.title = WebInspector.UIString("Setter");
+
+        if (!interactive)
+            setterElement.classList.add("disabled");
+
+        return setterElement;
+    }
 
     // Private
 
+    _logSymbolProperty()
+    {
+        var symbol = this._property.symbol;
+        if (!symbol)
+            return;
+
+        var text = WebInspector.UIString("Selected Symbol");
+        WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, symbol);
+    }
+
     _logValue(value)
     {
         var resolvedValue = value || this.resolvedValue();
@@ -160,7 +178,7 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
             WebInspector.quickConsole.prompt.pushHistoryItem(text);
 
         WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, resolvedValue);
-    },
+    }
 
     _contextMenuHandler(event)
     {
@@ -169,6 +187,10 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
             return;
 
         var contextMenu = new WebInspector.ContextMenu(event);
+
+        if (this._property && this._property.symbol)
+            contextMenu.appendItem(WebInspector.UIString("Log Symbol"), this._logSymbolProperty.bind(this));
+
         contextMenu.appendItem(WebInspector.UIString("Log Value"), this._logValue.bind(this));
 
         var propertyPath = this.resolvedValuePropertyPath();
@@ -184,7 +206,7 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
 
         if (!contextMenu.isEmpty())
             contextMenu.show();
-    },
+    }
 
     _appendMenusItemsForObject(contextMenu, resolvedValue)
     {