Adds the "this" object to the Local scope section of the
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 22:30:12 +0000 (22:30 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 May 2008 22:30:12 +0000 (22:30 +0000)
Scope Variables pane.

<rdar://problem/5774773> Web Inspector doesn't show the "this"
object in its variables list (10438)

Reviewed by Oliver Hunt.

* bindings/js/JSJavaScriptCallFrameCustom.cpp:
(WebCore::JSJavaScriptCallFrame::thisObject): Returns the thisObject
of the JavaScriptCallFrame impl. Returns jsNull if the impl is invalid.
* page/JavaScriptCallFrame.cpp:
(WebCore::JavaScriptCallFrame::thisObject): Return the thisValue from
the ExecState. Return 0 if m_exec is null.
* page/JavaScriptCallFrame.h:
* page/JavaScriptCallFrame.idl: Add thisObject.
* page/inspector/ObjectPropertiesSection.js:
(WebInspector.ObjectPropertiesSection): Adds two new arguments.
The ignoreHasOwnProperty tells the section to show all properties,
including inherited ones. And extraProperties is an object of
additional properties to show.
(WebInspector.ObjectPropertiesSection.prototype): Honor the
extraProperties and ignoreHasOwnProperty properties.
* page/inspector/ScopeChainSidebarPane.js:
(WebInspector.ScopeChainSidebarPane.prototype.update): Add a this
property to an extra object that is passed to the ObjectPropertiesSection.
Also pass true for ignoreHasOwnProperty since we want to show all properties.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33534 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp
WebCore/page/JavaScriptCallFrame.cpp
WebCore/page/JavaScriptCallFrame.h
WebCore/page/JavaScriptCallFrame.idl
WebCore/page/inspector/ObjectPropertiesSection.js
WebCore/page/inspector/ScopeChainSidebarPane.js

index e997263..46f6d20 100644 (file)
@@ -1,3 +1,33 @@
+2008-05-16  Timothy Hatcher  <timothy@apple.com>
+
+        Adds the "this" object to the Local scope section of the
+        Scope Variables pane.
+
+        <rdar://problem/5774773> Web Inspector doesn't show the "this"
+        object in its variables list (10438)
+
+        Reviewed by Oliver Hunt.
+
+        * bindings/js/JSJavaScriptCallFrameCustom.cpp:
+        (WebCore::JSJavaScriptCallFrame::thisObject): Returns the thisObject
+        of the JavaScriptCallFrame impl. Returns jsNull if the impl is invalid.
+        * page/JavaScriptCallFrame.cpp:
+        (WebCore::JavaScriptCallFrame::thisObject): Return the thisValue from
+        the ExecState. Return 0 if m_exec is null.
+        * page/JavaScriptCallFrame.h:
+        * page/JavaScriptCallFrame.idl: Add thisObject.
+        * page/inspector/ObjectPropertiesSection.js:
+        (WebInspector.ObjectPropertiesSection): Adds two new arguments.
+        The ignoreHasOwnProperty tells the section to show all properties,
+        including inherited ones. And extraProperties is an object of
+        additional properties to show.
+        (WebInspector.ObjectPropertiesSection.prototype): Honor the
+        extraProperties and ignoreHasOwnProperty properties.
+        * page/inspector/ScopeChainSidebarPane.js:
+        (WebInspector.ScopeChainSidebarPane.prototype.update): Add a this
+        property to an extra object that is passed to the ObjectPropertiesSection.
+        Also pass true for ignoreHasOwnProperty since we want to show all properties.
+
 2008-05-16  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Brady.
index beff3fb..1bf02a3 100644 (file)
@@ -47,6 +47,13 @@ JSValue* JSJavaScriptCallFrame::evaluate(ExecState* exec, const List& args)
     return result;
 }
 
+JSValue* JSJavaScriptCallFrame::thisObject(ExecState* exec) const
+{
+    if (!impl()->isValid() || !impl()->thisObject())
+        return jsNull();
+    return impl()->thisObject();
+}
+
 JSValue* JSJavaScriptCallFrame::scopeChain(ExecState* exec) const
 {
     if (!impl()->isValid())
index 210378b..7a6f9f5 100644 (file)
@@ -61,6 +61,13 @@ String JavaScriptCallFrame::functionName() const
     return String(function->functionName());
 }
 
+JSObject* JavaScriptCallFrame::thisObject() const
+{
+    if (!m_exec)
+        return 0;
+    return m_exec->thisValue();
+}
+
 // Evaluate some JavaScript code in the scope of this frame.
 JSValue* JavaScriptCallFrame::evaluate(const UString& script, JSValue*& exception) const
 {
index 635002b..63c96c5 100644 (file)
@@ -53,6 +53,7 @@ namespace WebCore {
 
         String functionName() const;
         const KJS::ScopeChain& scopeChain() const { return m_exec->scopeChain(); }
+        KJS::JSObject* thisObject() const;
         KJS::JSValue* evaluate(const KJS::UString& script, KJS::JSValue*& exception) const;
 
     private:
index 39f40fa..1f21f7d 100644 (file)
@@ -32,6 +32,7 @@ module inspector {
         readonly attribute long sourceIdentifier;
         readonly attribute long line;
         readonly attribute [CustomGetter] Array scopeChain;
+        readonly attribute [CustomGetter] Object thisObject;
         readonly attribute DOMString functionName;
     };
 
index f99bb26..5736126 100644 (file)
@@ -23,7 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder)
+WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder, ignoreHasOwnProperty, extraProperties)
 {
     if (!title) {
         title = Object.describe(object);
@@ -36,6 +36,8 @@ WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPl
 
     this.emptyPlaceholder = (emptyPlaceholder || WebInspector.UIString("No Properties"));
     this.object = object;
+    this.ignoreHasOwnProperty = ignoreHasOwnProperty;
+    this.extraProperties = extraProperties;
 
     WebInspector.PropertiesSection.call(this, title, subtitle);
 }
@@ -43,12 +45,24 @@ WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPl
 WebInspector.ObjectPropertiesSection.prototype = {
     onpopulate: function()
     {
-        var properties = Object.sortedProperties(this.object);
+        var properties = [];
+        for (var prop in this.object)
+            properties.push(prop);
+        if (this.extraProperties)
+            for (var prop in this.extraProperties)
+                properties.push(prop);
+        properties.sort();
+
         for (var i = 0; i < properties.length; ++i) {
+            var object = this.object;
             var propertyName = properties[i];
-            if (("hasOwnProperty" in this.object && !this.object.hasOwnProperty(propertyName)) || propertyName === "__treeElementIdentifier")
+            if (this.extraProperties && propertyName in this.extraProperties)
+                object = this.extraProperties;
+            if (propertyName === "__treeElementIdentifier")
+                continue;
+            if (!this.ignoreHasOwnProperty && "hasOwnProperty" in object && !object.hasOwnProperty(propertyName))
                 continue;
-            this.propertiesTreeOutline.appendChild(new WebInspector.ObjectPropertyTreeElement(this.object, propertyName));
+            this.propertiesTreeOutline.appendChild(new WebInspector.ObjectPropertyTreeElement(object, propertyName));
         }
 
         if (!this.propertiesTreeOutline.children.length) {
index af828cf..d4f4d56 100644 (file)
@@ -51,11 +51,13 @@ WebInspector.ScopeChainSidebarPane.prototype = {
             var subtitle = Object.describe(scopeObject, true);
             var emptyPlaceholder = null;
             var localScope = false;
+            var extraProperties = null;
 
             if (Object.prototype.toString.call(scopeObject) === "[object Activation]") {
-                if (!foundLocalScope)
+                if (!foundLocalScope) {
+                    extraProperties = { "this": callFrame.thisObject };
                     title = WebInspector.UIString("Local");
-                else
+                else
                     title = WebInspector.UIString("Closure");
                 emptyPlaceholder = WebInspector.UIString("No Variables");
                 subtitle = null;
@@ -73,7 +75,7 @@ WebInspector.ScopeChainSidebarPane.prototype = {
             if (!title || title === subtitle)
                 subtitle = null;
 
-            var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder);
+            var section = new WebInspector.ObjectPropertiesSection(scopeObject, title, subtitle, emptyPlaceholder, true, extraProperties);
             if (!foundLocalScope || localScope)
                 section.expanded = true;