Ignore:
Timestamp:
Feb 16, 2015, 2:10:12 PM (10 years ago)
Author:
[email protected]
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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.