Bug 1320905 - Add js::RefCounted that uses js_delete (r=waldo)
☠☠ backed out by 2d08aeb18ac9 ☠ ☠
authorLuke Wagner <luke@mozilla.com>
Mon, 05 Dec 2016 08:46:27 -0600
changeset 325253 f38852711f383117b245c47db466764cd0a0b8b8
parent 325252 8103c612b79c2587ea4ca1b0a9f9f82db4b185b8
child 325254 eb6839ca47ea10a1ac0f241b896ea2d0ac01ce2d
push id84632
push userlwagner@mozilla.com
push dateMon, 05 Dec 2016 14:49:05 +0000
treeherdermozilla-inbound@f38852711f38 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1320905
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1320905 - Add js::RefCounted that uses js_delete (r=waldo) MozReview-Commit-ID: D0mSwdm0nn0
js/public/RefCounted.h
js/public/UniquePtr.h
js/src/jsapi-tests/testIntTypesABI.cpp
js/src/jsapi.h
js/src/moz.build
mfbt/RefCounted.h
new file mode 100644
--- /dev/null
+++ b/js/public/RefCounted.h
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * vim: set ts=8 sts=4 et sw=4 tw=99:
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef js_RefCounted_h
+#define js_RefCounted_h
+
+#include "mozilla/RefCounted.h"
+
+#include "js/Utility.h"
+
+namespace js {
+
+// Replacement for mozilla::RefCounted and mozilla::external::AtomicRefCounted
+// that default to JS::DeletePolicy.
+
+template <typename T, typename D = JS::DeletePolicy<T>>
+using RefCounted = mozilla::RefCounted<T, D>;
+
+template <typename T, typename D = JS::DeletePolicy<T>>
+using AtomicRefCounted = mozilla::external::AtomicRefCounted<T, D>;
+
+} // namespace js
+
+#endif /* js_RefCounted_h */
--- a/js/public/UniquePtr.h
+++ b/js/public/UniquePtr.h
@@ -8,17 +8,17 @@
 #define js_UniquePtr_h
 
 #include "mozilla/UniquePtr.h"
 
 #include "js/Utility.h"
 
 namespace js {
 
-// Replacement for mozilla::UniquePtr that defaults to js::DefaultDelete.
+// Replacement for mozilla::UniquePtr that defaults to JS::DeletePolicy.
 template <typename T, typename D = JS::DeletePolicy<T>>
 using UniquePtr = mozilla::UniquePtr<T, D>;
 
 namespace detail {
 
 template<typename T>
 struct UniqueSelector
 {
--- a/js/src/jsapi-tests/testIntTypesABI.cpp
+++ b/js/src/jsapi-tests/testIntTypesABI.cpp
@@ -21,16 +21,17 @@
 #include "js/Debug.h"
 #include "js/GCAPI.h"
 #include "js/HashTable.h"
 #include "js/HeapAPI.h"
 #include "js/Id.h"
 /* LegacyIntTypes.h is deliberately exempted from this requirement */
 #include "js/MemoryMetrics.h"
 #include "js/ProfilingStack.h"
+#include "js/RefCounted.h"
 #include "js/RequiredDefines.h"
 #include "js/RootingAPI.h"
 #include "js/SliceBudget.h"
 #include "js/StructuredClone.h"
 #include "js/TracingAPI.h"
 #include "js/TrackedOptimizationInfo.h"
 #include "js/TypeDecls.h"
 #include "js/UbiNode.h"
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -9,17 +9,16 @@
 #ifndef jsapi_h
 #define jsapi_h
 
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Range.h"
 #include "mozilla/RangedPtr.h"
-#include "mozilla/RefCounted.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/Variant.h"
 
 #include <stdarg.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
 
@@ -29,16 +28,17 @@
 #include "js/CallArgs.h"
 #include "js/CharacterEncoding.h"
 #include "js/Class.h"
 #include "js/GCVector.h"
 #include "js/HashTable.h"
 #include "js/Id.h"
 #include "js/Principals.h"
 #include "js/Realm.h"
+#include "js/RefCounted.h"
 #include "js/RootingAPI.h"
 #include "js/TracingAPI.h"
 #include "js/Utility.h"
 #include "js/Value.h"
 #include "js/Vector.h"
 
 /************************************************************************/
 
@@ -6082,17 +6082,17 @@ SetBuildIdOp(JSContext* cx, BuildIdOp bu
  * still valid (as described above). DeserializeWasmModule is then called to
  * construct a JS::WasmModule (also on the background thread), passing the
  * bytecode file descriptor and, if valid, the compiled-code file descriptor.
  * The JS::WasmObject is then transported to the JSRuntime thread (which
  * originated the request) and the wrapping WebAssembly.Module object is created
  * by calling createObject().
  */
 
-struct WasmModule : mozilla::external::AtomicRefCounted<WasmModule>
+struct WasmModule : js::AtomicRefCounted<WasmModule>
 {
     MOZ_DECLARE_REFCOUNTED_TYPENAME(WasmModule)
     virtual ~WasmModule() {}
 
     virtual void serializedSize(size_t* bytecodeSize, size_t* compiledSize) const = 0;
     virtual void serialize(uint8_t* bytecodeBegin, size_t bytecodeSize,
                            uint8_t* compiledBegin, size_t compiledSize) const = 0;
 
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -128,16 +128,17 @@ EXPORTS.js += [
     '../public/Initialization.h',
     '../public/LegacyIntTypes.h',
     '../public/MemoryMetrics.h',
     '../public/Principals.h',
     '../public/ProfilingFrameIterator.h',
     '../public/ProfilingStack.h',
     '../public/Proxy.h',
     '../public/Realm.h',
+    '../public/RefCounted.h',
     '../public/RequiredDefines.h',
     '../public/Result.h',
     '../public/RootingAPI.h',
     '../public/SliceBudget.h',
     '../public/StructuredClone.h',
     '../public/SweepingAPI.h',
     '../public/TraceKind.h',
     '../public/TracingAPI.h',
--- a/mfbt/RefCounted.h
+++ b/mfbt/RefCounted.h
@@ -11,16 +11,17 @@
 
 #include "mozilla/AlreadyAddRefed.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Move.h"
 #include "mozilla/RefCountType.h"
 #include "mozilla/TypeTraits.h"
+#include "mozilla/UniquePtr.h"
 
 #if defined(MOZILLA_INTERNAL_API)
 #include "nsXPCOM.h"
 #endif
 
 #if defined(MOZILLA_INTERNAL_API) && \
     (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
 #define MOZ_REFCOUNTED_LEAK_CHECKING
@@ -81,17 +82,17 @@ public:
 
 // This is used WeakPtr.h as well as this file.
 enum RefCountAtomicity
 {
   AtomicRefCount,
   NonAtomicRefCount
 };
 
-template<typename T, RefCountAtomicity Atomicity>
+template<typename T, RefCountAtomicity Atomicity, typename D>
 class RefCounted
 {
 protected:
   RefCounted() : mRefCnt(0) {}
   ~RefCounted() { MOZ_ASSERT(mRefCnt == detail::DEAD); }
 
 public:
   // Compatibility with nsRefPtr.
@@ -127,17 +128,17 @@ public:
     if (0 == cnt) {
       // Because we have atomically decremented the refcount above, only
       // one thread can get a 0 count here, so as long as we can assume that
       // everything else in the system is accessing this object through
       // RefPtrs, it's safe to access |this| here.
 #ifdef DEBUG
       mRefCnt = detail::DEAD;
 #endif
-      delete static_cast<const T*>(this);
+      D()(const_cast<T*>(static_cast<const T*>(this)));
     }
   }
 
   // Compatibility with wtf::RefPtr.
   void ref() { AddRef(); }
   void deref() { Release(); }
   MozRefCountType refCount() const { return mRefCnt; }
   bool hasOneRef() const
@@ -166,18 +167,18 @@ private:
 // two small inline functions which will hopefully get eliminated by the linker
 // in non-leak-checking builds.
 #define MOZ_DECLARE_REFCOUNTED_TYPENAME(T) \
   const char* typeName() const { return #T; } \
   size_t typeSize() const { return sizeof(*this); }
 
 } // namespace detail
 
-template<typename T>
-class RefCounted : public detail::RefCounted<T, detail::NonAtomicRefCount>
+template<typename T, class D = DefaultDelete<T>>
+class RefCounted : public detail::RefCounted<T, detail::NonAtomicRefCount, D>
 {
 public:
   ~RefCounted()
   {
     static_assert(IsBaseOf<RefCounted, T>::value,
                   "T must derive from RefCounted<T>");
   }
 };
@@ -186,19 +187,19 @@ namespace external {
 
 /**
  * AtomicRefCounted<T> is like RefCounted<T>, with an atomically updated
  * reference counter.
  *
  * NOTE: Please do not use this class, use NS_INLINE_DECL_THREADSAFE_REFCOUNTING
  * instead.
  */
-template<typename T>
+template<typename T, typename D = DefaultDelete<T>>
 class AtomicRefCounted :
-  public mozilla::detail::RefCounted<T, mozilla::detail::AtomicRefCount>
+  public mozilla::detail::RefCounted<T, mozilla::detail::AtomicRefCount, D>
 {
 public:
   ~AtomicRefCounted()
   {
     static_assert(IsBaseOf<AtomicRefCounted, T>::value,
                   "T must derive from AtomicRefCounted<T>");
   }
 };