Changeset 147962 in webkit for trunk/Source/JavaScriptCore/heap/PassWeak.h
- Timestamp:
- Apr 8, 2013, 4:41:02 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/heap/PassWeak.h
r118483 r147962 1 1 /* 2 * Copyright (C) 2012 Apple Inc. All rights reserved.2 * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 35 35 namespace JSC { 36 36 37 template<typename T> class Weak;38 37 template<typename T> class PassWeak; 39 38 template<typename T> PassWeak<T> adoptWeak(WeakImpl*); 40 39 41 template<typename Base, typename T> class WeakImplAccessor{40 template<typename T> class PassWeak { 42 41 public: 43 typedef T* GetType;44 45 T* operator->() const;46 T& operator*() const;47 GetType get() const;48 49 bool was(GetType) const;50 };51 52 template<typename T> class PassWeak : public WeakImplAccessor<PassWeak<T>, T> {53 public:54 friend class WeakImplAccessor<PassWeak<T>, T>;55 typedef typename WeakImplAccessor<PassWeak<T>, T>::GetType GetType;56 57 42 PassWeak(); 58 43 PassWeak(std::nullptr_t); 59 PassWeak( GetType, WeakHandleOwner* = 0, void* context = 0);44 PassWeak(T*, WeakHandleOwner* = 0, void* context = 0); 60 45 61 46 // It somewhat breaks the type system to allow transfer of ownership out of … … 67 52 ~PassWeak(); 68 53 54 T* operator->() const; 55 T& operator*() const; 56 T* get() const; 57 69 58 bool operator!() const; 70 59 71 60 // This conversion operator allows implicit conversion to bool but not to other integer types. 72 typedef JSValue(PassWeak::*UnspecifiedBoolType);61 typedef void* (PassWeak::*UnspecifiedBoolType); 73 62 operator UnspecifiedBoolType*() const; 74 63 … … 82 71 }; 83 72 84 template<typename Base, typename T> inline T* WeakImplAccessor<Base, T>::operator->() const85 {86 ASSERT(static_cast<const Base*>(this)->m_impl && static_cast<const Base*>(this)->m_impl->state() == WeakImpl::Live);87 return jsCast<T*>(static_cast<const Base*>(this)->m_impl->jsValue().asCell());88 }89 90 template<typename Base, typename T> inline T& WeakImplAccessor<Base, T>::operator*() const91 {92 ASSERT(static_cast<const Base*>(this)->m_impl && static_cast<const Base*>(this)->m_impl->state() == WeakImpl::Live);93 return *jsCast<T*>(static_cast<const Base*>(this)->m_impl->jsValue().asCell());94 }95 96 template<typename Base, typename T> inline typename WeakImplAccessor<Base, T>::GetType WeakImplAccessor<Base, T>::get() const97 {98 if (!static_cast<const Base*>(this)->m_impl || static_cast<const Base*>(this)->m_impl->state() != WeakImpl::Live)99 return GetType();100 return jsCast<T*>(static_cast<const Base*>(this)->m_impl->jsValue().asCell());101 }102 103 template<typename Base, typename T> inline bool WeakImplAccessor<Base, T>::was(typename WeakImplAccessor<Base, T>::GetType other) const104 {105 return jsCast<T*>(static_cast<const Base*>(this)->m_impl->jsValue().asCell()) == other;106 }107 108 73 template<typename T> inline PassWeak<T>::PassWeak() 109 74 : m_impl(0) … … 116 81 } 117 82 118 template<typename T> inline PassWeak<T>::PassWeak( typename PassWeak<T>::GetType getType, WeakHandleOwner* weakOwner, void* context)119 : m_impl( getType ? WeakSet::allocate(getType, weakOwner, context) : 0)83 template<typename T> inline PassWeak<T>::PassWeak(T* cell, WeakHandleOwner* weakOwner, void* context) 84 : m_impl(cell ? WeakSet::allocate(cell, weakOwner, context) : 0) 120 85 { 121 86 } … … 138 103 } 139 104 105 template<typename T> inline T* PassWeak<T>::operator->() const 106 { 107 ASSERT(m_impl && m_impl->state() == WeakImpl::Live); 108 return jsCast<T*>(m_impl->jsValue().asCell()); 109 } 110 111 template<typename T> inline T& PassWeak<T>::operator*() const 112 { 113 ASSERT(m_impl && m_impl->state() == WeakImpl::Live); 114 return *jsCast<T*>(m_impl->jsValue().asCell()); 115 } 116 117 template<typename T> inline T* PassWeak<T>::get() const 118 { 119 if (!m_impl || m_impl->state() != WeakImpl::Live) 120 return 0; 121 return jsCast<T*>(m_impl->jsValue().asCell()); 122 } 123 140 124 template<typename T> inline bool PassWeak<T>::operator!() const 141 125 {
Note:
See TracChangeset
for help on using the changeset viewer.