Ignore:
Timestamp:
Sep 7, 2007, 9:52:45 AM (18 years ago)
Author:
kmccullo
Message:

JavaScriptCore:

Reviewed by Maciej.

  • Moved JSRetainPtr to the API.
  • API/JSRetainPtr.h: Copied from kjs/JSRetainPtr.h. (JSRetain): (JSRelease): (JSRetainPtr::JSRetainPtr): (JSRetainPtr::~JSRetainPtr): (JSRetainPtr::get): (JSRetainPtr::releaseRef): (JSRetainPtr::operator->): (JSRetainPtr::operator!): (JSRetainPtr::operator UnspecifiedBoolType): (::operator): (::adopt): (::swap): (swap): (operator==): (operator!=):
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • kjs/JSRetainPtr.h: Removed.

WebKitTools:

Reviewed by Maciej.

  • Changed Drosera to take advantage of the JSRetainPtr changes.
  • Drosera/DebuggerDocument.cpp: (DebuggerDocument::breakpointEditorHTML): (DebuggerDocument::evaluateScript): (DebuggerDocument::valueForScopeVariableNamed): (DebuggerDocument::log): (DebuggerDocument::windowScriptObjectAvailable): (DebuggerDocument::toJSArray): (DebuggerDocument::callFunctionOnObject): (DebuggerDocument::logException):
  • Drosera/mac/DebuggerDocumentMac.mm: (-[DebuggerClientMac webView:didLoadMainResourceForDataSource:]): (-[DebuggerClientMac webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:]): (DebuggerDocument::platformEvaluateScript): (DebuggerDocument::getPlatformCurrentFunctionStack): (DebuggerDocument::getPlatformLocalScopeVariableNamesForCallFrame): (DebuggerDocument::platformValueForScopeVariableNamed):
File:
1 moved

Legend:

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

    r25394 r25413  
    3333#include <algorithm>
    3434
    35 namespace KJS {
     35inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
     36inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
    3637
    37     inline void JSRetain(JSStringRef string) { JSStringRetain(string); }
    38     inline void JSRelease(JSStringRef string) { JSStringRelease(string); }
     38enum AdoptTag { Adopt };
    3939
    40     enum AdoptTag { Adopt };
     40template <typename T> class JSRetainPtr {
     41public:
     42    JSRetainPtr() : m_ptr(0) {}
     43    JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); }
    4144
    42     template <typename T> class JSRetainPtr {
    43     public:
    44         JSRetainPtr() : m_ptr(0) {}
    45         JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); }
     45    JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { }
     46   
     47    JSRetainPtr(const JSRetainPtr& o) : m_ptr(o.m_ptr) { if (T ptr = m_ptr) JSRetain(ptr); }
    4648
    47         JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { }
    48        
    49         JSRetainPtr(const JSRetainPtr& o) : m_ptr(o.m_ptr) { if (T ptr = m_ptr) JSRetain(ptr); }
     49    ~JSRetainPtr() { if (T ptr = m_ptr) JSRelease(ptr); }
     50   
     51    template <typename U> JSRetainPtr(const JSRetainPtr<U>& o) : m_ptr(o.get()) { if (T ptr = m_ptr) JSRetain(ptr); }
     52   
     53    T get() const { return m_ptr; }
     54   
     55    T releaseRef() { T tmp = m_ptr; m_ptr = 0; return tmp; }
     56   
     57    T operator->() const { return m_ptr; }
     58   
     59    bool operator!() const { return !m_ptr; }
    5060
    51         ~JSRetainPtr() { if (T ptr = m_ptr) JSRelease(ptr); }
    52        
    53         template <typename U> JSRetainPtr(const JSRetainPtr<U>& o) : m_ptr(o.get()) { if (T ptr = m_ptr) JSRetain(ptr); }
    54        
    55         T get() const { return m_ptr; }
    56        
    57         T releaseRef() { T tmp = m_ptr; m_ptr = 0; return tmp; }
    58        
    59         T operator->() const { return m_ptr; }
    60        
    61         bool operator!() const { return !m_ptr; }
     61    // This conversion operator allows implicit conversion to bool but not to other integer types.
     62    typedef T (JSRetainPtr::*UnspecifiedBoolType)() const;
     63    operator UnspecifiedBoolType() const { return m_ptr ? &JSRetainPtr::get : 0; }
    6264   
    63         // This conversion operator allows implicit conversion to bool but not to other integer types.
    64         typedef T (JSRetainPtr::*UnspecifiedBoolType)() const;
    65         operator UnspecifiedBoolType() const { return m_ptr ? &JSRetainPtr::get : 0; }
    66        
    67         JSRetainPtr& operator=(const JSRetainPtr&);
    68         template <typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&);
    69         JSRetainPtr& operator=(T);
    70         template <typename U> JSRetainPtr& operator=(U*);
     65    JSRetainPtr& operator=(const JSRetainPtr&);
     66    template <typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&);
     67    JSRetainPtr& operator=(T);
     68    template <typename U> JSRetainPtr& operator=(U*);
    7169
    72         void adopt(T);
    73        
    74         void swap(JSRetainPtr&);
     70    void adopt(T);
     71   
     72    void swap(JSRetainPtr&);
    7573
    76     private:
    77         T m_ptr;
    78     };
    79    
    80     template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o)
    81     {
    82         T optr = o.get();
    83         if (optr)
    84             JSRetain(optr);
    85         T ptr = m_ptr;
    86         m_ptr = optr;
    87         if (ptr)
    88             JSRelease(ptr);
    89         return *this;
    90     }
    91    
    92     template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)
    93     {
    94         T optr = o.get();
    95         if (optr)
    96             JSRetain(optr);
    97         T ptr = m_ptr;
    98         m_ptr = optr;
    99         if (ptr)
    100             JSRelease(ptr);
    101         return *this;
    102     }
    103    
    104     template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr)
    105     {
    106         if (optr)
    107             JSRetain(optr);
    108         T ptr = m_ptr;
    109         m_ptr = optr;
    110         if (ptr)
    111             JSRelease(ptr);
    112         return *this;
    113     }
     74private:
     75    T m_ptr;
     76};
    11477
    115     template <typename T> inline void JSRetainPtr<T>::adopt(T optr)
    116     {
    117         T ptr = m_ptr;
    118         m_ptr = optr;
    119         if (ptr)
    120             JSRelease(ptr);
    121     }
    122    
    123     template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)
    124     {
    125         if (optr)
    126             JSRetain(optr);
    127         T ptr = m_ptr;
    128         m_ptr = optr;
    129         if (ptr)
    130             JSRelease(ptr);
    131         return *this;
    132     }
     78template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o)
     79{
     80    T optr = o.get();
     81    if (optr)
     82        JSRetain(optr);
     83    T ptr = m_ptr;
     84    m_ptr = optr;
     85    if (ptr)
     86        JSRelease(ptr);
     87    return *this;
     88}
    13389
    134     template <class T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)
    135     {
    136         std::swap(m_ptr, o.m_ptr);
    137     }
     90template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)
     91{
     92    T optr = o.get();
     93    if (optr)
     94        JSRetain(optr);
     95    T ptr = m_ptr;
     96    m_ptr = optr;
     97    if (ptr)
     98        JSRelease(ptr);
     99    return *this;
     100}
    138101
    139     template <class T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)
    140     {
    141         a.swap(b);
    142     }
     102template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr)
     103{
     104    if (optr)
     105        JSRetain(optr);
     106    T ptr = m_ptr;
     107    m_ptr = optr;
     108    if (ptr)
     109        JSRelease(ptr);
     110    return *this;
     111}
    143112
    144     template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
    145     {
    146         return a.get() == b.get();
    147     }
     113template <typename T> inline void JSRetainPtr<T>::adopt(T optr)
     114{
     115    T ptr = m_ptr;
     116    m_ptr = optr;
     117    if (ptr)
     118        JSRelease(ptr);
     119}
    148120
    149     template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b)
    150     {
    151         return a.get() == b;
    152     }
    153    
    154     template <typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b)
    155     {
    156         return a == b.get();
    157     }
    158    
    159     template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
    160     {
    161         return a.get() != b.get();
    162     }
     121template <typename T> template <typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)
     122{
     123    if (optr)
     124        JSRetain(optr);
     125    T ptr = m_ptr;
     126    m_ptr = optr;
     127    if (ptr)
     128        JSRelease(ptr);
     129    return *this;
     130}
    163131
    164     template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b)
    165     {
    166         return a.get() != b;
    167     }
     132template <class T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)
     133{
     134    std::swap(m_ptr, o.m_ptr);
     135}
    168136
    169     template <typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b)
    170     {
    171         return a != b.get();
    172     }
     137template <class T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)
     138{
     139    a.swap(b);
     140}
    173141
    174 } // namespace KJS
     142template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
     143{
     144    return a.get() == b.get();
     145}
    175146
    176 using KJS::JSRetainPtr;
     147template <typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b)
     148{
     149    return a.get() == b;
     150}
    177151
    178 #endif // KJS_JSRetainPtr_h
     152template <typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b)
     153{
     154    return a == b.get();
     155}
     156
     157template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b)
     158{
     159    return a.get() != b.get();
     160}
     161
     162template <typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b)
     163{
     164    return a.get() != b;
     165}
     166
     167template <typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b)
     168{
     169    return a != b.get();
     170}
     171
     172
     173#endif // JSRetainPtr_h
Note: See TracChangeset for help on using the changeset viewer.