Changeset 37712 in webkit
- Timestamp:
- Oct 19, 2008 10:58:02 PM (15 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/APICast.h
r37705 r37712 71 71 inline JSValueRef toRef(JSC::JSValuePtr v) 72 72 { 73 return reinterpret_cast<JSValueRef>(v );73 return reinterpret_cast<JSValueRef>(v.payload()); 74 74 } 75 75 76 76 inline JSValueRef* toRef(JSC::JSValuePtr* v) 77 77 { 78 return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v ));78 return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v->payloadPtr())); 79 79 } 80 80 -
trunk/JavaScriptCore/ChangeLog
r37706 r37712 1 2008-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 1 52 2008-10-19 Darin Adler <darin@apple.com> 2 53 -
trunk/JavaScriptCore/JavaScriptCore.exp
r37684 r37712 103 103 __ZN3JSC11Interpreter21shouldPrintExceptionsEv 104 104 __ZN3JSC11Interpreter24setShouldPrintExceptionsEb 105 __ZN3JSC11Interpreter8evaluateEPNS_9ExecStateERNS_10ScopeChainERKNS_10SourceCodeE PNS_7JSValueE105 __ZN3JSC11Interpreter8evaluateEPNS_9ExecStateERNS_10ScopeChainERKNS_10SourceCodeENS_10JSValuePtrE 106 106 __ZN3JSC11JSImmediate12nonInlineNaNEv 107 __ZN3JSC11JSImmediate8toObjectE PNS_7JSValueEPNS_9ExecStateE108 __ZN3JSC11JSImmediate8toStringE PNS_7JSValueE109 __ZN3JSC11JSImmediate9prototypeE PNS_7JSValueEPNS_9ExecStateE107 __ZN3JSC11JSImmediate8toObjectENS_10JSValuePtrEPNS_9ExecStateE 108 __ZN3JSC11JSImmediate8toStringENS_10JSValuePtrE 109 __ZN3JSC11JSImmediate9prototypeENS_10JSValuePtrEPNS_9ExecStateE 110 110 __ZN3JSC11ProfileNode4sortEPFbRKN3WTF6RefPtrIS0_EES5_E 111 111 __ZN3JSC11ProgramNode6createEPNS_12JSGlobalDataEPNS_14SourceElementsEPN3WTF6VectorISt4pairINS_10IdentifierEjELm16EEEPNS6_INS5_6RefPtrINS_12FuncDeclNodeEEELm16EEERKNS_10SourceCodeEji … … 116 116 __ZN3JSC11StructureID21clearEnumerationCacheEv 117 117 __ZN3JSC11StructureID24fromDictionaryTransitionEPS0_ 118 __ZN3JSC11StructureID25changePrototypeTransitionEPS0_ PNS_7JSValueE118 __ZN3JSC11StructureID25changePrototypeTransitionEPS0_NS_10JSValuePtrE 119 119 __ZN3JSC11StructureID27growPropertyStorageCapacityEv 120 __ZN3JSC11StructureIDC1E PNS_7JSValueERKNS_8TypeInfoE120 __ZN3JSC11StructureIDC1ENS_10JSValuePtrERKNS_8TypeInfoE 121 121 __ZN3JSC11StructureIDD1Ev 122 122 __ZN3JSC12DateInstance4infoE … … 134 134 __ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE 135 135 __ZN3JSC12StringObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 136 __ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueERNS_15PutPropertySlotE136 __ZN3JSC12StringObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE 137 137 __ZN3JSC12StringObject4infoE 138 138 __ZN3JSC12StringObjectC2EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEERKNS_7UStringE … … 146 146 __ZN3JSC14JSGlobalObject14setTimeoutTimeEj 147 147 __ZN3JSC14JSGlobalObject16stopTimeoutCheckEv 148 __ZN3JSC14JSGlobalObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueEj148 __ZN3JSC14JSGlobalObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrEj 149 149 __ZN3JSC14JSGlobalObject17startTimeoutCheckEv 150 150 __ZN3JSC14JSGlobalObject29markCrossHeapDependentObjectsEv 151 __ZN3JSC14JSGlobalObject3putEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueERNS_15PutPropertySlotE151 __ZN3JSC14JSGlobalObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE 152 152 __ZN3JSC14JSGlobalObject4initEPNS_8JSObjectE 153 153 __ZN3JSC14JSGlobalObject4markEv … … 166 166 __ZN3JSC16ParserRefCounted5derefEv 167 167 __ZN3JSC17PropertyNameArray3addEPNS_7UString3RepE 168 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEEiRKNS_10IdentifierEPF PNS_7JSValueES2_PNS_8JSObjectESB_RKNS_7ArgListEE169 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEiRKNS_10IdentifierEPF PNS_7JSValueES2_PNS_8JSObjectES7_RKNS_7ArgListEE168 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEN3WTF10PassRefPtrINS_11StructureIDEEEiRKNS_10IdentifierEPFNS_10JSValuePtrES2_PNS_8JSObjectESA_RKNS_7ArgListEE 169 __ZN3JSC17PrototypeFunctionC1EPNS_9ExecStateEiRKNS_10IdentifierEPFNS_10JSValuePtrES2_PNS_8JSObjectES6_RKNS_7ArgListEE 170 170 __ZN3JSC17constructFunctionEPNS_9ExecStateERKNS_7ArgListERKNS_10IdentifierERKNS_7UStringEi 171 171 __ZN3JSC19constructEmptyArrayEPNS_9ExecStateE 172 172 __ZN3JSC19initializeThreadingEv 173 173 __ZN3JSC20constructEmptyObjectEPNS_9ExecStateE 174 __ZN3JSC23objectProtoFuncToStringEPNS_9ExecStateEPNS_8JSObjectE PNS_7JSValueERKNS_7ArgListE174 __ZN3JSC23objectProtoFuncToStringEPNS_9ExecStateEPNS_8JSObjectENS_10JSValuePtrERKNS_7ArgListE 175 175 __ZN3JSC23setUpStaticFunctionSlotEPNS_9ExecStateEPKNS_9HashEntryEPNS_8JSObjectERKNS_10IdentifierERNS_12PropertySlotE 176 176 __ZN3JSC4Heap14allocateNumberEm … … 183 183 __ZN3JSC4Heap25protectedObjectTypeCountsEv 184 184 __ZN3JSC4Heap26protectedGlobalObjectCountEv 185 __ZN3JSC4Heap4heapE PNS_7JSValueE185 __ZN3JSC4Heap4heapENS_10JSValuePtrE 186 186 __ZN3JSC4Heap4sizeEv 187 187 __ZN3JSC4Heap7collectEv 188 __ZN3JSC4Heap7protectE PNS_7JSValueE188 __ZN3JSC4Heap7protectENS_10JSValuePtrE 189 189 __ZN3JSC4Heap8allocateEm 190 __ZN3JSC4Heap9unprotectE PNS_7JSValueE191 __ZN3JSC4callEPNS_9ExecStateE PNS_7JSValueENS_8CallTypeERKNS_8CallDataES3_RKNS_7ArgListE190 __ZN3JSC4Heap9unprotectENS_10JSValuePtrE 191 __ZN3JSC4callEPNS_9ExecStateENS_10JSValuePtrENS_8CallTypeERKNS_8CallDataES2_RKNS_7ArgListE 192 192 __ZN3JSC5equalEPKNS_7UString3RepES3_ 193 193 __ZN3JSC6JSCell11getCallDataERNS_8CallDataE … … 199 199 __ZN3JSC6JSCell18getOwnPropertySlotEPNS_9ExecStateERKNS_10IdentifierERNS_12PropertySlotE 200 200 __ZN3JSC6JSCell18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 201 __ZN3JSC6JSCell3putEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueERNS_15PutPropertySlotE202 __ZN3JSC6JSCell3putEPNS_9ExecStateEj PNS_7JSValueE201 __ZN3JSC6JSCell3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE 202 __ZN3JSC6JSCell3putEPNS_9ExecStateEjNS_10JSValuePtrE 203 203 __ZN3JSC6JSCell9getObjectEv 204 204 __ZN3JSC6JSCellnwEmPNS_9ExecStateE … … 212 212 __ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE 213 213 __ZN3JSC6strtodEPKcPPc 214 __ZN3JSC7ArgList10slowAppendE PNS_7JSValueE214 __ZN3JSC7ArgList10slowAppendENS_10JSValuePtrE 215 215 __ZN3JSC7CStringD1Ev 216 216 __ZN3JSC7CStringaSERKS0_ … … 234 234 __ZN3JSC8DebuggerC2Ev 235 235 __ZN3JSC8DebuggerD2Ev 236 __ZN3JSC8JSObject11hasInstanceEPNS_9ExecStateE PNS_7JSValueES4_236 __ZN3JSC8JSObject11hasInstanceEPNS_9ExecStateENS_10JSValuePtrES3_ 237 237 __ZN3JSC8JSObject12defineGetterEPNS_9ExecStateERKNS_10IdentifierEPS0_ 238 238 __ZN3JSC8JSObject12defineSetterEPNS_9ExecStateERKNS_10IdentifierEPS0_ … … 244 244 __ZN3JSC8JSObject17createInheritorIDEv 245 245 __ZN3JSC8JSObject17putDirectFunctionEPNS_9ExecStateEPNS_16InternalFunctionEj 246 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueEj247 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateEj PNS_7JSValueEj246 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrEj 247 __ZN3JSC8JSObject17putWithAttributesEPNS_9ExecStateEjNS_10JSValuePtrEj 248 248 __ZN3JSC8JSObject18getOwnPropertySlotEPNS_9ExecStateEjRNS_12PropertySlotE 249 __ZN3JSC8JSObject18getPrimitiveNumberEPNS_9ExecStateERdR PNS_7JSValueE250 __ZN3JSC8JSObject22fillGetterPropertySlotERNS_12PropertySlotEP PNS_7JSValueE249 __ZN3JSC8JSObject18getPrimitiveNumberEPNS_9ExecStateERdRNS_10JSValuePtrE 250 __ZN3JSC8JSObject22fillGetterPropertySlotERNS_12PropertySlotEPNS_10JSValuePtrE 251 251 __ZN3JSC8JSObject23allocatePropertyStorageEmm 252 __ZN3JSC8JSObject3putEPNS_9ExecStateERKNS_10IdentifierE PNS_7JSValueERNS_15PutPropertySlotE253 __ZN3JSC8JSObject3putEPNS_9ExecStateEj PNS_7JSValueE252 __ZN3JSC8JSObject3putEPNS_9ExecStateERKNS_10IdentifierENS_10JSValuePtrERNS_15PutPropertySlotE 253 __ZN3JSC8JSObject3putEPNS_9ExecStateEjNS_10JSValuePtrE 254 254 __ZN3JSC8JSObject4markEv 255 255 __ZN3JSC8Profiler13stopProfilingEPNS_9ExecStateERKNS_7UStringE … … 259 259 __ZN3JSC9CodeBlockD1Ev 260 260 __ZN3JSC9CodeBlockD2Ev 261 __ZN3JSC9constructEPNS_9ExecStateE PNS_7JSValueENS_13ConstructTypeERKNS_13ConstructDataERKNS_7ArgListE261 __ZN3JSC9constructEPNS_9ExecStateENS_10JSValuePtrENS_13ConstructTypeERKNS_13ConstructDataERKNS_7ArgListE 262 262 __ZN3JSCeqERKNS_7UStringEPKc 263 263 __ZN3JSCgtERKNS_7UStringES2_ … … 310 310 __ZNK3JSC17DebuggerCallFrame12functionNameEv 311 311 __ZNK3JSC17DebuggerCallFrame4typeEv 312 __ZNK3JSC17DebuggerCallFrame8evaluateERKNS_7UStringER PNS_7JSValueE312 __ZNK3JSC17DebuggerCallFrame8evaluateERKNS_7UStringERNS_10JSValuePtrE 313 313 __ZNK3JSC4Node8toStringEv 314 314 __ZNK3JSC6JSCell12toThisObjectEPNS_9ExecStateE … … 328 328 __ZNK3JSC7JSValue9toIntegerEPNS_9ExecStateE 329 329 __ZNK3JSC7Machine14retrieveCallerEPNS_9ExecStateEPNS_16InternalFunctionE 330 __ZNK3JSC7Machine18retrieveLastCallerEPNS_9ExecStateERiRlRNS_7UStringER PNS_7JSValueE330 __ZNK3JSC7Machine18retrieveLastCallerEPNS_9ExecStateERiRlRNS_7UStringERNS_10JSValuePtrE 331 331 __ZNK3JSC7UString10UTF8StringEb 332 332 __ZNK3JSC7UString14toStrictUInt32EPb -
trunk/JavaScriptCore/VM/CTI.cpp
r37705 r37712 180 180 inline uintptr_t CTI::asInteger(JSValuePtr value) 181 181 { 182 return reinterpret_cast<uintptr_t>(value );182 return reinterpret_cast<uintptr_t>(value.payload()); 183 183 } 184 184 -
trunk/JavaScriptCore/VM/CodeGenerator.cpp
r37684 r37712 620 620 RegisterID* CodeGenerator::addConstant(JSValuePtr v) 621 621 { 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); 623 623 if (result.second) { 624 624 RegisterID& constant = m_calleeRegisters[m_nextConstant]; … … 806 806 } 807 807 808 RegisterID* CodeGenerator::emitLoad(RegisterID* dst, JSCell* cell) 809 { 810 JSValuePtr value = cell; 811 return emitLoad(dst, value); 812 } 813 808 814 RegisterID* CodeGenerator::emitUnexpectedLoad(RegisterID* dst, bool b) 809 815 { -
trunk/JavaScriptCore/VM/CodeGenerator.h
r37684 r37712 230 230 RegisterID* emitLoad(RegisterID* dst, const Identifier&); 231 231 RegisterID* emitLoad(RegisterID* dst, JSValuePtr); 232 RegisterID* emitLoad(RegisterID* dst, JSCell*); 232 233 RegisterID* emitUnexpectedLoad(RegisterID* dst, bool); 233 234 RegisterID* emitUnexpectedLoad(RegisterID* dst, double); … … 330 331 PassRefPtr<LabelID> emitComplexJumpScopes(LabelID* target, ControlFlowContext* topScope, ControlFlowContext* bottomScope); 331 332 332 struct JSValueHashTraits : HashTraits<JSValue Ptr> {333 static void constructDeletedValue(JSValue Ptr& slot) { slot = JSImmediate::impossibleValue(); }334 static bool isDeletedValue(JSValue Ptr 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(); } 335 336 }; 336 337 337 typedef HashMap<JSValue Ptr, unsigned, PtrHash<JSValuePtr>, JSValueHashTraits> JSValueMap;338 typedef HashMap<JSValue*, unsigned, PtrHash<JSValue*>, JSValueHashTraits> JSValueMap; 338 339 339 340 struct IdentifierMapIndexHashTraits { … … 399 400 RegisterID* addConstant(JSValuePtr); 400 401 unsigned addUnexpectedConstant(JSValuePtr); 401 unsigned addRegExp(RegExp* r);402 unsigned addRegExp(RegExp*); 402 403 StructureID* addStructureID(); 403 404 -
trunk/JavaScriptCore/VM/Register.h
r37684 r37712 51 51 Register(); 52 52 Register(JSValuePtr); 53 Register(JSCell*); 53 54 54 55 JSValuePtr jsValue(CallFrame*) const; … … 90 91 intptr_t i; 91 92 void* v; 92 JSValue Ptrvalue;93 JSValue* value; 93 94 94 95 JSActivation* activation; … … 143 144 { 144 145 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(); 146 153 } 147 154 -
trunk/JavaScriptCore/kjs/JSCell.h
r37684 r37712 111 111 { 112 112 ASSERT(!JSImmediate::isImmediate(value)); 113 return static_cast<JSCell*>(value );113 return static_cast<JSCell*>(value.payload()); 114 114 } 115 115 … … 156 156 { 157 157 ASSERT(!JSImmediate::isImmediate(asValue())); 158 return reinterpret_cast<JSCell*>(const_cast<JSValue Ptr>(this));158 return reinterpret_cast<JSCell*>(const_cast<JSValue*>(this)); 159 159 } 160 160 … … 166 166 return globalData->heap.allocate(size); 167 167 #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 { 168 175 } 169 176 -
trunk/JavaScriptCore/kjs/JSImmediate.h
r37684 r37712 35 35 36 36 class ExecState; 37 class JSCell; 37 38 class JSObject; 38 39 class JSValue; 39 40 class UString; 40 41 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(); } 45 65 46 66 /* … … 262 282 static ALWAYS_INLINE JSValuePtr makeValue(uintptr_t integer) 263 283 { 264 return reinterpret_cast<JSValue Ptr>(integer);284 return reinterpret_cast<JSValue*>(integer); 265 285 } 266 286 … … 302 322 static ALWAYS_INLINE uintptr_t rawValue(JSValuePtr v) 303 323 { 304 return reinterpret_cast<uintptr_t>(v );324 return reinterpret_cast<uintptr_t>(v.payload()); 305 325 } 306 326 -
trunk/JavaScriptCore/kjs/JSValue.h
r37706 r37712 151 151 }; 152 152 153 bool operator==(JSValuePtr, JSValuePtr); 154 bool operator!=(JSValuePtr, JSValuePtr); 155 153 156 // These are identical logic to the JSValue functions above, and faster than jsNumber(number)->toInt32(). 154 157 int32_t toInt32(double); … … 167 170 inline JSValuePtr JSValue::asValue() const 168 171 { 169 return const_cast<JSValue Ptr>(this);172 return const_cast<JSValue*>(this); 170 173 } 171 174 … … 261 264 } 262 265 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 263 276 } // namespace JSC 264 277 -
trunk/JavaScriptCore/kjs/PropertySlot.h
r37684 r37712 45 45 } 46 46 47 explicit PropertySlot( const JSValue*base)48 : m_slotBase( const_cast<JSValuePtr>(base))47 explicit PropertySlot(JSValuePtr base) 48 : m_slotBase(base) 49 49 , m_offset(WTF::notFound) 50 50 { -
trunk/JavaScriptCore/kjs/protect.h
r37706 r37712 23 23 #define protect_h 24 24 25 #include "JS Value.h"25 #include "JSCell.h" 26 26 #include "collector.h" 27 27 28 28 namespace JSC { 29 29 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) 45 41 { 46 42 if (val) … … 48 44 } 49 45 50 inline void gcUnprotectNullTolerant(JS ValuePtrval)46 inline void gcUnprotectNullTolerant(JSCell* val) 51 47 { 52 48 if (val) … … 54 50 } 55 51 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 56 80 // FIXME: Share more code with RefPtr template? The only differences are the ref/deref operation 57 81 // and the implicit conversion to raw pointer … … 66 90 67 91 T* get() const { return m_ptr; } 92 operator JSValuePtr() const { return m_ptr; } 68 93 operator T*() const { return m_ptr; } 69 94 T* operator->() const { return m_ptr; } … … 80 105 template <> class ProtectedPtr<JSValuePtr> { 81 106 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; } 88 115 operator JSValuePtr() const { return m_ptr; } 116 operator JSValue*() const { return m_ptr; } 89 117 JSValue* operator->() const { return m_ptr; } 90 118 91 119 bool operator!() const { return !m_ptr; } 120 121 ProtectedPtr& operator=(JSValuePtr); 122 ProtectedPtr& operator=(const ProtectedPtr&); 92 123 93 124 private: 94 ProtectedPtr<JSValue>m_ptr;125 JSValue* m_ptr; 95 126 }; 96 127 … … 98 129 : m_ptr(ptr) 99 130 { 100 if (ptr) 101 gcProtect(ptr); 131 gcProtectNullTolerant(m_ptr); 102 132 } 103 133 … … 105 135 : m_ptr(o.get()) 106 136 { 107 if (T* ptr = m_ptr) 108 gcProtect(ptr); 137 gcProtectNullTolerant(m_ptr); 109 138 } 110 139 111 140 template <class T> ProtectedPtr<T>::~ProtectedPtr() 112 141 { 113 if (T* ptr = m_ptr) 114 gcUnprotect(ptr); 142 gcUnprotectNullTolerant(m_ptr); 115 143 } 116 144 … … 118 146 : m_ptr(o.get()) 119 147 { 120 if (T* ptr = m_ptr) 121 gcProtect(ptr); 148 gcProtectNullTolerant(m_ptr); 122 149 } 123 150 … … 128 155 gcUnprotectNullTolerant(m_ptr); 129 156 m_ptr = optr; 130 157 return *this; 131 158 } 132 159 … … 136 163 gcUnprotectNullTolerant(m_ptr); 137 164 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(); 138 199 return *this; 139 200 }
Note: See TracChangeset
for help on using the changeset viewer.