Web Inspector: ES6: Show Symbol properties on Objects
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Views / ObjectTreeBaseTreeElement.js
index 0e5300e..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: function(event)
+    oncontextmenu(event)
     {
         this._contextMenuHandler(event);
-    },
+    }
 
-    resolvedValue: function()
+    resolvedValue()
     {
         console.assert(this._property);
         if (this._getterValue)
@@ -71,9 +69,9 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasValue())
             return this._property.value;
         return null;
-    },
+    }
 
-    resolvedValuePropertyPath: function()
+    resolvedValuePropertyPath()
     {
         console.assert(this._property);
         if (this._getterValue)
@@ -81,21 +79,21 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasValue())
             return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
         return null;
-    },
+    }
 
-    thisPropertyPath: function()
+    thisPropertyPath()
     {
         console.assert(this._property);
         return this._propertyPath.appendPropertyDescriptor(null, this._property, this.propertyPathType());
-    },
+    }
 
-    hadError: function()
+    hadError()
     {
         console.assert(this._property);
         return this._property.wasThrown || this._getterHadError;
-    },
+    }
 
-    propertyPathType: function()
+    propertyPathType()
     {
         console.assert(this._property);
         if (this._getterValue || this._property.hasValue())
@@ -105,22 +103,28 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         if (this._property.hasSetter())
             return WebInspector.PropertyPath.Type.Setter;
         return WebInspector.PropertyPath.Type.Value;
-    },
+    }
 
-    propertyPathString: function(propertyPath)
+    propertyPathString(propertyPath)
     {
         if (propertyPath.isFullPathImpossible())
             return WebInspector.UIString("Unable to determine path to property from root");
 
         return propertyPath.displayPath(this.propertyPathType());
-    },
+    }
 
-    createInteractiveGetterElement: function()
+    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,19 +138,33 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
         }.bind(this));
 
         return getterElement;
-    },
+    }
 
-    createReadOnlyIconElement: function()
+    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
 
-    _logValue: function(value)
+    _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();
         if (!resolvedValue)
@@ -160,15 +178,19 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
             WebInspector.quickConsole.prompt.pushHistoryItem(text);
 
         WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, resolvedValue);
-    },
+    }
 
-    _contextMenuHandler: function(event)
+    _contextMenuHandler(event)
     {
         var resolvedValue = this.resolvedValue();
         if (!resolvedValue)
             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,9 +206,9 @@ WebInspector.ObjectTreeBaseTreeElement.prototype = {
 
         if (!contextMenu.isEmpty())
             contextMenu.show();
-    },
+    }
 
-    _appendMenusItemsForObject: function(contextMenu, resolvedValue)
+    _appendMenusItemsForObject(contextMenu, resolvedValue)
     {
         if (resolvedValue.type === "function") {
             // FIXME: We should better handle bound functions.