summaryrefslogtreecommitdiff
path: root/Source/WTF/wtf/RefCounted.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WTF/wtf/RefCounted.h')
-rw-r--r--Source/WTF/wtf/RefCounted.h30
1 files changed, 13 insertions, 17 deletions
diff --git a/Source/WTF/wtf/RefCounted.h b/Source/WTF/wtf/RefCounted.h
index ab6c27a35..13762e07a 100644
--- a/Source/WTF/wtf/RefCounted.h
+++ b/Source/WTF/wtf/RefCounted.h
@@ -18,17 +18,15 @@
*
*/
-#ifndef RefCounted_h
-#define RefCounted_h
+#pragma once
#include <wtf/Assertions.h>
#include <wtf/FastMalloc.h>
#include <wtf/Noncopyable.h>
-#include <wtf/OwnPtr.h>
namespace WTF {
-#ifdef NDEBUG
+#if defined(NDEBUG) && !ENABLE(SECURITY_ASSERTIONS)
#define CHECK_REF_COUNTED_LIFECYCLE 0
#else
#define CHECK_REF_COUNTED_LIFECYCLE 1
@@ -39,10 +37,10 @@ namespace WTF {
// generated by the compiler (technique called template hoisting).
class RefCountedBase {
public:
- void ref()
+ void ref() const
{
#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(!m_deletionHasBegun);
+ ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
ASSERT(!m_adoptionIsRequired);
#endif
++m_refCount;
@@ -64,7 +62,7 @@ public:
void relaxAdoptionRequirement()
{
#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(!m_deletionHasBegun);
+ ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
ASSERT(m_adoptionIsRequired);
m_adoptionIsRequired = false;
#endif
@@ -89,10 +87,10 @@ protected:
}
// Returns whether the pointer should be freed or not.
- bool derefBase()
+ bool derefBase() const
{
#if CHECK_REF_COUNTED_LIFECYCLE
- ASSERT(!m_deletionHasBegun);
+ ASSERT_WITH_SECURITY_IMPLICATION(!m_deletionHasBegun);
ASSERT(!m_adoptionIsRequired);
#endif
@@ -121,10 +119,10 @@ private:
friend void adopted(RefCountedBase*);
#endif
- unsigned m_refCount;
+ mutable unsigned m_refCount;
#if CHECK_REF_COUNTED_LIFECYCLE
- bool m_deletionHasBegun;
- bool m_adoptionIsRequired;
+ mutable bool m_deletionHasBegun;
+ mutable bool m_adoptionIsRequired;
#endif
};
@@ -133,7 +131,7 @@ inline void adopted(RefCountedBase* object)
{
if (!object)
return;
- ASSERT(!object->m_deletionHasBegun);
+ ASSERT_WITH_SECURITY_IMPLICATION(!object->m_deletionHasBegun);
object->m_adoptionIsRequired = false;
}
#endif
@@ -141,10 +139,10 @@ inline void adopted(RefCountedBase* object)
template<typename T> class RefCounted : public RefCountedBase {
WTF_MAKE_NONCOPYABLE(RefCounted); WTF_MAKE_FAST_ALLOCATED;
public:
- void deref()
+ void deref() const
{
if (derefBase())
- delete static_cast<T*>(this);
+ delete static_cast<const T*>(this);
}
protected:
@@ -157,5 +155,3 @@ protected:
} // namespace WTF
using WTF::RefCounted;
-
-#endif // RefCounted_h