Web Inspector: Scope details sidebar should label objects with constructor names
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Feb 2015 22:10:12 +0000 (22:10 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Feb 2015 22:10:12 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=139449

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-02-16
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::internalConstructorName):
* runtime/Structure.cpp:
(JSC::Structure::toStructureShape):
Share calculatedClassName.

* runtime/JSObject.h:
* runtime/JSObject.cpp:
(JSC::JSObject::calculatedClassName):
Elaborate on a way to get an Object's class name.

LayoutTests:

* inspector/model/remote-object-expected.txt:
* inspector/model/remote-object.html:
Improve the test to include Objects where previously
we would have had poorer class name descriptions.

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

LayoutTests/ChangeLog
LayoutTests/inspector/model/remote-object-expected.txt
LayoutTests/inspector/model/remote-object.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
Source/JavaScriptCore/runtime/JSObject.cpp
Source/JavaScriptCore/runtime/JSObject.h
Source/JavaScriptCore/runtime/Structure.cpp

index 02955ca..d64c622 100644 (file)
@@ -1,3 +1,15 @@
+2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Scope details sidebar should label objects with constructor names
+        https://bugs.webkit.org/show_bug.cgi?id=139449
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/model/remote-object-expected.txt:
+        * inspector/model/remote-object.html:
+        Improve the test to include Objects where previously
+        we would have had poorer class name descriptions.
+
 2015-02-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Update expected result for editing/pasteboard/5761530-1.html after r177774
index 939bab3..1c58939 100644 (file)
@@ -1495,6 +1495,34 @@ EXPRESSION: function Foo() {}; new Foo
 }
 
 -----------------------------------------------------
+EXPRESSION: var Foo2 = function() {}; new Foo2
+{
+  "_type": "object",
+  "_objectId": "<filtered>",
+  "_description": "Foo2",
+  "_preview": {
+    "type": "object",
+    "description": "Foo2",
+    "lossless": true,
+    "properties": []
+  }
+}
+
+-----------------------------------------------------
+EXPRESSION: var namespace = {}; namespace.Foo3 = function() {}; new namespace.Foo3
+{
+  "_type": "object",
+  "_objectId": "<filtered>",
+  "_description": "Foo3",
+  "_preview": {
+    "type": "object",
+    "description": "Foo3",
+    "lossless": true,
+    "properties": []
+  }
+}
+
+-----------------------------------------------------
 EXPRESSION: function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, get x() {return this._x;}}; new Bar
 {
   "_type": "object",
@@ -1524,6 +1552,26 @@ EXPRESSION: function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, g
 }
 
 -----------------------------------------------------
+EXPRESSION: function Bar2() { this._x = 5 }; Bar.prototype = {get x() {return this._x;}}; new Bar2
+{
+  "_type": "object",
+  "_objectId": "<filtered>",
+  "_description": "Bar2",
+  "_preview": {
+    "type": "object",
+    "description": "Bar2",
+    "lossless": true,
+    "properties": [
+      {
+        "name": "_x",
+        "type": "number",
+        "value": "5"
+      }
+    ]
+  }
+}
+
+-----------------------------------------------------
 EXPRESSION: window.loadEvent
 {
   "_type": "object",
index 2ae061a..184569e 100644 (file)
@@ -90,7 +90,10 @@ function test()
         {expression: "({a: 1, b: \"string\", c: /regex/, d: Symbol('sym')})"},
         {expression: "({a:function a(){}, b:function b(){}, get getter(){}, set setter(v){}})"},
         {expression: "function Foo() {}; new Foo"},
+        {expression: "var Foo2 = function() {}; new Foo2"},
+        {expression: "var namespace = {}; namespace.Foo3 = function() {}; new namespace.Foo3"},
         {expression: "function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, get x() {return this._x;}}; new Bar"},
+        {expression: "function Bar2() { this._x = 5 }; Bar.prototype = {get x() {return this._x;}}; new Bar2"},
         {expression: "window.loadEvent"}, // window.loadEvent is set inside of <body onload="..."> below.
         {expression: "new ArrayBuffer(16)"},
         {expression: "new DataView(new ArrayBuffer(16))"},
index a78df2d..d10f553 100644 (file)
@@ -1,3 +1,21 @@
+2015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Scope details sidebar should label objects with constructor names
+        https://bugs.webkit.org/show_bug.cgi?id=139449
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/JSInjectedScriptHost.cpp:
+        (Inspector::JSInjectedScriptHost::internalConstructorName):
+        * runtime/Structure.cpp:
+        (JSC::Structure::toStructureShape):
+        Share calculatedClassName.
+
+        * runtime/JSObject.h:        
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::calculatedClassName):
+        Elaborate on a way to get an Object's class name.
+
 2015-02-16  Filip Pizlo  <fpizlo@apple.com>
 
         DFG SSA should use GetLocal for arguments, and the GetArgument node type should be removed
index 5855b58..2b461c9 100644 (file)
@@ -96,9 +96,8 @@ JSValue JSInjectedScriptHost::internalConstructorName(ExecState* exec)
     if (exec->argumentCount() < 1)
         return jsUndefined();
 
-    JSObject* thisObject = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
-    String result = thisObject->methodTable()->className(thisObject);
-    return jsString(exec, result);
+    JSObject* object = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
+    return jsString(exec, JSObject::calculatedClassName(object));
 }
 
 JSValue JSInjectedScriptHost::isHTMLAllCollection(ExecState* exec)
index 87c1919..dcda13f 100644 (file)
@@ -257,6 +257,44 @@ String JSObject::className(const JSObject* object)
     return info->className;
 }
 
+String JSObject::calculatedClassName(JSObject* object)
+{
+    String prototypeFunctionName;
+    ExecState* exec = object->globalObject()->globalExec();
+    PropertySlot slot(object->structure()->storedPrototype());
+    PropertyName constructor(exec->propertyNames().constructor);
+    if (object->getPropertySlot(exec, constructor, slot)) {
+        if (slot.isValue()) {
+            JSValue constructorValue = slot.getValue(exec, constructor);
+            if (constructorValue.isCell()) {
+                if (JSCell* constructorCell = constructorValue.asCell()) {
+                    if (JSObject* ctorObject = constructorCell->getObject()) {
+                        if (JSFunction* constructorFunction = jsDynamicCast<JSFunction*>(ctorObject))
+                            prototypeFunctionName = constructorFunction->calculatedDisplayName(exec);
+                        else if (InternalFunction* constructorFunction = jsDynamicCast<InternalFunction*>(ctorObject))
+                            prototypeFunctionName = constructorFunction->calculatedDisplayName(exec);
+                    }
+                }
+            }
+        }
+    }
+
+    if (prototypeFunctionName.isNull() || prototypeFunctionName == "Object") {
+        String tableClassName = object->methodTable()->className(object);
+        if (!tableClassName.isNull() && tableClassName != "Object")
+            return tableClassName;
+
+        String classInfoName = object->classInfo()->className;
+        if (!classInfoName.isNull())
+            return classInfoName;
+
+        if (prototypeFunctionName.isNull())
+            return ASCIILiteral("Object");
+    }
+
+    return prototypeFunctionName;
+}
+
 bool JSObject::getOwnPropertySlotByIndex(JSObject* thisObject, ExecState* exec, unsigned i, PropertySlot& slot)
 {
     // NB. The fact that we're directly consulting our indexed storage implies that it is not
index c972139..5f02b3e 100644 (file)
@@ -100,6 +100,7 @@ public:
     JS_EXPORT_PRIVATE static void copyBackingStore(JSCell*, CopyVisitor&, CopyToken);
 
     JS_EXPORT_PRIVATE static String className(const JSObject*);
+    JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
 
     JSValue prototype() const;
     JS_EXPORT_PRIVATE void setPrototype(VM&, JSValue prototype);
index 3fcb426..c769051 100644 (file)
@@ -1059,32 +1059,10 @@ PassRefPtr<StructureShape> Structure::toStructureShape(JSValue value)
                 curShape->addProperty(structure->m_nameInPrevious.get());
         }
 
-        bool foundCtorName = false;
-        if (JSObject* profilingVal = curValue.getObject()) {
-            ExecState* exec = profilingVal->globalObject()->globalExec();
-            PropertySlot slot(storedPrototype());
-            PropertyName constructor(exec->propertyNames().constructor);
-            if (profilingVal->getPropertySlot(exec, constructor, slot)) {
-                if (slot.isValue()) {
-                    JSValue constructorValue = slot.getValue(exec, constructor);
-                    if (constructorValue.isCell()) {
-                        if (JSCell* constructorCell = constructorValue.asCell()) {
-                            if (JSObject* ctorObject = constructorCell->getObject()) {
-                                if (JSFunction* constructorFunction = jsDynamicCast<JSFunction*>(ctorObject)) {
-                                    curShape->setConstructorName(constructorFunction->calculatedDisplayName(exec));
-                                    foundCtorName = true;
-                                } else if (InternalFunction* constructorFunction = jsDynamicCast<InternalFunction*>(ctorObject)) {
-                                    curShape->setConstructorName(constructorFunction->calculatedDisplayName(exec));
-                                    foundCtorName = true;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-
-        if (!foundCtorName)
+        
+        if (JSObject* curObject = curValue.getObject())
+            curShape->setConstructorName(JSObject::calculatedClassName(curObject));
+        else
             curShape->setConstructorName(curStructure->classInfo()->className);
 
         if (curStructure->isDictionary())