Files
roytam1 e333860065 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1251090 - Shell functions should check whether an off main thread compilation is for a script or a module r=shu (41b89b1232)
- Bug 1222420 - Make AutoFinishGC into a function r=terrence (a8f535528c)
- Bug 1253094, part 4 - Stop using DebugOnly for class/struct members in js/. r=billm (2c790aa526)
- Bug 1080968 - Don't use constexpr on clang-cl when emulating MSVC 2013 (e9cc2d7c7c)
- Bug 1257496 - Add information about cycle count and GC state to our GC stats r=sfink (6c2250bfba)
- Bug 1256178 - Drop the moz prefix from the MozCSSKeyframeRule and MozCSSKeyframesRule interfaces; r=bzbarsky (894855bce1)
- Bug 1249896 - Part 1: Remove unused AndOrLeft, AndOrRight, RelationalLeft, and RelationalRight. r=jwalden (c4db9dfecf)
- Bug 1249896 - Part 2: Remove unused type member from SIMD Int8x16Defnetc. r=bbouvier (7d3d7a4db1)
- Bug 1249896 - Part 3: Add JS namespace for GenericNaN. r=luke (69acc1f3ec)
- Bug 1249896 - Part 4: Avoid declaring variable between cases in switch. r=luke (28e5f94c24)
- Bug 1249896 - Part 5: Remove unused ReportInvalidTrapResult. r=efaust (caa948acac)
- Bug 1249896 - Part 7: Remove unnecessary static from my_ErrorReporter. r=sfink (7f723e079d)
- Bug 1249896 - Part 8: Remove unreachable code from GetLine. r=jwalden (108c857a1a)
- Bug 1249896 - Part 9: Include shell/jsshell.h in js.cpp. r=sfink (638bfc13c4)
- Bug 1253094, part 3 - Stop using DebugOnly for class/struct members in ipc/. r=billm (ab9e014158)
- Bug 1259737 - Make sure BackgroundImpl.cpp's mBoundThread is not used in release builds. r=froydnj (5c278ab398)
- Bug 1254515 - GonkCameraImage.cpp:16:5: error: class 'mozilla::GonkCameraImage' does not have any field named 'mThread' r=reuben (e5cac8cf5b)
- Bug 1250952: Create a join block in case we're in dead code after the condition; r=luke (1d6b706ae5)
- Bug 1249601 - Implement wasm i64 comparisons. r=sunfish (4927f709db)
- Bug 1250165 - Implement wasm i64 bitwise ops. r=luke (5c25322772)
- Bug 1251225 - Implement wasm i64 binary arithmetic operators. r=sunfish (f478fa8b4b)
- Bug 1251392 - Baldr: Implement PopcntI. r=sunfish (79556e947f)
- Bug 1229985 - remove nsAutoArrayPtr; r=erahm (91c49451ca)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth managers, r=shuang (2c1dc7ca89)
- Bug 1251541: Pass arguments to AVRCP passthrough command as uint8_t, r=shuang (73a094bd26)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth interfaces, r=shuang (371041f093)
- Bug 1249424 - Remove use of nsAutoArrayPtr from librlz. r=gerald (7cbcfea1b0)
- Bug 1249389 - part 0 - use getter_Transfers in TestStartupCache.cpp; r=erahm (ecb8818959)
- Bug 1249389 - part 1 - change NewObjectInputStreamFromBuffer to take a UniquePtr argument; r=erahm (0bdafa20ae)
- Bug 1249389 - part 2 - change NewBufferFromStorageStream's outparam into a UniquePtr; r=erahm (b27a70ce2d)
- Bug 1249389 - part 3 - assert the size of nsZipItemPtr's storage type; r=erahm (7c55da9ea7)
- Bug 1249389 - part 4 - make StartupCache::GetBuffer take a UniquePtr outparam; r=erahm (84b722479b)
- Bug 1249389 - part 5 - use UniquePtr instead of nsAutoArrayPtr in mozilla::scache::CacheEntry; r=erahm (0fd492ea95)
- Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm (c27231d945)
- Bug 1249389 - followup - fix compilation bustage in gfxFT2FontList.cpp; r=me (a86a1b0399)
- Bug 1249389 - part 7 - clean up calls to GetBuffer in TestStartupCache; r=erahm (98939334b6)
- Bug 1249369 - use UniquePtr instead of nsAutoArrayPtr in MediaPipeline.cpp; r=jesup (7402a75a8a)
- Bug 1238842 - Add error codes to Gecko by following W3C spec. r=brsun (0dd283f6ba)
- Bug 1253217 - Change filename from BluetoothUuid to BluetoothUuidHelper. r=jocelyn (1946bcac26)
- Bug 1241382 - Revise default value of BluetoothAdapter.address and BluetoothDevice.address to empty string, f=wiwang, r=shuang (d9fdb97743)
- Bug 1223722: Transfer arrays of Bluetooth UUIDs in |BluetoothValue|, r=brsun (344af40591)
- Bug 1222956: Use |BluetoothUuid| in |BluetoothDiscoveryHandle|, r=tzimmermann (40512de386)
- Bug 1250694: Use functions to return static const BluetoothAddress and BluetoothUuid; r=tzimmermann (0c4b20066f)
- Bug 1236561 - part 1 - convert easy cases of nsAutoArrayPtr<T> to UniquePtr<T[]> in dom/bluetooth/; r=btian (31ef8b7b50)
- Bug 1236561 - part 2 - remove ObexHeaderSet::GetAuthChallenge; r=btian (f70daddd53)
- Bug 1236561 - part 3 - make BluetoothConfigurationParameter.mValue a UniquePtr; r=btian (a5a0ac988a)
- Bug 1239979: Add |BluetoothSocket::Accept| method, r=btian (ca92a0ab7c)
- Bug 1239979: Store pointer to Bluetooth socket interface in |BluetoothSocket|, r=btian (7c15e75133)
- Bug 1239979: Cleanup |BluetoothSocket|'s internals when connections close, r=btian (b6ac677d2e)
- Bug 1252841: Convert Bluetooth module to |UniquePtr<>|, r=btian (76d9759afd)
- Bug 1232687: Start bluetoothd with HAL service interface, r=shuang (379a68064f)
- Bug 1223729 - HID Connection Implementation, r=jocelyn, sr=mrbkap (0eeddf875e)
- Bug 1232670: Prepare Bluetooth PDU for sending after checking connection status, r=shuang (699ff14d9b)
- Bug 1252841: Convert Bluetooth daemon interfaces to |UniquePtr<>|, r=brsun (797260c6dc)
2024-02-07 15:25:46 +08:00

455 lines
9.5 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 nsAutoPtr_h
#define nsAutoPtr_h
#include "nsCOMPtr.h"
#include "mozilla/RefPtr.h"
#include "mozilla/TypeTraits.h"
#include "nsCycleCollectionNoteChild.h"
#include "mozilla/MemoryReporting.h"
/*****************************************************************************/
// template <class T> class nsAutoPtrGetterTransfers;
template <class T>
class nsAutoPtr
{
private:
static_assert(!mozilla::IsScalar<T>::value, "If you are using "
"nsAutoPtr to hold an array, use UniquePtr<T[]> instead");
void**
begin_assignment()
{
assign(0);
return reinterpret_cast<void**>(&mRawPtr);
}
void
assign(T* aNewPtr)
{
T* oldPtr = mRawPtr;
if (aNewPtr && aNewPtr == oldPtr) {
NS_RUNTIMEABORT("Logic flaw in the caller");
}
mRawPtr = aNewPtr;
delete oldPtr;
}
// |class Ptr| helps us prevent implicit "copy construction"
// through |operator T*() const| from a |const nsAutoPtr<T>|
// because two implicit conversions in a row aren't allowed.
// It still allows assignment from T* through implicit conversion
// from |T*| to |nsAutoPtr<T>::Ptr|
class Ptr
{
public:
MOZ_IMPLICIT Ptr(T* aPtr)
: mPtr(aPtr)
{
}
operator T*() const
{
return mPtr;
}
private:
T* MOZ_NON_OWNING_REF mPtr;
};
private:
T* MOZ_OWNING_REF mRawPtr;
public:
typedef T element_type;
~nsAutoPtr()
{
delete mRawPtr;
}
// Constructors
nsAutoPtr()
: mRawPtr(0)
// default constructor
{
}
MOZ_IMPLICIT nsAutoPtr(Ptr aRawPtr)
: mRawPtr(aRawPtr)
// construct from a raw pointer (of the right type)
{
}
// This constructor shouldn't exist; we should just use the &&
// constructor.
nsAutoPtr(nsAutoPtr<T>& aSmartPtr)
: mRawPtr(aSmartPtr.forget())
// Construct by transferring ownership from another smart pointer.
{
}
template <typename I>
MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>& aSmartPtr)
: mRawPtr(aSmartPtr.forget())
// Construct by transferring ownership from another smart pointer.
{
}
nsAutoPtr(nsAutoPtr<T>&& aSmartPtr)
: mRawPtr(aSmartPtr.forget())
// Construct by transferring ownership from another smart pointer.
{
}
template <typename I>
MOZ_IMPLICIT nsAutoPtr(nsAutoPtr<I>&& aSmartPtr)
: mRawPtr(aSmartPtr.forget())
// Construct by transferring ownership from another smart pointer.
{
}
// Assignment operators
nsAutoPtr<T>&
operator=(T* aRhs)
// assign from a raw pointer (of the right type)
{
assign(aRhs);
return *this;
}
nsAutoPtr<T>& operator=(nsAutoPtr<T>& aRhs)
// assign by transferring ownership from another smart pointer.
{
assign(aRhs.forget());
return *this;
}
template <typename I>
nsAutoPtr<T>& operator=(nsAutoPtr<I>& aRhs)
// assign by transferring ownership from another smart pointer.
{
assign(aRhs.forget());
return *this;
}
nsAutoPtr<T>& operator=(nsAutoPtr<T>&& aRhs)
{
assign(aRhs.forget());
return *this;
}
template <typename I>
nsAutoPtr<T>& operator=(nsAutoPtr<I>&& aRhs)
{
assign(aRhs.forget());
return *this;
}
// Other pointer operators
T*
get() const
/*
Prefer the implicit conversion provided automatically by
|operator T*() const|. Use |get()| _only_ to resolve
ambiguity.
*/
{
return mRawPtr;
}
operator T*() const
/*
...makes an |nsAutoPtr| act like its underlying raw pointer
type whenever it is used in a context where a raw pointer
is expected. It is this operator that makes an |nsAutoPtr|
substitutable for a raw pointer.
Prefer the implicit use of this operator to calling |get()|,
except where necessary to resolve ambiguity.
*/
{
return get();
}
T*
forget()
{
T* temp = mRawPtr;
mRawPtr = 0;
return temp;
}
T*
operator->() const
{
NS_PRECONDITION(mRawPtr != 0,
"You can't dereference a NULL nsAutoPtr with operator->().");
return get();
}
template <typename R, typename... Args>
class Proxy
{
typedef R (T::*member_function)(Args...);
T* mRawPtr;
member_function mFunction;
public:
Proxy(T* aRawPtr, member_function aFunction)
: mRawPtr(aRawPtr),
mFunction(aFunction)
{
}
template<typename... ActualArgs>
R operator()(ActualArgs&&... aArgs)
{
return ((*mRawPtr).*mFunction)(mozilla::Forward<ActualArgs>(aArgs)...);
}
};
template <typename R, typename C, typename... Args>
Proxy<R, Args...> operator->*(R (C::*aFptr)(Args...)) const
{
NS_PRECONDITION(mRawPtr != 0,
"You can't dereference a NULL nsAutoPtr with operator->*().");
return Proxy<R, Args...>(get(), aFptr);
}
nsAutoPtr<T>*
get_address()
// This is not intended to be used by clients. See |address_of|
// below.
{
return this;
}
const nsAutoPtr<T>*
get_address() const
// This is not intended to be used by clients. See |address_of|
// below.
{
return this;
}
public:
T&
operator*() const
{
NS_PRECONDITION(mRawPtr != 0,
"You can't dereference a NULL nsAutoPtr with operator*().");
return *get();
}
T**
StartAssignment()
{
#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
return reinterpret_cast<T**>(begin_assignment());
#else
assign(0);
return reinterpret_cast<T**>(&mRawPtr);
#endif
}
};
template <class T>
inline nsAutoPtr<T>*
address_of(nsAutoPtr<T>& aPtr)
{
return aPtr.get_address();
}
template <class T>
inline const nsAutoPtr<T>*
address_of(const nsAutoPtr<T>& aPtr)
{
return aPtr.get_address();
}
template <class T>
class nsAutoPtrGetterTransfers
/*
...
This class is designed to be used for anonymous temporary objects in the
argument list of calls that return COM interface pointers, e.g.,
nsAutoPtr<IFoo> fooP;
...->GetTransferedPointer(getter_Transfers(fooP))
DO NOT USE THIS TYPE DIRECTLY IN YOUR CODE. Use |getter_Transfers()| instead.
When initialized with a |nsAutoPtr|, as in the example above, it returns
a |void**|, a |T**|, or an |nsISupports**| as needed, that the
outer call (|GetTransferedPointer| in this case) can fill in.
This type should be a nested class inside |nsAutoPtr<T>|.
*/
{
public:
explicit
nsAutoPtrGetterTransfers(nsAutoPtr<T>& aSmartPtr)
: mTargetSmartPtr(aSmartPtr)
{
// nothing else to do
}
operator void**()
{
return reinterpret_cast<void**>(mTargetSmartPtr.StartAssignment());
}
operator T**()
{
return mTargetSmartPtr.StartAssignment();
}
T*&
operator*()
{
return *(mTargetSmartPtr.StartAssignment());
}
private:
nsAutoPtr<T>& mTargetSmartPtr;
};
template <class T>
inline nsAutoPtrGetterTransfers<T>
getter_Transfers(nsAutoPtr<T>& aSmartPtr)
/*
Used around a |nsAutoPtr| when
...makes the class |nsAutoPtrGetterTransfers<T>| invisible.
*/
{
return nsAutoPtrGetterTransfers<T>(aSmartPtr);
}
// Comparing two |nsAutoPtr|s
template <class T, class U>
inline bool
operator==(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs)
{
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoPtr<T>& aLhs, const nsAutoPtr<U>& aRhs)
{
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs.get());
}
// Comparing an |nsAutoPtr| to a raw pointer
template <class T, class U>
inline bool
operator==(const nsAutoPtr<T>& aLhs, const U* aRhs)
{
return static_cast<const T*>(aLhs.get()) == static_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator==(const U* aLhs, const nsAutoPtr<T>& aRhs)
{
return static_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoPtr<T>& aLhs, const U* aRhs)
{
return static_cast<const T*>(aLhs.get()) != static_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator!=(const U* aLhs, const nsAutoPtr<T>& aRhs)
{
return static_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator==(const nsAutoPtr<T>& aLhs, U* aRhs)
{
return static_cast<const T*>(aLhs.get()) == const_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator==(U* aLhs, const nsAutoPtr<T>& aRhs)
{
return const_cast<const U*>(aLhs) == static_cast<const T*>(aRhs.get());
}
template <class T, class U>
inline bool
operator!=(const nsAutoPtr<T>& aLhs, U* aRhs)
{
return static_cast<const T*>(aLhs.get()) != const_cast<const U*>(aRhs);
}
template <class T, class U>
inline bool
operator!=(U* aLhs, const nsAutoPtr<T>& aRhs)
{
return const_cast<const U*>(aLhs) != static_cast<const T*>(aRhs.get());
}
// Comparing an |nsAutoPtr| to |nullptr|
template <class T>
inline bool
operator==(const nsAutoPtr<T>& aLhs, decltype(nullptr))
{
return aLhs.get() == nullptr;
}
template <class T>
inline bool
operator==(decltype(nullptr), const nsAutoPtr<T>& aRhs)
{
return nullptr == aRhs.get();
}
template <class T>
inline bool
operator!=(const nsAutoPtr<T>& aLhs, decltype(nullptr))
{
return aLhs.get() != nullptr;
}
template <class T>
inline bool
operator!=(decltype(nullptr), const nsAutoPtr<T>& aRhs)
{
return nullptr != aRhs.get();
}
/*****************************************************************************/
#endif // !defined(nsAutoPtr_h)