Changeset 95466 in webkit


Ignore:
Timestamp:
Sep 19, 2011 1:32:52 PM (13 years ago)
Author:
mhahnenberg@apple.com
Message:

Remove toPrimitive from JSCell
https://bugs.webkit.org/show_bug.cgi?id=67875

Reviewed by Geoffrey Garen.

Part of the refactoring process to un-virtualize JSCell. We move
all of the implicit functionality provided by the virtual toPrimitive method
in JSCell to be explicit in JSValue::toPrimitive and JSCell:toPrimitive while
also de-virtualizing JSCell::toPrimitive.

  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • runtime/JSCell.cpp:

(JSC::JSCell::toPrimitive):

  • runtime/JSCell.h:

We replace JSNotAnObject::toPrimitive with defaultValue, which it overrides from
JSObject. This pushes the virtual method further down, enabling us to get rid
of the virtual call in JSCell. Eventually we'll probably have to deal with this
again, but we'll cross that bridge when we come to it.

  • runtime/JSNotAnObject.cpp:

(JSC::JSNotAnObject::defaultValue):

  • runtime/JSNotAnObject.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:

(JSC::JSValue::toPrimitive):

Location:
trunk/Source/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r95455 r95466  
     12011-09-19  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Remove toPrimitive from JSCell
     4        https://bugs.webkit.org/show_bug.cgi?id=67875
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Part of the refactoring process to un-virtualize JSCell.  We move
     9        all of the implicit functionality provided by the virtual toPrimitive method
     10        in JSCell to be explicit in JSValue::toPrimitive and JSCell:toPrimitive while
     11        also de-virtualizing JSCell::toPrimitive.
     12
     13        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     14        * runtime/JSCell.cpp:
     15        (JSC::JSCell::toPrimitive):
     16        * runtime/JSCell.h:
     17
     18        We replace JSNotAnObject::toPrimitive with defaultValue, which it overrides from
     19        JSObject.  This pushes the virtual method further down, enabling us to get rid
     20        of the virtual call in JSCell.  Eventually we'll probably have to deal with this
     21        again, but we'll cross that bridge when we come to it.
     22        * runtime/JSNotAnObject.cpp:
     23        (JSC::JSNotAnObject::defaultValue):
     24        * runtime/JSNotAnObject.h:
     25        * runtime/JSObject.h:
     26        * runtime/JSString.h:
     27        (JSC::JSValue::toPrimitive):
     28
    1292011-09-19  Oliver Hunt  <oliver@apple.com>
    230
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r95450 r95466  
    357357    ?toObject@JSObject@JSC@@UBEPAV12@PAVExecState@2@PAVJSGlobalObject@2@@Z
    358358    ?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z
    359     ?toPrimitive@JSCell@JSC@@UBE?AVJSValue@2@PAVExecState@2@W4PreferredPrimitiveType@2@@Z
    360     ?toPrimitive@JSString@JSC@@EBE?AVJSValue@2@PAVExecState@2@W4PreferredPrimitiveType@2@@Z
    361359    ?toStrictThisObject@JSObject@JSC@@UBE?AVJSValue@2@PAVExecState@2@@Z
    362360    ?toString@JSCell@JSC@@UBE?AVUString@2@PAVExecState@2@@Z
  • trunk/Source/JavaScriptCore/runtime/JSCell.cpp

    r95229 r95466  
    3030
    3131namespace JSC {
     32
     33JSValue JSCell::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
     34{
     35    if (isString())
     36        return static_cast<const JSString*>(this)->toPrimitive(exec, preferredType);
     37    return static_cast<const JSObject*>(this)->toPrimitive(exec, preferredType);
     38}
    3239
    3340bool JSCell::getString(ExecState* exec, UString&stringValue) const
     
    118125}
    119126
    120 JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
    121 {
    122     ASSERT_NOT_REACHED();
    123     return JSValue();
    124 }
    125 
    126127bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
    127128{
  • trunk/Source/JavaScriptCore/runtime/JSCell.h

    r95453 r95466  
    103103
    104104        // Basic conversions.
    105         virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
     105        JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    106106        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
    107107        virtual bool toBoolean(ExecState*) const;
     
    284284        }
    285285        return false;
    286     }
    287 
    288     inline JSValue JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
    289     {
    290         return isCell() ? asCell()->toPrimitive(exec, preferredType) : asValue();
    291286    }
    292287
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.cpp

    r95229 r95466  
    3838
    3939// JSValue methods
    40 JSValue JSNotAnObject::toPrimitive(ExecState* exec, PreferredPrimitiveType) const
     40JSValue JSNotAnObject::defaultValue(ExecState* exec, PreferredPrimitiveType) const
    4141{
    4242    ASSERT_UNUSED(exec, exec->hadException());
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.h

    r95229 r95466  
    6464
    6565        // JSValue methods
    66         virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
     66        virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
    6767        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
    6868        virtual bool toBoolean(ExecState*) const;
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r95447 r95466  
    133133        virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties);
    134134
    135         virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
     135        JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
    136136        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    137137        virtual bool toBoolean(ExecState*) const;
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r95229 r95466  
    427427        unsigned length() { return m_length; }
    428428
     429        JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    429430        bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
    430431        bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
     
    493494        }
    494495
    495         virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    496496        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    497497        virtual bool toBoolean(ExecState*) const;
     
    682682
    683683    // --- JSValue inlines ----------------------------
     684
     685    inline JSValue JSValue::toPrimitive(ExecState* exec, PreferredPrimitiveType preferredType) const
     686    {
     687        if (!isCell())
     688            return asValue();
     689        return asCell()->toPrimitive(exec, preferredType);
     690    }
    684691
    685692    inline UString JSValue::toString(ExecState* exec) const
Note: See TracChangeset for help on using the changeset viewer.