diff --git a/mozilla/js/js2/gc_allocator.h b/mozilla/js/js2/gc_allocator.h index 3e78f1e3e90..41fe4ea9f94 100644 --- a/mozilla/js/js2/gc_allocator.h +++ b/mozilla/js/js2/gc_allocator.h @@ -146,6 +146,18 @@ namespace JavaScript { static void collect() { GC_gcollect(); } }; + + /** + * Generic base class for objects allocated using a gc_allocator. + */ + template class gc_object { + public: + void* operator new(size_t) { return alloc.allocate(1, 0); } + void operator delete(void* /* ptr */) {} + private: + static gc_allocator alloc; + }; + template gc_allocator gc_object::alloc; } #endif /* gc_allocator_h */ diff --git a/mozilla/js2/src/gc_allocator.h b/mozilla/js2/src/gc_allocator.h index 3e78f1e3e90..41fe4ea9f94 100644 --- a/mozilla/js2/src/gc_allocator.h +++ b/mozilla/js2/src/gc_allocator.h @@ -146,6 +146,18 @@ namespace JavaScript { static void collect() { GC_gcollect(); } }; + + /** + * Generic base class for objects allocated using a gc_allocator. + */ + template class gc_object { + public: + void* operator new(size_t) { return alloc.allocate(1, 0); } + void operator delete(void* /* ptr */) {} + private: + static gc_allocator alloc; + }; + template gc_allocator gc_object::alloc; } #endif /* gc_allocator_h */