diff options
-rw-r--r-- | third_party/WebKit/Source/wtf/RefCounted.h | 16 | ||||
-rw-r--r-- | third_party/WebKit/Source/wtf/RefPtrTest.cpp | 12 |
2 files changed, 20 insertions, 8 deletions
diff --git a/third_party/WebKit/Source/wtf/RefCounted.h b/third_party/WebKit/Source/wtf/RefCounted.h index 299fb37..db9d082 100644 --- a/third_party/WebKit/Source/wtf/RefCounted.h +++ b/third_party/WebKit/Source/wtf/RefCounted.h @@ -41,7 +41,7 @@ namespace WTF { // generated by the compiler (technique called template hoisting). class WTF_EXPORT RefCountedBase { public: - void ref() + void ref() const { #if CHECK_REF_COUNTED_LIFECYCLE m_verifier.onRef(m_refCount); @@ -89,7 +89,7 @@ protected: } // Returns whether the pointer should be freed or not. - bool derefBase() + bool derefBase() const { ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun); #if CHECK_REF_COUNTED_LIFECYCLE @@ -122,13 +122,13 @@ private: friend void adopted(RefCountedBase*); #endif - int m_refCount; + mutable int m_refCount; #if ENABLE(SECURITY_ASSERT) - bool m_deletionHasBegun; + mutable bool m_deletionHasBegun; #endif #if CHECK_REF_COUNTED_LIFECYCLE - bool m_adoptionIsRequired; - ThreadRestrictionVerifier m_verifier; + mutable bool m_adoptionIsRequired; + mutable ThreadRestrictionVerifier m_verifier; #endif }; @@ -153,10 +153,10 @@ template<typename T> class RefCounted : public RefCountedBase { USING_FAST_MALLOC(T); public: - void deref() + void deref() const { if (derefBase()) - delete static_cast<T*>(this); + delete static_cast<const T*>(this); } protected: diff --git a/third_party/WebKit/Source/wtf/RefPtrTest.cpp b/third_party/WebKit/Source/wtf/RefPtrTest.cpp index 7f37fc3..a21b4f7 100644 --- a/third_party/WebKit/Source/wtf/RefPtrTest.cpp +++ b/third_party/WebKit/Source/wtf/RefPtrTest.cpp @@ -5,6 +5,7 @@ #include "wtf/RefPtr.h" #include "testing/gtest/include/gtest/gtest.h" +#include "wtf/RefCounted.h" #include "wtf/text/StringImpl.h" namespace WTF { @@ -28,4 +29,15 @@ TEST(RefPtrTest, MoveAssignmentOperator) EXPECT_TRUE(!a); } +class RefCountedClass : public RefCounted<RefCountedClass> { +}; + +TEST(RefPtrTest, ConstObject) +{ + // This test is only to ensure we force the compilation of a const RefCounted + // object to ensure the generated code compiles. + RefPtr<const RefCountedClass> ptrToConst = adoptRef(new RefCountedClass()); +} + + } // namespace WTF |