Index: Source/heap/Heap.h |
diff --git a/Source/heap/Heap.h b/Source/heap/Heap.h |
index 50ee7277b246623b2530160ae7c390e472e59188..a6b897ee4ffa98ad85aefcb10488b9772e0cfa4f 100644 |
--- a/Source/heap/Heap.h |
+++ b/Source/heap/Heap.h |
@@ -442,10 +442,36 @@ template<typename T> |
class HeapAllocatedFinalized : public HeapAllocated<T> { |
WTF_MAKE_NONCOPYABLE(HeapAllocatedFinalized); |
+ // If this assert fails then you are inheriting this method instead of |
Mads Ager (chromium)
2013/06/11 06:42:43
This comment seems to belong on the inherited new
|
+ // overriding it. This may be an issue because the inherited class |
+ // specialization (T) is used to find the finalizer. This may mean that the |
+ // wrong method is used in the allocateFinalized specialization below and |
+ // the wrong accept method may be used to visit the method if there is a GC |
+ // before the new object has been adopted. |
+#define OVERRIDE_NEW(subClass) \ |
+ void* operator new(size_t size) \ |
+ { \ |
+ ASSERT(size == sizeof(class subClass)); \ |
+ return Heap::allocateFinalized<subClass>(size); \ |
+ } |
+ |
+// Only use this for classes where we know that accept(Visitor*) is dynamic, |
+// ie. it is virtual or uses a type field that is immediately initialized |
+// in the constuctors. Similarly the finalizer must be the same for all |
+// subclasses. |
+#define OVERRIDE_NEW_ALL_SUBCLASSES_HAVE_DYNAMIC_ACCEPT(subClass) \ |
+ void* operator new(size_t size) \ |
+ { \ |
+ return Heap::allocateFinalized<subClass>(size); \ |
+ } |
+ |
public: |
// Override new to pass the finalizer. |
void* operator new(size_t size) |
{ |
+ // If this assert fails you probably need to use OVERRIDE_NEW |
+ // (see above). |
+ ASSERT(size == sizeof(T)); |
return Heap::allocateFinalized<T>(size); |
} |