Changeset 37712 in webkit


Ignore:
Timestamp:
Oct 19, 2008 10:58:02 PM (15 years ago)
Author:
Darin Adler
Message:

2008-10-19 Darin Adler <Darin Adler>

Reviewed by Cameron Zwarich.

Change JSValuePtr from a typedef into a class. This allows us to support
conversion from JSCell* to JSValuePtr even if JSCell isn't derived from
JSValue.

  • JavaScriptCore.exp: Updated symbols that involve JSValuePtr, since it's now a distinct type.
  • API/APICast.h: (toRef): Extract the JSValuePtr payload explicitly since we can't just cast any more.
  • VM/CTI.cpp: (JSC::CTI::asInteger): Ditto.
  • VM/CodeGenerator.cpp: (JSC::CodeGenerator::addConstant): Get at the payload directly. (JSC::CodeGenerator::emitLoad): Added an overload of JSCell* because otherwise classes derived from JSValue end up calling the bool overload instead of JSValuePtr.
  • VM/CodeGenerator.h: Ditto. Also update traits to use JSValue* and the payload functions.
  • VM/Register.h: Added a JSCell* overload and use of payload functions.
  • kjs/JSCell.h: (JSC::asCell): Use payload function. (JSC::JSValue::asCell): Use JSValue* instead of JSValuePtr. (JSC::JSValuePtr::JSValuePtr): Added. Constructor that takes JSCell* and creates a JSValuePtr.
  • kjs/JSImmediate.h: Added JSValuePtr class. Also updated makeValue and makeInt to work with JSValue* and the payload function.
  • kjs/JSValue.h: Added == and != operators for JSValuePtr. Put them here because eventually all the JSValue functions should go here except what's needed by JSImmediate. Also fix asValue to use JSValue* instead of JSValuePtr.
  • kjs/PropertySlot.h: Change constructor to take JSValuePtr.
  • kjs/protect.h: Update gcProtect functions to work with JSCell* as well as JSValuePtr. Also updated the ProtectedPtr<JSValuePtr> specialization to work more directly. Also changed all the call sites to use gcProtectNullTolerant.
Location:
trunk/JavaScriptCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/APICast.h

    r37705 r37712  
    7171inline JSValueRef toRef(JSC::JSValuePtr v)
    7272{
    73     return reinterpret_cast<JSValueRef>(v);
     73    return reinterpret_cast<JSValueRef>(v.payload());
    7474}
    7575
    7676inline JSValueRef* toRef(JSC::JSValuePtr* v)
    7777{
    78     return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v));
     78    return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v->payloadPtr()));
    7979}
    8080
  • trunk/JavaScriptCore/ChangeLog

    r37706 r37712  
     12008-10-19  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Cameron Zwarich.
     4
     5        - next step of https://bugs.webkit.org/show_bug.cgi?id=21732
     6          improve performance by eliminating JSValue as a base class for JSCell
     7
     8        Change JSValuePtr from a typedef into a class. This allows us to support
     9        conversion from JSCell* to JSValuePtr even if JSCell isn't derived from
     10        JSValue.
     11
     12        * JavaScriptCore.exp: Updated symbols that involve JSValuePtr, since
     13        it's now a distinct type.
     14
     15        * API/APICast.h:
     16        (toRef): Extract the JSValuePtr payload explicitly since we can't just
     17        cast any more.
     18        * VM/CTI.cpp:
     19        (JSC::CTI::asInteger): Ditto.
     20
     21        * VM/CodeGenerator.cpp:
     22        (JSC::CodeGenerator::addConstant): Get at the payload directly.
     23        (JSC::CodeGenerator::emitLoad): Added an overload of JSCell* because
     24        otherwise classes derived from JSValue end up calling the bool
     25        overload instead of JSValuePtr.
     26        * VM/CodeGenerator.h: Ditto. Also update traits to use JSValue*
     27        and the payload functions.
     28
     29        * VM/Register.h: Added a JSCell* overload and use of payload functions.
     30
     31        * kjs/JSCell.h:
     32        (JSC::asCell): Use payload function.
     33        (JSC::JSValue::asCell): Use JSValue* instead of JSValuePtr.
     34        (JSC::JSValuePtr::JSValuePtr): Added. Constructor that takes JSCell*
     35        and creates a JSValuePtr.
     36
     37        * kjs/JSImmediate.h: Added JSValuePtr class. Also updated makeValue
     38        and makeInt to work with JSValue* and the payload function.
     39
     40        * kjs/JSValue.h: Added == and != operators for JSValuePtr. Put them
     41        here because eventually all the JSValue functions should go here
     42        except what's needed by JSImmediate. Also fix asValue to use
     43        JSValue* instead of JSValuePtr.
     44
     45        * kjs/PropertySlot.h: Change constructor to take JSValuePtr.
     46
     47        * kjs/protect.h: Update gcProtect functions to work with JSCell*
     48        as well as JSValuePtr. Also updated the ProtectedPtr<JSValuePtr>
     49        specialization to work more directly. Also changed all the call
     50        sites to use gcProtectNullTolerant.
     51
    1522008-10-19  Darin Adler  <darin@apple.com>
    253
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r37684 r37712  
    103103__ZN3JSC11Interpreter21shouldPrintExceptionsEv
    104104__ZN3JSC11Interpreter24setShouldPrintExceptionsEb
    105 __ZN3JSC11Interpreter8evaluateEPNS_9ExecStateERNS_10ScopeChainERKNS_10SourceCodeEPNS_7JSValueE
     105__ZN3JSC11Interpreter8evaluateEPNS_9ExecStateERNS_10ScopeChainERKNS_10SourceCodeENS_10JSValuePtrE
    106106__ZN3JSC11JSImmediate12nonInlineNaNEv
    107 __ZN3JSC11JSImmediate8toObjectEPNS_7JSValueEPNS_9ExecStateE
    108 __ZN3JSC11JSImmediate8toStringEPNS_7JSValueE
    109 __ZN3JSC11JSImmediate9prototypeEPNS_7JSValueEPNS_9ExecStateE
     107__ZN3JSC11JSImmediate8toObjectENS_10JSValuePtrEPNS_9ExecStateE
     108__ZN3JSC11JSImmediate8toStringENS_10JSValuePtrE
     109__ZN3JSC11JSImmediate9prototypeENS_10JSValuePtrEPNS_9ExecStateE
    110110__ZN3JSC11ProfileNode4sortEPFbRKN3WTF6RefPtrIS0_EES5_E
    111111__ZN3JSC11ProgramNode6createEPNS_12JSGlobalDataEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS6_INS5_6RefPtrINS_12FuncDeclNodeEEELm16EEERKNS_10SourceCodeEji
     
    116116__ZN3JSC11StructureID21clearEnumerationCacheEv
    117117__ZN3JSC11StructureID24fromDictionaryTransitionEPS0_
    118 __ZN3JSC11StructureID25changePrototypeTransitionEPS0_PNS_7JSValueE
     118__ZN3JSC11StructureID25changePrototypeTransitionEPS0_NS_10JSValuePtrE
    119119__ZN3JSC11StructureID27growPropertyStorageCapacityEv
    120 __ZN3JSC11StructureIDC1EPNS_7JSValueERKNS_8TypeInfoE
     120__ZN3JSC11StructureIDC1ENS_10JSValuePtrERKNS_8TypeInfoE
    121121__ZN3JSC11StructureIDD1Ev
    122122__ZN3JSC12DateInstance4infoE
     
    134134__ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE
    135135__ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
    136 __ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueERNS_15PutPropertySlotE
     136__ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE
    137137__ZN3JSC12StringObject4infoE
    138138__ZN3JSC12StringObjectC2EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEERKNS_7UStringE
     
    146146__ZN3JSC14JSGlobalObject14setTimeoutTimeEj
    147147__ZN3JSC14JSGlobalObject16stopTimeoutCheckEv
    148 __ZN3JSC14JSGlobalObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueEj
     148__ZN3JSC14JSGlobalObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrEj
    149149__ZN3JSC14JSGlobalObject17startTimeoutCheckEv
    150150__ZN3JSC14JSGlobalObject29markCrossHeapDependentObjectsEv
    151 __ZN3JSC14JSGlobalObject3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueERNS_15PutPropertySlotE
     151__ZN3JSC14JSGlobalObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE
    152152__ZN3JSC14JSGlobalObject4initEPNS_8JSObjectE
    153153__ZN3JSC14JSGlobalObject4markEv
     
    166166__ZN3JSC16ParserRefCounted5derefEv
    167167__ZN3JSC17PropertyNameArray3addEPNS_7UString3RepE
    168 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEEiRKNS_10IdentifierEPFPNS_7JSValueES2_PNS_8JSObjectESB_RKNS_7ArgListEE
    169 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEiRKNS_10IdentifierEPFPNS_7JSValueES2_PNS_8JSObjectES7_RKNS_7ArgListEE
     168__ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEEiRKNS_10IdentifierEPFNS_10JSValuePtrES2_PNS_8JSObjectESA_RKNS_7ArgListEE
     169__ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEiRKNS_10IdentifierEPFNS_10JSValuePtrES2_PNS_8JSObjectES6_RKNS_7ArgListEE
    170170__ZN3JSC17constructFunctionEPNS_9ExecStateERKNS_7ArgListERKNS_10IdentifierERKNS_7UStringEi
    171171__ZN3JSC19constructEmptyArrayEPNS_9ExecStateE
    172172__ZN3JSC19initializeThreadingEv
    173173__ZN3JSC20constructEmptyObjectEPNS_9ExecStateE
    174 __ZN3JSC23objectProtoFuncToStringEPNS_9ExecStateEPNS_8JSObjectEPNS_7JSValueERKNS_7ArgListE
     174__ZN3JSC23objectProtoFuncToStringEPNS_9ExecStateEPNS_8JSObjectENS_10JSValuePtrERKNS_7ArgListE
    175175__ZN3JSC23setUpStaticFunctionSlotEPNS_9ExecStateEPKNS_9HashEntryEPNS_8JSObjectERKNS_10IdentifierERNS_12PropertySlotE
    176176__ZN3JSC4Heap14allocateNumberEm
     
    183183__ZN3JSC4Heap25protectedObjectTypeCountsEv
    184184__ZN3JSC4Heap26protectedGlobalObjectCountEv
    185 __ZN3JSC4Heap4heapEPNS_7JSValueE
     185__ZN3JSC4Heap4heapENS_10JSValuePtrE
    186186__ZN3JSC4Heap4sizeEv
    187187__ZN3JSC4Heap7collectEv
    188 __ZN3JSC4Heap7protectEPNS_7JSValueE
     188__ZN3JSC4Heap7protectENS_10JSValuePtrE
    189189__ZN3JSC4Heap8allocateEm
    190 __ZN3JSC4Heap9unprotectEPNS_7JSValueE
    191 __ZN3JSC4callEPNS_9ExecStateEPNS_7JSValueENS_8CallTypeERKNS_8CallDataES3_RKNS_7ArgListE
     190__ZN3JSC4Heap9unprotectENS_10JSValuePtrE
     191__ZN3JSC4callEPNS_9ExecStateENS_10JSValuePtrENS_8CallTypeERKNS_8CallDataES2_RKNS_7ArgListE
    192192__ZN3JSC5equalEPKNS_7UString3RepES3_
    193193__ZN3JSC6JSCell11getCallDataERNS_8CallDataE
     
    199199__ZN3JSC6JSCell18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE
    200200__ZN3JSC6JSCell18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
    201 __ZN3JSC6JSCell3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueERNS_15PutPropertySlotE
    202 __ZN3JSC6JSCell3putEPNS_9ExecStateEjPNS_7JSValueE
     201__ZN3JSC6JSCell3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE
     202__ZN3JSC6JSCell3putEPNS_9ExecStateEjNS_10JSValuePtrE
    203203__ZN3JSC6JSCell9getObjectEv
    204204__ZN3JSC6JSCellnwEmPNS_9ExecStateE
     
    212212__ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE
    213213__ZN3JSC6strtodEPKcPPc
    214 __ZN3JSC7ArgList10slowAppendEPNS_7JSValueE
     214__ZN3JSC7ArgList10slowAppendENS_10JSValuePtrE
    215215__ZN3JSC7CStringD1Ev
    216216__ZN3JSC7CStringaSERKS0_
     
    234234__ZN3JSC8DebuggerC2Ev
    235235__ZN3JSC8DebuggerD2Ev
    236 __ZN3JSC8JSObject11hasInstanceEPNS_9ExecStateEPNS_7JSValueES4_
     236__ZN3JSC8JSObject11hasInstanceEPNS_9ExecStateENS_10JSValuePtrES3_
    237237__ZN3JSC8JSObject12defineGetterEPNS_9ExecStateERKNS_10IdentifierEPS0_
    238238__ZN3JSC8JSObject12defineSetterEPNS_9ExecStateERKNS_10IdentifierEPS0_
     
    244244__ZN3JSC8JSObject17createInheritorIDEv
    245245__ZN3JSC8JSObject17putDirectFunctionEPNS_9ExecStateEPNS_16InternalFunctionEj
    246 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueEj
    247 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateEjPNS_7JSValueEj
     246__ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrEj
     247__ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateEjNS_10JSValuePtrEj
    248248__ZN3JSC8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE
    249 __ZN3JSC8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRPNS_7JSValueE
    250 __ZN3JSC8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPPNS_7JSValueE
     249__ZN3JSC8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRNS_10JSValuePtrE
     250__ZN3JSC8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPNS_10JSValuePtrE
    251251__ZN3JSC8JSObject23allocatePropertyStorageEmm
    252 __ZN3JSC8JSObject3putEPNS_9ExecStateERKNS_10IdentifierEPNS_7JSValueERNS_15PutPropertySlotE
    253 __ZN3JSC8JSObject3putEPNS_9ExecStateEjPNS_7JSValueE
     252__ZN3JSC8JSObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE
     253__ZN3JSC8JSObject3putEPNS_9ExecStateEjNS_10JSValuePtrE
    254254__ZN3JSC8JSObject4markEv
    255255__ZN3JSC8Profiler13stopProfilingEPNS_9ExecStateERKNS_7UStringE
     
    259259__ZN3JSC9CodeBlockD1Ev
    260260__ZN3JSC9CodeBlockD2Ev
    261 __ZN3JSC9constructEPNS_9ExecStateEPNS_7JSValueENS_13ConstructTypeERKNS_13ConstructDataERKNS_7ArgListE
     261__ZN3JSC9constructEPNS_9ExecStateENS_10JSValuePtrENS_13ConstructTypeERKNS_13ConstructDataERKNS_7ArgListE
    262262__ZN3JSCeqERKNS_7UStringEPKc
    263263__ZN3JSCgtERKNS_7UStringES2_
     
    310310__ZNK3JSC17DebuggerCallFrame12functionNameEv
    311311__ZNK3JSC17DebuggerCallFrame4typeEv
    312 __ZNK3JSC17DebuggerCallFrame8evaluateERKNS_7UStringERPNS_7JSValueE
     312__ZNK3JSC17DebuggerCallFrame8evaluateERKNS_7UStringERNS_10JSValuePtrE
    313313__ZNK3JSC4Node8toStringEv
    314314__ZNK3JSC6JSCell12toThisObjectEPNS_9ExecStateE
     
    328328__ZNK3JSC7JSValue9toIntegerEPNS_9ExecStateE
    329329__ZNK3JSC7Machine14retrieveCallerEPNS_9ExecStateEPNS_16InternalFunctionE
    330 __ZNK3JSC7Machine18retrieveLastCallerEPNS_9ExecStateERiRlRNS_7UStringERPNS_7JSValueE
     330__ZNK3JSC7Machine18retrieveLastCallerEPNS_9ExecStateERiRlRNS_7UStringERNS_10JSValuePtrE
    331331__ZNK3JSC7UString10UTF8StringEb
    332332__ZNK3JSC7UString14toStrictUInt32EPb
  • trunk/JavaScriptCore/VM/CTI.cpp

    r37705 r37712  
    180180inline uintptr_t CTI::asInteger(JSValuePtr value)
    181181{
    182     return reinterpret_cast<uintptr_t>(value);
     182    return reinterpret_cast<uintptr_t>(value.payload());
    183183}
    184184
  • trunk/JavaScriptCore/VM/CodeGenerator.cpp

    r37684 r37712  
    620620RegisterID* CodeGenerator::addConstant(JSValuePtr v)
    621621{
    622     pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(v, m_nextConstant);
     622    pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(v.payload(), m_nextConstant);
    623623    if (result.second) {
    624624        RegisterID& constant = m_calleeRegisters[m_nextConstant];
     
    806806}
    807807
     808RegisterID* CodeGenerator::emitLoad(RegisterID* dst, JSCell* cell)
     809{
     810    JSValuePtr value = cell;
     811    return emitLoad(dst, value);
     812}
     813
    808814RegisterID* CodeGenerator::emitUnexpectedLoad(RegisterID* dst, bool b)
    809815{
  • trunk/JavaScriptCore/VM/CodeGenerator.h

    r37684 r37712  
    230230        RegisterID* emitLoad(RegisterID* dst, const Identifier&);
    231231        RegisterID* emitLoad(RegisterID* dst, JSValuePtr);
     232        RegisterID* emitLoad(RegisterID* dst, JSCell*);
    232233        RegisterID* emitUnexpectedLoad(RegisterID* dst, bool);
    233234        RegisterID* emitUnexpectedLoad(RegisterID* dst, double);
     
    330331        PassRefPtr<LabelID> emitComplexJumpScopes(LabelID* target, ControlFlowContext* topScope, ControlFlowContext* bottomScope);
    331332
    332         struct JSValueHashTraits : HashTraits<JSValuePtr> {
    333             static void constructDeletedValue(JSValuePtr& slot) { slot = JSImmediate::impossibleValue(); }
    334             static bool isDeletedValue(JSValuePtr value) { return value == JSImmediate::impossibleValue(); }
     333        struct JSValueHashTraits : HashTraits<JSValue*> {
     334            static void constructDeletedValue(JSValue*& slot) { slot = JSImmediate::impossibleValue().payload(); }
     335            static bool isDeletedValue(JSValue* value) { return value == JSImmediate::impossibleValue().payload(); }
    335336        };
    336337
    337         typedef HashMap<JSValuePtr, unsigned, PtrHash<JSValuePtr>, JSValueHashTraits> JSValueMap;
     338        typedef HashMap<JSValue*, unsigned, PtrHash<JSValue*>, JSValueHashTraits> JSValueMap;
    338339
    339340        struct IdentifierMapIndexHashTraits {
     
    399400        RegisterID* addConstant(JSValuePtr);
    400401        unsigned addUnexpectedConstant(JSValuePtr);
    401         unsigned addRegExp(RegExp* r);
     402        unsigned addRegExp(RegExp*);
    402403        StructureID* addStructureID();
    403404
  • trunk/JavaScriptCore/VM/Register.h

    r37684 r37712  
    5151        Register();
    5252        Register(JSValuePtr);
     53        Register(JSCell*);
    5354
    5455        JSValuePtr jsValue(CallFrame*) const;
     
    9091            intptr_t i;
    9192            void* v;
    92             JSValuePtr value;
     93            JSValue* value;
    9394
    9495            JSActivation* activation;
     
    143144    {
    144145        SET_TYPE(ValueType);
    145         u.value = v;
     146        u.value = v.payload();
     147    }
     148
     149    ALWAYS_INLINE Register::Register(JSCell* v)
     150    {
     151        SET_TYPE(ValueType);
     152        u.value = JSValuePtr(v).payload();
    146153    }
    147154
  • trunk/JavaScriptCore/kjs/JSCell.h

    r37684 r37712  
    111111    {
    112112        ASSERT(!JSImmediate::isImmediate(value));
    113         return static_cast<JSCell*>(value);
     113        return static_cast<JSCell*>(value.payload());
    114114    }
    115115
     
    156156    {
    157157        ASSERT(!JSImmediate::isImmediate(asValue()));
    158         return reinterpret_cast<JSCell*>(const_cast<JSValuePtr>(this));
     158        return reinterpret_cast<JSCell*>(const_cast<JSValue*>(this));
    159159    }
    160160
     
    166166        return globalData->heap.allocate(size);
    167167#endif
     168    }
     169
     170    // --- JSValuePtr inlines ----------------------------
     171
     172    inline JSValuePtr::JSValuePtr(const JSCell* cell)
     173        : m_payload(reinterpret_cast<JSValue*>(const_cast<JSCell*>(cell)))
     174    {
    168175    }
    169176
  • trunk/JavaScriptCore/kjs/JSImmediate.h

    r37684 r37712  
    3535
    3636    class ExecState;
     37    class JSCell;
    3738    class JSObject;
    3839    class JSValue;
    3940    class UString;
    4041
    41     typedef JSValue* JSValuePtr;
    42 
    43     inline JSValuePtr noValue() { return 0; }
    44     inline void* asPointer(JSValuePtr value) { return value; }
     42    class JSValuePtr {
     43    public:
     44        JSValuePtr() { } // uninitialized (not zero)
     45        JSValuePtr(const JSValue* payload) : m_payload(const_cast<JSValue*>(payload)) { }
     46        JSValuePtr(const JSCell*);
     47
     48        JSValue* payload() const { return m_payload; }
     49        JSValue** payloadPtr() { return &m_payload; }
     50
     51        bool operator!() const { return !payload(); }
     52   
     53        // This conversion operator allows implicit conversion to bool but not to other integer types.
     54        typedef JSValue* JSValuePtr::*UnspecifiedBoolType;
     55        operator UnspecifiedBoolType() const { return payload() ? &JSValuePtr::m_payload : 0; }
     56
     57        JSValue* operator->() const { return payload(); }
     58
     59    private:
     60        JSValue* m_payload;
     61    };
     62
     63    inline JSValuePtr noValue() { return static_cast<JSValue*>(0); }
     64    inline void* asPointer(JSValuePtr value) { return value.payload(); }
    4565
    4666    /*
     
    262282        static ALWAYS_INLINE JSValuePtr makeValue(uintptr_t integer)
    263283        {
    264             return reinterpret_cast<JSValuePtr>(integer);
     284            return reinterpret_cast<JSValue*>(integer);
    265285        }
    266286
     
    302322        static ALWAYS_INLINE uintptr_t rawValue(JSValuePtr v)
    303323        {
    304             return reinterpret_cast<uintptr_t>(v);
     324            return reinterpret_cast<uintptr_t>(v.payload());
    305325        }
    306326
  • trunk/JavaScriptCore/kjs/JSValue.h

    r37706 r37712  
    151151    };
    152152
     153    bool operator==(JSValuePtr, JSValuePtr);
     154    bool operator!=(JSValuePtr, JSValuePtr);
     155
    153156    // These are identical logic to the JSValue functions above, and faster than jsNumber(number)->toInt32().
    154157    int32_t toInt32(double);
     
    167170    inline JSValuePtr JSValue::asValue() const
    168171    {
    169         return const_cast<JSValuePtr>(this);
     172        return const_cast<JSValue*>(this);
    170173    }
    171174
     
    261264    }
    262265
     266    inline bool operator==(JSValuePtr a, JSValuePtr b)
     267    {
     268        return a.payload() == b.payload();
     269    }
     270
     271    inline bool operator!=(JSValuePtr a, JSValuePtr b)
     272    {
     273        return a.payload() != b.payload();
     274    }
     275
    263276} // namespace JSC
    264277
  • trunk/JavaScriptCore/kjs/PropertySlot.h

    r37684 r37712  
    4545        }
    4646
    47         explicit PropertySlot(const JSValue* base)
    48             : m_slotBase(const_cast<JSValuePtr>(base))
     47        explicit PropertySlot(JSValuePtr base)
     48            : m_slotBase(base)
    4949            , m_offset(WTF::notFound)
    5050        {
  • trunk/JavaScriptCore/kjs/protect.h

    r37706 r37712  
    2323#define protect_h
    2424
    25 #include "JSValue.h"
     25#include "JSCell.h"
    2626#include "collector.h"
    2727
    2828namespace JSC {
    2929
    30     inline void gcProtect(JSValuePtr val)
    31     {
    32         Heap* heap = Heap::heap(val);
    33         if (heap)
    34             heap->protect(val);
    35     }
    36 
    37     inline void gcUnprotect(JSValuePtr val)
    38     {
    39         Heap* heap = Heap::heap(val);
    40         if (heap)
    41             heap->unprotect(val);
    42     }
    43 
    44     inline void gcProtectNullTolerant(JSValuePtr val)
     30    inline void gcProtect(JSCell* val)
     31    {
     32        Heap::heap(val)->protect(val);
     33    }
     34
     35    inline void gcUnprotect(JSCell* val)
     36    {
     37        Heap::heap(val)->unprotect(val);
     38    }
     39
     40    inline void gcProtectNullTolerant(JSCell* val)
    4541    {
    4642        if (val)
     
    4844    }
    4945
    50     inline void gcUnprotectNullTolerant(JSValuePtr val)
     46    inline void gcUnprotectNullTolerant(JSCell* val)
    5147    {
    5248        if (val)
     
    5450    }
    5551   
     52    inline void gcProtect(JSValuePtr value)
     53    {
     54        if (JSImmediate::isImmediate(value))
     55            return;
     56        gcProtect(asCell(value));
     57    }
     58
     59    inline void gcUnprotect(JSValuePtr value)
     60    {
     61        if (JSImmediate::isImmediate(value))
     62            return;
     63        gcUnprotect(asCell(value));
     64    }
     65
     66    inline void gcProtectNullTolerant(JSValuePtr value)
     67    {
     68        if (!value || JSImmediate::isImmediate(value))
     69            return;
     70        gcProtect(asCell(value));
     71    }
     72
     73    inline void gcUnprotectNullTolerant(JSValuePtr value)
     74    {
     75        if (!value || JSImmediate::isImmediate(value))
     76            return;
     77        gcUnprotect(asCell(value));
     78    }
     79
    5680    // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation
    5781    // and the implicit conversion to raw pointer
     
    6690       
    6791        T* get() const { return m_ptr; }
     92        operator JSValuePtr() const { return m_ptr; }
    6893        operator T*() const { return m_ptr; }
    6994        T* operator->() const { return m_ptr; }
     
    80105    template <> class ProtectedPtr<JSValuePtr> {
    81106    public:
    82         ProtectedPtr() { }
    83         ProtectedPtr(JSValuePtr ptr) : m_ptr(ptr) { }
    84 
    85         template <class U> ProtectedPtr(const ProtectedPtr<U>& ptr) : m_ptr(ptr) { }
    86        
    87         JSValuePtr get() const { return m_ptr; }
     107        ProtectedPtr() : m_ptr(0) { }
     108        ProtectedPtr(JSValuePtr);
     109        ProtectedPtr(const ProtectedPtr&);
     110        ~ProtectedPtr();
     111
     112        template <class U> ProtectedPtr(const ProtectedPtr<U>&);
     113       
     114        JSValue* get() const { return m_ptr; }
    88115        operator JSValuePtr() const { return m_ptr; }
     116        operator JSValue*() const { return m_ptr; }
    89117        JSValue* operator->() const { return m_ptr; }
    90118       
    91119        bool operator!() const { return !m_ptr; }
     120
     121        ProtectedPtr& operator=(JSValuePtr);
     122        ProtectedPtr& operator=(const ProtectedPtr&);
    92123       
    93124    private:
    94         ProtectedPtr<JSValue> m_ptr;
     125        JSValue* m_ptr;
    95126    };
    96127
     
    98129        : m_ptr(ptr)
    99130    {
    100         if (ptr)
    101             gcProtect(ptr);
     131        gcProtectNullTolerant(m_ptr);
    102132    }
    103133
     
    105135        : m_ptr(o.get())
    106136    {
    107         if (T* ptr = m_ptr)
    108             gcProtect(ptr);
     137        gcProtectNullTolerant(m_ptr);
    109138    }
    110139
    111140    template <class T> ProtectedPtr<T>::~ProtectedPtr()
    112141    {
    113         if (T* ptr = m_ptr)
    114             gcUnprotect(ptr);
     142        gcUnprotectNullTolerant(m_ptr);
    115143    }
    116144
     
    118146        : m_ptr(o.get())
    119147    {
    120         if (T* ptr = m_ptr)
    121             gcProtect(ptr);
     148        gcProtectNullTolerant(m_ptr);
    122149    }
    123150
     
    128155        gcUnprotectNullTolerant(m_ptr);
    129156        m_ptr = optr;
    130             return *this;
     157        return *this;
    131158    }
    132159
     
    136163        gcUnprotectNullTolerant(m_ptr);
    137164        m_ptr = optr;
     165        return *this;
     166    }
     167
     168    inline ProtectedPtr<JSValuePtr>::ProtectedPtr(JSValuePtr ptr)
     169        : m_ptr(ptr.payload())
     170    {
     171        gcProtectNullTolerant(m_ptr);
     172    }
     173
     174    inline ProtectedPtr<JSValuePtr>::ProtectedPtr(const ProtectedPtr& o)
     175        : m_ptr(o.m_ptr)
     176    {
     177        gcProtectNullTolerant(m_ptr);
     178    }
     179
     180    inline ProtectedPtr<JSValuePtr>::~ProtectedPtr()
     181    {
     182        gcUnprotectNullTolerant(m_ptr);
     183    }
     184
     185    inline ProtectedPtr<JSValuePtr>& ProtectedPtr<JSValuePtr>::operator=(const ProtectedPtr& o)
     186    {
     187        JSValuePtr optr = o.m_ptr;
     188        gcProtectNullTolerant(optr);
     189        gcUnprotectNullTolerant(m_ptr);
     190        m_ptr = optr.payload();
     191        return *this;
     192    }
     193
     194    inline ProtectedPtr<JSValuePtr>& ProtectedPtr<JSValuePtr>::operator=(JSValuePtr ptr)
     195    {
     196        gcProtectNullTolerant(ptr);
     197        gcUnprotectNullTolerant(m_ptr);
     198        m_ptr = ptr.payload();
    138199        return *this;
    139200    }
Note: See TracChangeset for help on using the changeset viewer.