2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 * @extends {WebInspector.SidebarPane}
31 WebInspector.ScopeChainSidebarPane = function()
33 WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope"));
35 /** @type {!Set.<?string>} */
36 this._expandedSections = new Set();
37 /** @type {!Set.<string>} */
38 this._expandedProperties = new Set();
41 WebInspector.ScopeChainSidebarPane._pathSymbol = Symbol("path");
43 WebInspector.ScopeChainSidebarPane.prototype = {
45 * @param {?WebInspector.DebuggerModel.CallFrame} callFrame
47 update: function(callFrame)
49 this.element.removeChildren();
52 var infoElement = createElement("div");
53 infoElement.className = "info";
54 infoElement.textContent = WebInspector.UIString("Not Paused");
55 this.element.appendChild(infoElement);
59 for (var i = 0; i < this._sections.length; ++i) {
60 var section = this._sections[i];
64 this._expandedSections.add(section.title);
66 this._expandedSections.delete(section.title);
71 var foundLocalScope = false;
72 var scopeChain = callFrame.scopeChain();
73 for (var i = 0; i < scopeChain.length; ++i) {
74 var scope = scopeChain[i];
76 var emptyPlaceholder = null;
77 var extraProperties = [];
79 switch (scope.type()) {
80 case DebuggerAgent.ScopeType.Local:
81 foundLocalScope = true;
82 title = WebInspector.UIString("Local");
83 emptyPlaceholder = WebInspector.UIString("No Variables");
84 var thisObject = callFrame.thisObject();
86 extraProperties.push(new WebInspector.RemoteObjectProperty("this", thisObject));
88 var details = callFrame.debuggerModel.debuggerPausedDetails();
89 if (!callFrame.isAsync()) {
90 var exception = details.exception();
92 extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", exception));
94 var returnValue = callFrame.returnValue();
96 extraProperties.push(new WebInspector.RemoteObjectProperty("<return>", returnValue));
99 case DebuggerAgent.ScopeType.Closure:
100 title = WebInspector.UIString("Closure");
101 emptyPlaceholder = WebInspector.UIString("No Variables");
103 case DebuggerAgent.ScopeType.Catch:
104 title = WebInspector.UIString("Catch");
106 case DebuggerAgent.ScopeType.Block:
107 title = WebInspector.UIString("Block");
109 case DebuggerAgent.ScopeType.Script:
110 title = WebInspector.UIString("Script");
112 case DebuggerAgent.ScopeType.With:
113 title = WebInspector.UIString("With Block");
115 case DebuggerAgent.ScopeType.Global:
116 title = WebInspector.UIString("Global");
120 var subtitle = scope.description();
121 if (!title || title === subtitle)
122 subtitle = undefined;
124 var titleElement = createElementWithClass("div");
125 titleElement.createChild("div", "scope-chain-sidebar-pane-section-subtitle").textContent = subtitle;
126 titleElement.createChild("div", "scope-chain-sidebar-pane-section-title").textContent = title;
128 var section = new WebInspector.ObjectPropertiesSection(scope.object(), titleElement, emptyPlaceholder, true, extraProperties);
129 section[WebInspector.ScopeChainSidebarPane._pathSymbol] = title + ":" + (subtitle ? subtitle + ":" : "");
130 section.addEventListener(TreeOutline.Events.ElementAttached, this._elementAttached, this);
131 section.addEventListener(TreeOutline.Events.ElementExpanded, this._elementExpanded, this);
132 section.addEventListener(TreeOutline.Events.ElementCollapsed, this._elementCollapsed, this);
134 if (scope.type() === DebuggerAgent.ScopeType.Global)
135 section.objectTreeElement().collapse();
136 else if (!foundLocalScope || scope.type() === DebuggerAgent.ScopeType.Local || this._expandedSections.has(title))
137 section.objectTreeElement().expand();
139 section.element.classList.add("scope-chain-sidebar-pane-section");
140 this._sections.push(section);
141 this.element.appendChild(section.element);
146 * @param {!WebInspector.Event} event
148 _elementAttached: function(event)
150 var element = /** @type {!WebInspector.ObjectPropertyTreeElement} */ (event.data);
151 if (element.isExpandable() && this._expandedProperties.has(this._propertyPath(element)))
156 * @param {!WebInspector.Event} event
158 _elementExpanded: function(event)
160 var element = /** @type {!WebInspector.ObjectPropertyTreeElement} */ (event.data);
161 this._expandedProperties.add(this._propertyPath(element));
165 * @param {!WebInspector.Event} event
167 _elementCollapsed: function(event)
169 var element = /** @type {!WebInspector.ObjectPropertyTreeElement} */ (event.data);
170 this._expandedProperties.delete(this._propertyPath(element));
174 * @param {!WebInspector.ObjectPropertyTreeElement} treeElement
177 _propertyPath: function(treeElement)
179 return treeElement.treeOutline[WebInspector.ScopeChainSidebarPane._pathSymbol] + WebInspector.ObjectPropertyTreeElement.prototype.propertyPath.call(treeElement);
182 __proto__: WebInspector.SidebarPane.prototype