Changeset 180173 in webkit


Ignore:
Timestamp:
Feb 16, 2015 2:10:12 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Scope details sidebar should label objects with constructor names
https://bugs.webkit.org/show_bug.cgi?id=139449

Patch by Joseph Pecoraro <Joseph Pecoraro> 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.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r180172 r180173  
     12015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Scope details sidebar should label objects with constructor names
     4        https://bugs.webkit.org/show_bug.cgi?id=139449
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * inspector/model/remote-object-expected.txt:
     9        * inspector/model/remote-object.html:
     10        Improve the test to include Objects where previously
     11        we would have had poorer class name descriptions.
     12
    1132015-02-16  Myles C. Maxfield  <mmaxfield@apple.com>
    214
  • trunk/LayoutTests/inspector/model/remote-object-expected.txt

    r180113 r180173  
    14961496
    14971497-----------------------------------------------------
     1498EXPRESSION: var Foo2 = function() {}; new Foo2
     1499{
     1500  "_type": "object",
     1501  "_objectId": "<filtered>",
     1502  "_description": "Foo2",
     1503  "_preview": {
     1504    "type": "object",
     1505    "description": "Foo2",
     1506    "lossless": true,
     1507    "properties": []
     1508  }
     1509}
     1510
     1511-----------------------------------------------------
     1512EXPRESSION: var namespace = {}; namespace.Foo3 = function() {}; new namespace.Foo3
     1513{
     1514  "_type": "object",
     1515  "_objectId": "<filtered>",
     1516  "_description": "Foo3",
     1517  "_preview": {
     1518    "type": "object",
     1519    "description": "Foo3",
     1520    "lossless": true,
     1521    "properties": []
     1522  }
     1523}
     1524
     1525-----------------------------------------------------
    14981526EXPRESSION: function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, get x() {return this._x;}}; new Bar
    14991527{
     
    15191547        "name": "x",
    15201548        "type": "accessor"
     1549      }
     1550    ]
     1551  }
     1552}
     1553
     1554-----------------------------------------------------
     1555EXPRESSION: function Bar2() { this._x = 5 }; Bar.prototype = {get x() {return this._x;}}; new Bar2
     1556{
     1557  "_type": "object",
     1558  "_objectId": "<filtered>",
     1559  "_description": "Bar2",
     1560  "_preview": {
     1561    "type": "object",
     1562    "description": "Bar2",
     1563    "lossless": true,
     1564    "properties": [
     1565      {
     1566        "name": "_x",
     1567        "type": "number",
     1568        "value": "5"
    15211569      }
    15221570    ]
  • trunk/LayoutTests/inspector/model/remote-object.html

    r179659 r180173  
    9191        {expression: "({a:function a(){}, b:function b(){}, get getter(){}, set setter(v){}})"},
    9292        {expression: "function Foo() {}; new Foo"},
     93        {expression: "var Foo2 = function() {}; new Foo2"},
     94        {expression: "var namespace = {}; namespace.Foo3 = function() {}; new namespace.Foo3"},
    9395        {expression: "function Bar() { this._x = 5 }; Bar.prototype = {constructor: Bar, get x() {return this._x;}}; new Bar"},
     96        {expression: "function Bar2() { this._x = 5 }; Bar.prototype = {get x() {return this._x;}}; new Bar2"},
    9497        {expression: "window.loadEvent"}, // window.loadEvent is set inside of <body onload="..."> below.
    9598        {expression: "new ArrayBuffer(16)"},
  • trunk/Source/JavaScriptCore/ChangeLog

    r180160 r180173  
     12015-02-16  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Scope details sidebar should label objects with constructor names
     4        https://bugs.webkit.org/show_bug.cgi?id=139449
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        * inspector/JSInjectedScriptHost.cpp:
     9        (Inspector::JSInjectedScriptHost::internalConstructorName):
     10        * runtime/Structure.cpp:
     11        (JSC::Structure::toStructureShape):
     12        Share calculatedClassName.
     13
     14        * runtime/JSObject.h:       
     15        * runtime/JSObject.cpp:
     16        (JSC::JSObject::calculatedClassName):
     17        Elaborate on a way to get an Object's class name.
     18
    1192015-02-16  Filip Pizlo  <fpizlo@apple.com>
    220
  • trunk/Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp

    r179429 r180173  
    9797        return jsUndefined();
    9898
    99     JSObject* thisObject = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
    100     String result = thisObject->methodTable()->className(thisObject);
    101     return jsString(exec, result);
     99    JSObject* object = jsCast<JSObject*>(exec->uncheckedArgument(0).toThis(exec, NotStrictMode));
     100    return jsString(exec, JSObject::calculatedClassName(object));
    102101}
    103102
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r178928 r180173  
    256256    ASSERT(info);
    257257    return info->className;
     258}
     259
     260String JSObject::calculatedClassName(JSObject* object)
     261{
     262    String prototypeFunctionName;
     263    ExecState* exec = object->globalObject()->globalExec();
     264    PropertySlot slot(object->structure()->storedPrototype());
     265    PropertyName constructor(exec->propertyNames().constructor);
     266    if (object->getPropertySlot(exec, constructor, slot)) {
     267        if (slot.isValue()) {
     268            JSValue constructorValue = slot.getValue(exec, constructor);
     269            if (constructorValue.isCell()) {
     270                if (JSCell* constructorCell = constructorValue.asCell()) {
     271                    if (JSObject* ctorObject = constructorCell->getObject()) {
     272                        if (JSFunction* constructorFunction = jsDynamicCast<JSFunction*>(ctorObject))
     273                            prototypeFunctionName = constructorFunction->calculatedDisplayName(exec);
     274                        else if (InternalFunction* constructorFunction = jsDynamicCast<InternalFunction*>(ctorObject))
     275                            prototypeFunctionName = constructorFunction->calculatedDisplayName(exec);
     276                    }
     277                }
     278            }
     279        }
     280    }
     281
     282    if (prototypeFunctionName.isNull() || prototypeFunctionName == "Object") {
     283        String tableClassName = object->methodTable()->className(object);
     284        if (!tableClassName.isNull() && tableClassName != "Object")
     285            return tableClassName;
     286
     287        String classInfoName = object->classInfo()->className;
     288        if (!classInfoName.isNull())
     289            return classInfoName;
     290
     291        if (prototypeFunctionName.isNull())
     292            return ASCIILiteral("Object");
     293    }
     294
     295    return prototypeFunctionName;
    258296}
    259297
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r178928 r180173  
    101101
    102102    JS_EXPORT_PRIVATE static String className(const JSObject*);
     103    JS_EXPORT_PRIVATE static String calculatedClassName(JSObject*);
    103104
    104105    JSValue prototype() const;
  • trunk/Source/JavaScriptCore/runtime/Structure.cpp

    r179429 r180173  
    10601060        }
    10611061
    1062         bool foundCtorName = false;
    1063         if (JSObject* profilingVal = curValue.getObject()) {
    1064             ExecState* exec = profilingVal->globalObject()->globalExec();
    1065             PropertySlot slot(storedPrototype());
    1066             PropertyName constructor(exec->propertyNames().constructor);
    1067             if (profilingVal->getPropertySlot(exec, constructor, slot)) {
    1068                 if (slot.isValue()) {
    1069                     JSValue constructorValue = slot.getValue(exec, constructor);
    1070                     if (constructorValue.isCell()) {
    1071                         if (JSCell* constructorCell = constructorValue.asCell()) {
    1072                             if (JSObject* ctorObject = constructorCell->getObject()) {
    1073                                 if (JSFunction* constructorFunction = jsDynamicCast<JSFunction*>(ctorObject)) {
    1074                                     curShape->setConstructorName(constructorFunction->calculatedDisplayName(exec));
    1075                                     foundCtorName = true;
    1076                                 } else if (InternalFunction* constructorFunction = jsDynamicCast<InternalFunction*>(ctorObject)) {
    1077                                     curShape->setConstructorName(constructorFunction->calculatedDisplayName(exec));
    1078                                     foundCtorName = true;
    1079                                 }
    1080                             }
    1081                         }
    1082                     }
    1083                 }
    1084             }
    1085         }
    1086 
    1087         if (!foundCtorName)
     1062       
     1063        if (JSObject* curObject = curValue.getObject())
     1064            curShape->setConstructorName(JSObject::calculatedClassName(curObject));
     1065        else
    10881066            curShape->setConstructorName(curStructure->classInfo()->className);
    10891067
Note: See TracChangeset for help on using the changeset viewer.