Bug 1320905 - Add js::RefCounted that uses js_delete (r=waldo)

This commit is contained in:
Luke Wagner 2016-12-05 15:59:18 -08:00
Родитель 2b70890ad5
Коммит 549d7571b3
7 изменённых файлов: 42 добавлений и 12 удалений

27
js/public/RefCounted.h Normal file
Просмотреть файл

@ -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 */

Просмотреть файл

@ -13,7 +13,7 @@
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>;

Просмотреть файл

@ -26,6 +26,7 @@
/* 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"

Просмотреть файл

@ -14,7 +14,6 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/Range.h"
#include "mozilla/RangedPtr.h"
#include "mozilla/RefCounted.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Variant.h"
@ -34,6 +33,7 @@
#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"
@ -6087,7 +6087,7 @@ SetBuildIdOp(JSContext* cx, BuildIdOp buildIdOp);
* by calling createObject().
*/
struct WasmModule : mozilla::external::AtomicRefCounted<WasmModule>
struct WasmModule : js::AtomicRefCounted<WasmModule>
{
MOZ_DECLARE_REFCOUNTED_TYPENAME(WasmModule)
virtual ~WasmModule() {}

Просмотреть файл

@ -133,6 +133,7 @@ EXPORTS.js += [
'../public/ProfilingStack.h',
'../public/Proxy.h',
'../public/Realm.h',
'../public/RefCounted.h',
'../public/RequiredDefines.h',
'../public/Result.h',
'../public/RootingAPI.h',

Просмотреть файл

@ -16,6 +16,7 @@
#include "mozilla/Move.h"
#include "mozilla/RefCountType.h"
#include "mozilla/TypeTraits.h"
#include "mozilla/UniquePtr.h"
#if defined(MOZILLA_INTERNAL_API)
#include "nsXPCOM.h"
@ -86,7 +87,7 @@ enum RefCountAtomicity
NonAtomicRefCount
};
template<typename T, RefCountAtomicity Atomicity>
template<typename T, RefCountAtomicity Atomicity, typename D>
class RefCounted
{
protected:
@ -132,7 +133,7 @@ public:
#ifdef DEBUG
mRefCnt = detail::DEAD;
#endif
delete static_cast<const T*>(this);
D()(const_cast<T*>(static_cast<const T*>(this)));
}
}
@ -171,8 +172,8 @@ private:
} // 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()
@ -191,9 +192,9 @@ namespace external {
* 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()

Просмотреть файл

@ -81,9 +81,9 @@ class LibHandle;
namespace mozilla {
namespace detail {
template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() const;
template <> inline void RefCounted<LibHandle, AtomicRefCount, DefaultDelete<LibHandle>>::Release() const;
template <> inline RefCounted<LibHandle, AtomicRefCount>::~RefCounted()
template <> inline RefCounted<LibHandle, AtomicRefCount, DefaultDelete<LibHandle>>::~RefCounted()
{
MOZ_ASSERT(mRefCnt == 0x7fffdead);
}
@ -249,7 +249,7 @@ private:
namespace mozilla {
namespace detail {
template <> inline void RefCounted<LibHandle, AtomicRefCount>::Release() const {
template <> inline void RefCounted<LibHandle, AtomicRefCount, DefaultDelete<LibHandle>>::Release() const {
#ifdef DEBUG
if (mRefCnt > 0x7fff0000)
MOZ_ASSERT(mRefCnt > 0x7fffdead);