home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 July / CA07.iso / Multimedija / QuickTimeInstaller.exe / AppleApplicationSupport.msi / WebKit.resources_inspector_ScopeChainSidebarPane.js < prev    next >
Encoding:
Text File  |  2010-03-15  |  6.2 KB  |  157 lines

  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. }
  30.  
  31. WebInspector.ScopeChainSidebarPane.prototype = {
  32.     update: function(callFrame)
  33.     {
  34.         this.bodyElement.removeChildren();
  35.  
  36.         this.sections = [];
  37.         this.callFrame = callFrame;
  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.         if (!callFrame._expandedProperties) {
  48.             // FIXME: fix this when https://bugs.webkit.org/show_bug.cgi?id=19410 is fixed.
  49.             // The callFrame is a JSInspectedObjectWrapper, so we are not allowed to assign
  50.             // an object created in the Inspector's context to that object. So create an
  51.             // Object from the inspectedWindow.
  52.             var inspectedWindow = InspectorController.inspectedWindow();
  53.             callFrame._expandedProperties = new inspectedWindow.Object;
  54.         }
  55.  
  56.         var foundLocalScope = false;
  57.         var scopeChain = callFrame.scopeChain;
  58.         for (var i = 0; i < scopeChain.length; ++i) {
  59.             var scopeObject = scopeChain[i];
  60.             var title = null;
  61.             var subtitle = Object.describe(scopeObject, true);
  62.             var emptyPlaceholder = null;
  63.             var localScope = false;
  64.             var extraProperties = null;
  65.  
  66.             if (Object.prototype.toString.call(scopeObject) === "[object JSActivation]") {
  67.                 if (!foundLocalScope) {
  68.                     extraProperties = { "this": callFrame.thisObject };
  69.                     title = WebInspector.UIString("Local");
  70.                 } else
  71.                     title = WebInspector.UIString("Closure");
  72.                 emptyPlaceholder = WebInspector.UIString("No Variables");
  73.                 subtitle = null;
  74.                 foundLocalScope = true;
  75.                 localScope = true;
  76.             } else if (i === (scopeChain.length - 1))
  77.                 title = WebInspector.UIString("Global");
  78.             else if (foundLocalScope && scopeObject instanceof InspectorController.inspectedWindow().Element)
  79.                 title = WebInspector.UIString("Event Target");
  80.             else if (foundLocalScope && scopeObject instanceof InspectorController.inspectedWindow().Document)
  81.                 title = WebInspector.UIString("Event Document");
  82.             else if (!foundLocalScope && !localScope)
  83.                 title = WebInspector.UIString("With Block");
  84.  
  85.             if (!title || title === subtitle)
  86.                 subtitle = null;
  87.  
  88.             var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties, WebInspector.ScopeVariableTreeElement);
  89.             section.editInSelectedCallFrameWhenPaused = true;
  90.             section.pane = this;
  91.  
  92.             if (!foundLocalScope || localScope)
  93.                 section.expanded = true;
  94.  
  95.             this.sections.push(section);
  96.             this.bodyElement.appendChild(section.element);
  97.         }
  98.     }
  99. }
  100.  
  101. WebInspector.ScopeChainSidebarPane.prototype.__proto__ = WebInspector.SidebarPane.prototype;
  102.  
  103. WebInspector.ScopeVariableTreeElement = function(parentObject, propertyName)
  104. {
  105.     WebInspector.ObjectPropertyTreeElement.call(this, parentObject, propertyName);
  106. }
  107.  
  108. WebInspector.ScopeVariableTreeElement.prototype = {
  109.     onattach: function()
  110.     {
  111.         WebInspector.ObjectPropertyTreeElement.prototype.onattach.call(this);
  112.         if (this.hasChildren && this.propertyIdentifier in this.treeOutline.section.pane.callFrame._expandedProperties)
  113.             this.expand();
  114.     },
  115.  
  116.     onexpand: function()
  117.     {
  118.         this.treeOutline.section.pane.callFrame._expandedProperties[this.propertyIdentifier] = true;
  119.     },
  120.  
  121.     oncollapse: function()
  122.     {
  123.         delete this.treeOutline.section.pane.callFrame._expandedProperties[this.propertyIdentifier];
  124.     },
  125.  
  126.     get propertyIdentifier()
  127.     {
  128.         if ("_propertyIdentifier" in this)
  129.             return this._propertyIdentifier;
  130.         var section = this.treeOutline.section;
  131.         this._propertyIdentifier = section.title + ":" + (section.subtitle ? section.subtitle + ":" : "") + this.propertyPath;
  132.         return this._propertyIdentifier;
  133.     },
  134.  
  135.     get propertyPath()
  136.     {
  137.         if ("_propertyPath" in this)
  138.             return this._propertyPath;
  139.  
  140.         var current = this;
  141.         var result;
  142.  
  143.         do {
  144.             if (result)
  145.                 result = current.propertyName + "." + result;
  146.             else
  147.                 result = current.propertyName;
  148.             current = current.parent;
  149.         } while (current && !current.root);
  150.  
  151.         this._propertyPath = result;
  152.         return result;
  153.     }
  154. }
  155.  
  156. WebInspector.ScopeVariableTreeElement.prototype.__proto__ = WebInspector.ObjectPropertyTreeElement.prototype;
  157.