ScopeChainSidebarPane.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. * @constructor
  28. * @extends {WebInspector.SidebarPane}
  29. */
  30. WebInspector.ScopeChainSidebarPane = function()
  31. {
  32. WebInspector.SidebarPane.call(this, WebInspector.UIString("Scope Variables"));
  33. this._sections = [];
  34. this._expandedSections = {};
  35. this._expandedProperties = [];
  36. }
  37. WebInspector.ScopeChainSidebarPane.prototype = {
  38. update: function(callFrame)
  39. {
  40. this.bodyElement.removeChildren();
  41. if (!callFrame) {
  42. var infoElement = document.createElement("div");
  43. infoElement.className = "info";
  44. infoElement.textContent = WebInspector.UIString("Not Paused");
  45. this.bodyElement.appendChild(infoElement);
  46. return;
  47. }
  48. for (var i = 0; i < this._sections.length; ++i) {
  49. var section = this._sections[i];
  50. if (!section.title)
  51. continue;
  52. if (section.expanded)
  53. this._expandedSections[section.title] = true;
  54. else
  55. delete this._expandedSections[section.title];
  56. }
  57. this._sections = [];
  58. var foundLocalScope = false;
  59. var scopeChain = callFrame.scopeChain;
  60. for (var i = 0; i < scopeChain.length; ++i) {
  61. var scope = scopeChain[i];
  62. var title = null;
  63. var subtitle = scope.object.description;
  64. var emptyPlaceholder = null;
  65. var extraProperties = null;
  66. var declarativeScope;
  67. switch (scope.type) {
  68. case "local":
  69. foundLocalScope = true;
  70. title = WebInspector.UIString("Local");
  71. emptyPlaceholder = WebInspector.UIString("No Variables");
  72. subtitle = null;
  73. if (callFrame.this)
  74. extraProperties = [ new WebInspector.RemoteObjectProperty("this", WebInspector.RemoteObject.fromPayload(callFrame.this)) ];
  75. if (i == 0) {
  76. var details = WebInspector.debuggerModel.debuggerPausedDetails();
  77. var exception = details.reason === WebInspector.DebuggerModel.BreakReason.Exception ? details.auxData : 0;
  78. if (exception) {
  79. extraProperties = extraProperties || [];
  80. var exceptionObject = /** @type {RuntimeAgent.RemoteObject} */ (exception);
  81. extraProperties.push(new WebInspector.RemoteObjectProperty("<exception>", WebInspector.RemoteObject.fromPayload(exceptionObject)));
  82. }
  83. }
  84. declarativeScope = true;
  85. break;
  86. case "closure":
  87. title = WebInspector.UIString("Closure");
  88. emptyPlaceholder = WebInspector.UIString("No Variables");
  89. subtitle = null;
  90. declarativeScope = true;
  91. break;
  92. case "catch":
  93. title = WebInspector.UIString("Catch");
  94. subtitle = null;
  95. declarativeScope = true;
  96. break;
  97. case "with":
  98. title = WebInspector.UIString("With Block");
  99. declarativeScope = false;
  100. break;
  101. case "global":
  102. title = WebInspector.UIString("Global");
  103. declarativeScope = false;
  104. break;
  105. }
  106. if (!title || title === subtitle)
  107. subtitle = null;
  108. var scopeRef;
  109. if (declarativeScope)
  110. scopeRef = new WebInspector.ScopeRef(i, callFrame.id, undefined);
  111. else
  112. scopeRef = undefined;
  113. var section = new WebInspector.ObjectPropertiesSection(WebInspector.ScopeRemoteObject.fromPayload(scope.object, scopeRef), title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement);
  114. section.editInSelectedCallFrameWhenPaused = true;
  115. section.pane = this;
  116. if (scope.type === "global")
  117. section.expanded = false;
  118. else if (!foundLocalScope || scope.type === "local" || title in this._expandedSections)
  119. section.expanded = true;
  120. this._sections.push(section);
  121. this.bodyElement.appendChild(section.element);
  122. }
  123. },
  124. __proto__: WebInspector.SidebarPane.prototype
  125. }
  126. /**
  127. * @constructor
  128. * @extends {WebInspector.ObjectPropertyTreeElement}
  129. * @param {WebInspector.RemoteObjectProperty} property
  130. */
  131. WebInspector.ScopeVariableTreeElement = function(property)
  132. {
  133. WebInspector.ObjectPropertyTreeElement.call(this, property);
  134. }
  135. WebInspector.ScopeVariableTreeElement.prototype = {
  136. onattach: function()
  137. {
  138. WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  139. if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane._expandedProperties)
  140. this.expand();
  141. },
  142. onexpand: function()
  143. {
  144. this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier] = true;
  145. },
  146. oncollapse: function()
  147. {
  148. delete this.treeOutline.section.pane._expandedProperties[this.propertyIdentifier];
  149. },
  150. get propertyIdentifier()
  151. {
  152. if ("_propertyIdentifier" in this)
  153. return this._propertyIdentifier;
  154. var section = this.treeOutline.section;
  155. this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath();
  156. return this._propertyIdentifier;
  157. },
  158. __proto__: WebInspector.ObjectPropertyTreeElement.prototype
  159. }