2 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 WebInspector.ObjectTreeBaseTreeElement = function(representedObject, propertyPath, property)
28 console.assert(representedObject);
29 console.assert(propertyPath instanceof WebInspector.PropertyPath);
30 console.assert(!property || property instanceof WebInspector.PropertyDescriptor);
32 this._property = property;
33 this._propertyPath = propertyPath;
35 WebInspector.GeneralTreeElement.call(this, null, null, null, representedObject, false);
38 this.toggleOnClick = true;
39 this.selectable = false;
40 this.tooltipHandledSeparately = true;
43 WebInspector.ObjectTreeBaseTreeElement.prototype = {
44 constructor: WebInspector.ObjectTreeBaseTreeElement,
45 __proto__: WebInspector.GeneralTreeElement.prototype,
51 return this._property;
56 return this._propertyPath;
63 this._contextMenuHandler(event);
68 console.assert(this._property);
69 if (this._getterValue)
70 return this._getterValue;
71 if (this._property.hasValue())
72 return this._property.value;
76 resolvedValuePropertyPath()
78 console.assert(this._property);
79 if (this._getterValue)
80 return this._propertyPath.appendPropertyDescriptor(this._getterValue, this._property, WebInspector.PropertyPath.Type.Value);
81 if (this._property.hasValue())
82 return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
88 console.assert(this._property);
89 return this._propertyPath.appendPropertyDescriptor(null, this._property, this.propertyPathType());
94 console.assert(this._property);
95 return this._property.wasThrown || this._getterHadError;
100 console.assert(this._property);
101 if (this._getterValue || this._property.hasValue())
102 return WebInspector.PropertyPath.Type.Value;
103 if (this._property.hasGetter())
104 return WebInspector.PropertyPath.Type.Getter;
105 if (this._property.hasSetter())
106 return WebInspector.PropertyPath.Type.Setter;
107 return WebInspector.PropertyPath.Type.Value;
110 propertyPathString(propertyPath)
112 if (propertyPath.isFullPathImpossible())
113 return WebInspector.UIString("Unable to determine path to property from root");
115 return propertyPath.displayPath(this.propertyPathType());
118 createInteractiveGetterElement()
120 var getterElement = document.createElement("img");
121 getterElement.className = "getter";
122 getterElement.title = WebInspector.UIString("Invoke getter");
124 getterElement.addEventListener("click", function(event) {
125 event.stopPropagation();
126 var lastNonPrototypeObject = this._propertyPath.lastNonPrototypeObject;
127 var getterObject = this._property.get;
128 lastNonPrototypeObject.invokeGetter(getterObject, function(error, result, wasThrown) {
129 this._getterHadError = !!(error || wasThrown);
130 this._getterValue = result;
131 if (this.invokedGetter && typeof this.invokedGetter === "function")
132 this.invokedGetter();
136 return getterElement;
139 createReadOnlyIconElement()
141 var readOnlyElement = document.createElement("img");
142 readOnlyElement.className = "read-only";
143 readOnlyElement.title = WebInspector.UIString("Read only");
144 return readOnlyElement;
151 var resolvedValue = value || this.resolvedValue();
155 var propertyPath = this.resolvedValuePropertyPath();
156 var isImpossible = propertyPath.isFullPathImpossible();
157 var text = isImpossible ? WebInspector.UIString("Selected Value") : propertyPath.displayPath(this.propertyPathType());
160 WebInspector.quickConsole.prompt.pushHistoryItem(text);
162 WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, resolvedValue);
165 _contextMenuHandler(event)
167 var resolvedValue = this.resolvedValue();
171 var contextMenu = new WebInspector.ContextMenu(event);
172 contextMenu.appendItem(WebInspector.UIString("Log Value"), this._logValue.bind(this));
174 var propertyPath = this.resolvedValuePropertyPath();
175 if (propertyPath && !propertyPath.isFullPathImpossible()) {
176 contextMenu.appendItem(WebInspector.UIString("Copy Path to Property"), function() {
177 InspectorFrontendHost.copyText(propertyPath.displayPath(WebInspector.PropertyPath.Type.Value));
181 contextMenu.appendSeparator();
183 this._appendMenusItemsForObject(contextMenu, resolvedValue);
185 if (!contextMenu.isEmpty())
189 _appendMenusItemsForObject(contextMenu, resolvedValue)
191 if (resolvedValue.type === "function") {
192 // FIXME: We should better handle bound functions.
193 if (!isFunctionStringNativeCode(resolvedValue.description)) {
194 contextMenu.appendItem(WebInspector.UIString("Jump to Definition"), function() {
195 DebuggerAgent.getFunctionDetails(resolvedValue.objectId, function(error, response) {
199 var location = response.location;
200 var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
204 var sourceCodeLocation = sourceCode.createSourceCodeLocation(location.lineNumber, location.columnNumber || 0);
205 WebInspector.resourceSidebarPanel.showSourceCodeLocation(sourceCodeLocation);
212 if (resolvedValue.subtype === "node") {
213 contextMenu.appendItem(WebInspector.UIString("Reveal in DOM Tree"), function() {
214 resolvedValue.pushNodeToFrontend(function(nodeId) {
215 WebInspector.domTreeManager.inspectElement(nodeId);