1 /* 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 WebInspector.ScopeChainSidebarPane = function() 27 { 28 WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope Variables")); 29 this._sections = []; 30 this._expandedSections = {}; 31 this._expandedProperties = []; 32 } 33 34 WebInspector.ScopeChainSidebarPane.prototype = { 35 update: function(callFrame) 36 { 37 this.bodyElement.removeChildren(); 38 39 if (!callFrame) { 40 var infoElement = document.createElement("div"); 41 infoElement.className = "info"; 42 infoElement.textContent = WebInspector.UIString("Not Paused"); 43 this.bodyElement.appendChild(infoElement); 44 return; 45 } 46 47 for (var i = 0; i < this._sections.length; ++i) { 48 var section = this._sections[i]; 49 if (!section.title) 50 continue; 51 if (section.expanded) 52 this._expandedSections[section.title] = true; 53 else 54 delete this._expandedSections[section.title]; 55 } 56 57 this._sections = []; 58 59 var foundLocalScope = false; 60 var scopeChain = callFrame.scopeChain; 61 for (var i = 0; i < scopeChain.length; ++i) { 62 var scope = scopeChain[i]; 63 var title = null; 64 var subtitle = scope.object.description; 65 var emptyPlaceholder = null; 66 var extraProperties = null; 67 68 switch (scope.type) { 69 case "local": 70 foundLocalScope = true; 71 title = WebInspector.UIString("Local"); 72 emptyPlaceholder = WebInspector.UIString("No Variables"); 73 subtitle = null; 74 if (scope.this) 75 extraProperties = [ new WebInspector.RemoteObjectProperty("this", WebInspector.RemoteObject.fromPayload(scope.this)) ]; 76 break; 77 case "closure": 78 title = WebInspector.UIString("Closure"); 79 emptyPlaceholder = WebInspector.UIString("No Variables"); 80 subtitle = null; 81 break; 82 case "catch": 83 title = WebInspector.UIString("Catch"); 84 break; 85 case "with": 86 title = WebInspector.UIString("With Block"); 87 break; 88 case "global": 89 title = WebInspector.UIString("Global"); 90 break; 91 } 92 93 if (!title || title === subtitle) 94 subtitle = null; 95 96 var section = new WebInspector.ObjectPropertiesSection(WebInspector.RemoteObject.fromPayload(scope.object), title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement); 97 section.editInSelectedCallFrameWhenPaused = true; 98 section.pane = this; 99 100 if (!foundLocalScope || scope.type === "local" || title in this._expandedSections) 101 section.expanded = true; 102 103 this._sections.push(section); 104 this.bodyElement.appendChild(section.element); 105 } 106 } 107 } 108 109 WebInspector.ScopeChainSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype; 110 111 WebInspector.ScopeVariableTreeElement = function(property) 112 { 113 WebInspector.ObjectPropertyTreeElement.call(this, property); 114 } 115 116 WebInspector.ScopeVariableTreeElement.prototype = { 117 onattach: function() 118 { 119 WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this); 120 if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties) 121 this.expand(); 122 }, 123 124 onexpand: function() 125 { 126 this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true; 127 }, 128 129 oncollapse: function() 130 { 131 delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier]; 132 }, 133 134 get propertyIdentifier() 135 { 136 if ("_propertyIdentifier" in this) 137 return this._propertyIdentifier; 138 var section = this.treeOutline.section; 139 this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath; 140 return this._propertyIdentifier; 141 }, 142 143 get propertyPath() 144 { 145 if ("_propertyPath" in this) 146 return this._propertyPath; 147 148 var current = this; 149 var result; 150 151 do { 152 if (result) 153 result = current.property.name + "." + result; 154 else 155 result = current.property.name; 156 current = current.parent; 157 } while (current && !current.root); 158 159 this._propertyPath = result; 160 return result; 161 } 162 } 163 164 WebInspector.ScopeVariableTreeElement.prototype.__proto__ = WebInspector.ObjectPropertyTreeElement.prototype; 165