1/* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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. 25 */ 26 27/** 28 * @constructor 29 * @extends {WebInspector.SidebarPane} 30 */ 31WebInspector.ScopeChainSidebarPane = function() 32{ 33 WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope Variables")); 34 this._sections = []; 35 this._expandedSections = {}; 36 this._expandedProperties = []; 37} 38 39WebInspector.ScopeChainSidebarPane.prototype = { 40 /** 41 * @param {?WebInspector.DebuggerModel.CallFrame} callFrame 42 */ 43 update: function(callFrame) 44 { 45 this.bodyElement.removeChildren(); 46 47 if (!callFrame) { 48 var infoElement = document.createElement("div"); 49 infoElement.className = "info"; 50 infoElement.textContent = WebInspector.UIString("Not Paused"); 51 this.bodyElement.appendChild(infoElement); 52 return; 53 } 54 55 for (var i = 0; i < this._sections.length; ++i) { 56 var section = this._sections[i]; 57 if (!section.title) 58 continue; 59 if (section.expanded) 60 this._expandedSections[section.title] = true; 61 else 62 delete this._expandedSections[section.title]; 63 } 64 65 this._sections = []; 66 67 var foundLocalScope = false; 68 var scopeChain = callFrame.scopeChain; 69 for (var i = 0; i < scopeChain.length; ++i) { 70 var scope = scopeChain[i]; 71 var title = null; 72 var subtitle = scope.object.description; 73 var emptyPlaceholder = null; 74 var extraProperties = []; 75 var declarativeScope; 76 77 switch (scope.type) { 78 case DebuggerAgent.ScopeType.Local: 79 foundLocalScope = true; 80 title = WebInspector.UIString("Local"); 81 emptyPlaceholder = WebInspector.UIString("No Variables"); 82 subtitle = undefined; 83 var thisObject = callFrame.thisObject(); 84 if (thisObject) 85 extraProperties.push(new WebInspector.RemoteObjectProperty("this", thisObject)); 86 if (i == 0) { 87 var details = callFrame.target().debuggerModel.debuggerPausedDetails(); 88 if (!callFrame.isAsync()) { 89 var exception = details.exception(); 90 if (exception) 91 extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", exception)); 92 } 93 var returnValue = callFrame.returnValue(); 94 if (returnValue) 95 extraProperties.push(new WebInspector.RemoteObjectProperty("<return>", returnValue)); 96 } 97 declarativeScope = true; 98 break; 99 case DebuggerAgent.ScopeType.Closure: 100 title = WebInspector.UIString("Closure"); 101 emptyPlaceholder = WebInspector.UIString("No Variables"); 102 subtitle = undefined; 103 declarativeScope = true; 104 break; 105 case DebuggerAgent.ScopeType.Catch: 106 title = WebInspector.UIString("Catch"); 107 subtitle = undefined; 108 declarativeScope = true; 109 break; 110 case DebuggerAgent.ScopeType.With: 111 title = WebInspector.UIString("With Block"); 112 declarativeScope = false; 113 break; 114 case DebuggerAgent.ScopeType.Global: 115 title = WebInspector.UIString("Global"); 116 declarativeScope = false; 117 break; 118 } 119 120 if (!title || title === subtitle) 121 subtitle = undefined; 122 123 var runtimeModel = callFrame.target().runtimeModel; 124 if (declarativeScope) 125 var scopeObject = runtimeModel.createScopeRemoteObject(scope.object, new WebInspector.ScopeRef(i, callFrame.id, undefined)); 126 else 127 var scopeObject = runtimeModel.createRemoteObject(scope.object); 128 129 var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement); 130 section.editInSelectedCallFrameWhenPaused = true; 131 section.pane = this; 132 133 if (scope.type === DebuggerAgent.ScopeType.Global) 134 section.expanded = false; 135 else if (!foundLocalScope || scope.type === DebuggerAgent.ScopeType.Local || title in this._expandedSections) 136 section.expanded = true; 137 138 this._sections.push(section); 139 this.bodyElement.appendChild(section.element); 140 } 141 }, 142 143 __proto__: WebInspector.SidebarPane.prototype 144} 145 146/** 147 * @constructor 148 * @extends {WebInspector.ObjectPropertyTreeElement} 149 * @param {!WebInspector.RemoteObjectProperty} property 150 */ 151WebInspector.ScopeVariableTreeElement = function(property) 152{ 153 WebInspector.ObjectPropertyTreeElement.call(this, property); 154} 155 156WebInspector.ScopeVariableTreeElement.prototype = { 157 onattach: function() 158 { 159 WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this); 160 if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties) 161 this.expand(); 162 }, 163 164 onexpand: function() 165 { 166 this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true; 167 }, 168 169 oncollapse: function() 170 { 171 delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier]; 172 }, 173 174 get propertyIdentifier() 175 { 176 if ("_propertyIdentifier" in this) 177 return this._propertyIdentifier; 178 var section = this.treeOutline.section; 179 this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath(); 180 return this._propertyIdentifier; 181 }, 182 183 __proto__: WebInspector.ObjectPropertyTreeElement.prototype 184} 185