Bug 1196378 - js_delete should accept a const pointer like builtin delete, r=fitzgen
authorSteve Fink <sfink@mozilla.com>
Wed, 19 Aug 2015 10:59:50 -0700
changeset 287177 bdb54665c61c46ab4770f921dd3385d771989496
parent 287176 bc43f663e5e16b7a5e5a6d77b4a96b7c27accafa
child 287178 42ac4229e5f15ab5ceea77f64e1342a46016f439
push id4660
push usermartin.thomson@gmail.com
push dateFri, 21 Aug 2015 22:37:38 +0000
reviewersfitzgen
bugs1196378
milestone43.0a1
Bug 1196378 - js_delete should accept a const pointer like builtin delete, r=fitzgen
js/public/Utility.h
--- a/js/public/Utility.h
+++ b/js/public/Utility.h
@@ -189,17 +189,17 @@ static inline char* js_strdup(const char
  *   These functions accumulate the number of bytes allocated which is used as
  *   part of the GC-triggering heuristic.
  *
  *   The difference between the JSContext and JSRuntime versions is that the
  *   cx version reports an out-of-memory error on OOM. (This follows from the
  *   general SpiderMonkey idiom that a JSContext-taking function reports its
  *   own errors.)
  *
- * - Otherwise, use js_malloc/js_realloc/js_calloc/js_free/js_new
+ * - Otherwise, use js_malloc/js_realloc/js_calloc/js_new
  *
  * Deallocation:
  *
  * - Ordinarily, use js_free/js_delete.
  *
  * - For deallocations during GC finalization, use one of the following
  *   operations on the FreeOp provided to the finalizer:
  *
@@ -243,32 +243,32 @@ static inline char* js_strdup(const char
         T* ptr = NEWNAME<T>(mozilla::Forward<Args>(args)...); \
         return mozilla::UniquePtr<T, JS::DeletePolicy<T>>(ptr); \
     }
 
 JS_DECLARE_NEW_METHODS(js_new, js_malloc, static MOZ_ALWAYS_INLINE)
 
 template <class T>
 static MOZ_ALWAYS_INLINE void
-js_delete(T* p)
+js_delete(const T* p)
 {
     if (p) {
         p->~T();
-        js_free(p);
+        js_free(const_cast<T*>(p));
     }
 }
 
 template<class T>
 static MOZ_ALWAYS_INLINE void
-js_delete_poison(T* p)
+js_delete_poison(const T* p)
 {
     if (p) {
         p->~T();
-        memset(p, 0x3B, sizeof(T));
-        js_free(p);
+        memset(const_cast<T*>(p), 0x3B, sizeof(T));
+        js_free(const_cast<T*>(p));
     }
 }
 
 template <class T>
 static MOZ_ALWAYS_INLINE T*
 js_pod_malloc()
 {
     return (T*)js_malloc(sizeof(T));