Changeset 95167 in webkit


Ignore:
Timestamp:
Sep 14, 2011 10:15:16 PM (13 years ago)
Author:
mhahnenberg@apple.com
Message:

Make JSCell::toBoolean non-virtual
https://bugs.webkit.org/show_bug.cgi?id=67727

Reviewed by Sam Weinig.

JSCell::toBoolean now manually performs the toBoolean check for objects and strings (where
before it was simply virtual and would crash if its implementation was called).
Its descendants in JSObject and JSString have also been made non-virtual. JSCell now
explicitly covers all cases of toBoolean, so having a virtual implementation of
JSCell::toBoolean is no longer necessary. This is part of a larger process of un-virtualizing JSCell.

  • JavaScriptCore.exp:
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
  • runtime/JSCell.cpp:
  • runtime/JSCell.h:
  • runtime/JSNotAnObject.cpp:
  • runtime/JSNotAnObject.h:
  • runtime/JSObject.h:
  • runtime/JSString.h:

(JSC::JSCell::toBoolean):
(JSC::JSValue::toBoolean):

  • runtime/StringObjectThatMasqueradesAsUndefined.h:
Location:
trunk/Source/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r95163 r95167  
     12011-09-14  Mark Hahnenberg  <mhahnenberg@apple.com>
     2
     3        Make JSCell::toBoolean non-virtual
     4        https://bugs.webkit.org/show_bug.cgi?id=67727
     5
     6        Reviewed by Sam Weinig.
     7
     8        JSCell::toBoolean now manually performs the toBoolean check for objects and strings (where
     9        before it was simply virtual and would crash if its implementation was called).
     10        Its descendants in JSObject and JSString have also been made non-virtual.  JSCell now
     11        explicitly covers all cases of toBoolean, so having a virtual implementation of
     12        JSCell::toBoolean is no longer necessary.  This is part of a larger process of un-virtualizing JSCell.
     13
     14        * JavaScriptCore.exp:
     15        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
     16        * runtime/JSCell.cpp:
     17        * runtime/JSCell.h:
     18        * runtime/JSNotAnObject.cpp:
     19        * runtime/JSNotAnObject.h:
     20        * runtime/JSObject.h:
     21        * runtime/JSString.h:
     22        (JSC::JSCell::toBoolean):
     23        (JSC::JSValue::toBoolean):
     24        * runtime/StringObjectThatMasqueradesAsUndefined.h:
     25
    1262011-09-14  Alexis Menard  <alexis.menard@openbossa.org>
    227
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r94981 r95167  
    564564__ZNK3JSC6JSCell9getStringEPNS_9ExecStateE
    565565__ZNK3JSC6JSCell9getStringEPNS_9ExecStateERNS_7UStringE
    566 __ZNK3JSC6JSCell9toBooleanEPNS_9ExecStateE
    567566__ZNK3JSC7ArgList8getSliceEiRS0_
    568567__ZNK3JSC7JSArray12subclassDataEv
     
    586585__ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE
    587586__ZNK3JSC8JSString11resolveRopeEPNS_9ExecStateE
     587__ZNK3JSC8JSString9toBooleanEPNS_9ExecStateE
    588588__ZNK3JSC9HashTable11createTableEPNS_12JSGlobalDataE
    589589__ZNK3JSC9HashTable11deleteTableEv
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r94981 r95167  
    348348    ?tlsKeyCount@WTF@@YAAAJXZ
    349349    ?tlsKeys@WTF@@YAPAKXZ
    350     ?toBoolean@JSCell@JSC@@UBE_NPAVExecState@2@@Z
    351     ?toBoolean@JSObject@JSC@@UBE_NPAVExecState@2@@Z
    352     ?toBoolean@JSString@JSC@@EBE_NPAVExecState@2@@Z
    353350    ?toInt32@JSC@@YAHN@Z
    354351    ?toInteger@JSValue@JSC@@QBENPAVExecState@2@@Z
  • trunk/Source/JavaScriptCore/runtime/JSCell.cpp

    r94930 r95167  
    130130}
    131131
    132 bool JSCell::toBoolean(ExecState*) const
    133 {
    134     ASSERT_NOT_REACHED();
    135     return false;
    136 }
    137 
    138132double JSCell::toNumber(ExecState*) const
    139133{
  • trunk/Source/JavaScriptCore/runtime/JSCell.h

    r94932 r95167  
    106106        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    107107        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
    108         virtual bool toBoolean(ExecState*) const;
     108        bool toBoolean(ExecState*) const;
    109109        virtual double toNumber(ExecState*) const;
    110110        virtual UString toString(ExecState*) const;
     
    317317    }
    318318
    319     inline bool JSValue::toBoolean(ExecState* exec) const
    320     {
    321         if (isInt32())
    322             return asInt32() != 0;
    323         if (isDouble())
    324             return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
    325         if (isCell())
    326             return asCell()->toBoolean(exec);
    327         return isTrue(); // false, null, and undefined all convert to false.
    328     }
    329 
    330319    ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const
    331320    {
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.cpp

    r88587 r95167  
    4545
    4646bool JSNotAnObject::getPrimitiveNumber(ExecState* exec, double&, JSValue&)
    47 {
    48     ASSERT_UNUSED(exec, exec->hadException());
    49     return false;
    50 }
    51 
    52 bool JSNotAnObject::toBoolean(ExecState* exec) const
    5347{
    5448    ASSERT_UNUSED(exec, exec->hadException());
  • trunk/Source/JavaScriptCore/runtime/JSNotAnObject.h

    r94929 r95167  
    6666        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    6767        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
    68         virtual bool toBoolean(ExecState*) const;
    6968        virtual double toNumber(ExecState*) const;
    7069        virtual UString toString(ExecState*) const;
  • trunk/Source/JavaScriptCore/runtime/JSObject.h

    r95115 r95167  
    135135        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
    136136        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    137         virtual bool toBoolean(ExecState*) const;
     137        bool toBoolean(ExecState*) const;
    138138        virtual double toNumber(ExecState*) const;
    139139        virtual UString toString(ExecState*) const;
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r94929 r95167  
    6363    public:
    6464        friend class JIT;
     65        friend class JSCell;
    6566        friend class JSGlobalData;
     67        friend class JSValue;
    6668        friend class SpecializedThunkJIT;
    6769        friend struct ThunkHelpers;
     
    495497        virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
    496498        virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
    497         virtual bool toBoolean(ExecState*) const;
     499        bool toBoolean(ExecState*) const;
    498500        virtual double toNumber(ExecState*) const;
    499501        virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
     
    681683    inline bool isJSString(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
    682684
     685    inline bool JSCell::toBoolean(ExecState* exec) const
     686    {
     687        if (isString())
     688            return static_cast<const JSString*>(this)->toBoolean(exec);
     689        return !structure()->typeInfo().masqueradesAsUndefined();
     690    }
     691
    683692    // --- JSValue inlines ----------------------------
     693   
     694    inline bool JSValue::toBoolean(ExecState* exec) const
     695    {
     696        if (isInt32())
     697            return asInt32();
     698        if (isDouble())
     699            return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
     700        if (isCell())
     701            return asCell()->toBoolean(exec);
     702        return isTrue(); // false, null, and undefined all convert to false.
     703    }
    684704
    685705    inline UString JSValue::toString(ExecState* exec) const
  • trunk/Source/JavaScriptCore/runtime/StringObjectThatMasqueradesAsUndefined.h

    r95108 r95167  
    5454
    5555        static const unsigned StructureFlags = OverridesGetOwnPropertySlot | MasqueradesAsUndefined | OverridesGetPropertyNames | StringObject::StructureFlags;
    56 
    57         virtual bool toBoolean(ExecState*) const { return false; }
    5856    };
    5957 
Note: See TracChangeset for help on using the changeset viewer.