# HG changeset patch # Parent e1d57aec0d3f42ff5f78425c1a230bb349528f60 # User Jeff Walden Bug 851237 - Replace StaticAssert uses with MOZ_STATIC_ASSERT. NOT REVIEWED YET diff --git a/js/public/HashTable.h b/js/public/HashTable.h --- a/js/public/HashTable.h +++ b/js/public/HashTable.h @@ -8,6 +8,7 @@ #ifndef js_HashTable_h__ #define js_HashTable_h__ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/DebugOnly.h" #include "mozilla/TypeTraits.h" @@ -67,7 +68,15 @@ class HashMap // HashMap construction is fallible (due to OOM); thus the user must call // init after constructing a HashMap and check the return value. - HashMap(AllocPolicy a = AllocPolicy()) : impl(a) {} + HashMap(AllocPolicy a = AllocPolicy()) + : impl(a) + { + MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType::result, + "Key type must be relocatable"); + MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType::result, + "Value type must be relocatable"); + } + bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -254,9 +263,6 @@ class HashMap HashMap &operator=(const HashMap &hm) MOZ_DELETE; friend class Impl::Enum; - - typedef typename tl::StaticAssert::result>::result keyAssert; - typedef typename tl::StaticAssert::result>::result valAssert; }; /*****************************************************************************/ @@ -297,7 +303,11 @@ class HashSet // HashSet construction is fallible (due to OOM); thus the user must call // init after constructing a HashSet and check the return value. - HashSet(AllocPolicy a = AllocPolicy()) : impl(a) {} + HashSet(AllocPolicy a = AllocPolicy()) : impl(a) + { + MOZ_STATIC_ASSERT(tl::IsRelocatableHeapType::result, + "Set element type must be relocatable"); + } bool init(uint32_t len = 16) { return impl.init(len); } bool initialized() const { return impl.initialized(); } @@ -448,8 +458,6 @@ class HashSet HashSet &operator=(const HashSet &hs) MOZ_DELETE; friend class Impl::Enum; - - typedef typename tl::StaticAssert::result>::result _; }; /*****************************************************************************/ diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -191,13 +191,15 @@ class Handle : public js::HandleBase /* Create a handle for a NULL pointer. */ Handle(js::NullPtr) { - typedef typename js::tl::StaticAssert::value>::result _; + MOZ_STATIC_ASSERT(mozilla::IsPointer::value, + "js::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&js::NullPtr::constNullValue); } /* Create a handle for a NULL pointer. */ Handle(JS::NullPtr) { - typedef typename js::tl::StaticAssert::value>::result _; + MOZ_STATIC_ASSERT(mozilla::IsPointer::value, + "JS::NullPtr overload not valid for non-pointer types"); ptr = reinterpret_cast(&JS::NullPtr::constNullValue); } diff --git a/js/public/TemplateLib.h b/js/public/TemplateLib.h --- a/js/public/TemplateLib.h +++ b/js/public/TemplateLib.h @@ -64,16 +64,12 @@ template struct BitSize { static const size_t result = sizeof(T) * JS_BITS_PER_BYTE; }; -/* Allow Assertions by only including the 'result' typedef if 'true'. */ -template struct StaticAssert {}; -template <> struct StaticAssert { typedef int result; }; - /* * Produce an N-bit mask, where N <= BitSize::result. Handle the * language-undefined edge case when N = BitSize::result. */ template struct NBitMask { - typedef typename StaticAssert::result>::result _; + static const size_t checkPrecondition = 0 / (N < BitSize::result); static const size_t result = (size_t(1) << N) - 1; }; template <> struct NBitMask::result> { diff --git a/js/src/ds/LifoAlloc.h b/js/src/ds/LifoAlloc.h --- a/js/src/ds/LifoAlloc.h +++ b/js/src/ds/LifoAlloc.h @@ -8,6 +8,7 @@ #ifndef LifoAlloc_h__ #define LifoAlloc_h__ +#include "mozilla/Assertions.h" #include "mozilla/Attributes.h" #include "mozilla/DebugOnly.h" #include "mozilla/GuardObjects.h" @@ -33,9 +34,9 @@ JS_ALWAYS_INLINE char * AlignPtr(void *orig) { - typedef tl::StaticAssert< - tl::FloorLog2::result == tl::CeilingLog2::result - >::result _; + MOZ_STATIC_ASSERT(tl::FloorLog2::result == + tl::CeilingLog2::result, + "LIFO_ALLOC_ALIGN must be a power of two"); char *result = (char *) ((uintptr_t(orig) + (LIFO_ALLOC_ALIGN - 1)) & (~LIFO_ALLOC_ALIGN + 1)); JS_ASSERT(uintptr_t(result) % LIFO_ALLOC_ALIGN == 0);