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 if (callFrame.this) 84 extraProperties.push(new WebInspector.RemoteObjectProperty("this", WebInspector.RemoteObject.fromPayload(callFrame.this))); 85 if (i == 0) { 86 var details = WebInspector.debuggerModel.debuggerPausedDetails(); 87 var exception = details.reason === WebInspector.DebuggerModel.BreakReason.Exception ? details.auxData : 0; 88 if (exception) { 89 var exceptionObject = /** @type {!RuntimeAgent.RemoteObject} */ (exception); 90 extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", WebInspector.RemoteObject.fromPayload(exceptionObject))); 91 } 92 if (callFrame.returnValue) 93 extraProperties.push(new WebInspector.RemoteObjectProperty("<return>", WebInspector.RemoteObject.fromPayload(callFrame.returnValue))); 94 } 95 declarativeScope = true; 96 break; 97 case DebuggerAgent.ScopeType.Closure: 98 title = WebInspector.UIString("Closure"); 99 emptyPlaceholder = WebInspector.UIString("No Variables"); 100 subtitle = undefined; 101 declarativeScope = true; 102 break; 103 case DebuggerAgent.ScopeType.Catch: 104 title = WebInspector.UIString("Catch"); 105 subtitle = undefined; 106 declarativeScope = true; 107 break; 108 case DebuggerAgent.ScopeType.With: 109 title = WebInspector.UIString("With Block"); 110 declarativeScope = false; 111 break; 112 case DebuggerAgent.ScopeType.Global: 113 title = WebInspector.UIString("Global"); 114 declarativeScope = false; 115 break; 116 } 117 118 if (!title || title === subtitle) 119 subtitle = undefined; 120 121 var scopeRef = declarativeScope ? new WebInspector.ScopeRef(i, callFrame.id, undefined) : undefined; 122 var scopeObject = WebInspector.ScopeRemoteObject.fromPayload(scope.object, scopeRef); 123 var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement); 124 section.editInSelectedCallFrameWhenPaused = true; 125 section.pane = this; 126 127 if (scope.type === DebuggerAgent.ScopeType.Global) 128 section.expanded = false; 129 else if (!foundLocalScope || scope.type === DebuggerAgent.ScopeType.Local || title in this._expandedSections) 130 section.expanded = true; 131 132 this._sections.push(section); 133 this.bodyElement.appendChild(section.element); 134 } 135 }, 136 137 __proto__: WebInspector.SidebarPane.prototype 138} 139 140/** 141 * @constructor 142 * @extends {WebInspector.ObjectPropertyTreeElement} 143 * @param {!WebInspector.RemoteObjectProperty} property 144 */ 145WebInspector.ScopeVariableTreeElement = function(property) 146{ 147 WebInspector.ObjectPropertyTreeElement.call(this, property); 148} 149 150WebInspector.ScopeVariableTreeElement.prototype = { 151 onattach: function() 152 { 153 WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this); 154 if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties) 155 this.expand(); 156 }, 157 158 onexpand: function() 159 { 160 this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true; 161 }, 162 163 oncollapse: function() 164 { 165 delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier]; 166 }, 167 168 get propertyIdentifier() 169 { 170 if ("_propertyIdentifier" in this) 171 return this._propertyIdentifier; 172 var section = this.treeOutline.section; 173 this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath(); 174 return this._propertyIdentifier; 175 }, 176 177 __proto__: WebInspector.ObjectPropertyTreeElement.prototype 178} 179