mirror of
https://github.com/roytam1/UXP.git
synced 2026-05-26 13:58:49 +00:00
Issue #2255 & #1240 - Simplify and enhance Maybe and Some(). https://bugzilla.mozilla.org/show_bug.cgi?id=1325351 This is a prerequisite for our BigInt V8 fast forward and potential #2255 fix.
This commit is contained in:
@@ -588,6 +588,15 @@ class JS_FRIEND_API(AutoEnterPolicy)
|
||||
inline void recordLeave() {}
|
||||
#endif
|
||||
|
||||
private:
|
||||
// This operator needs to be deleted explicitly, otherwise Visual C++ will
|
||||
// create it automatically when it is part of the export JS API. In that
|
||||
// case, compile would fail because HandleId is not allowed to be assigned
|
||||
// and consequently instantiation of assign operator of mozilla::Maybe
|
||||
// would fail. See bug 1325351 comment 16. Copy constructor is removed at
|
||||
// the same time for consistency.
|
||||
AutoEnterPolicy(const AutoEnterPolicy&) = delete;
|
||||
AutoEnterPolicy& operator=(const AutoEnterPolicy&) = delete;
|
||||
};
|
||||
|
||||
#ifdef JS_DEBUG
|
||||
|
||||
+44
-23
@@ -102,16 +102,11 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe<T*> can be copy-constructed from a Maybe<U*> if U* and T* are
|
||||
* compatible, or from Maybe<decltype(nullptr)>.
|
||||
* Maybe<T> can be copy-constructed from a Maybe<U> if U is convertible to T.
|
||||
*/
|
||||
template<typename U,
|
||||
typename =
|
||||
typename std::enable_if<std::is_pointer<T>::value &&
|
||||
(std::is_same<U, decltype(nullptr)>::value ||
|
||||
(std::is_pointer<U>::value &&
|
||||
std::is_base_of<typename std::remove_pointer<T>::type,
|
||||
typename std::remove_pointer<U>::type>::value))>::type>
|
||||
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||
MOZ_IMPLICIT
|
||||
Maybe(const Maybe<U>& aOther)
|
||||
: mIsSome(false)
|
||||
@@ -131,16 +126,11 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe<T*> can be move-constructed from a Maybe<U*> if U* and T* are
|
||||
* compatible, or from Maybe<decltype(nullptr)>.
|
||||
* Maybe<T> can be move-constructed from a Maybe<U> if U is convertible to T.
|
||||
*/
|
||||
template<typename U,
|
||||
typename =
|
||||
typename std::enable_if<std::is_pointer<T>::value &&
|
||||
(std::is_same<U, decltype(nullptr)>::value ||
|
||||
(std::is_pointer<U>::value &&
|
||||
std::is_base_of<typename std::remove_pointer<T>::type,
|
||||
typename std::remove_pointer<U>::type>::value))>::type>
|
||||
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||
MOZ_IMPLICIT
|
||||
Maybe(Maybe<U>&& aOther)
|
||||
: mIsSome(false)
|
||||
@@ -156,13 +146,7 @@ public:
|
||||
if (&aOther != this) {
|
||||
if (aOther.mIsSome) {
|
||||
if (mIsSome) {
|
||||
// XXX(seth): The correct code for this branch, below, can't be used
|
||||
// due to a bug in Visual Studio 2010. See bug 1052940.
|
||||
/*
|
||||
ref() = aOther.ref();
|
||||
*/
|
||||
reset();
|
||||
emplace(*aOther);
|
||||
} else {
|
||||
emplace(*aOther);
|
||||
}
|
||||
@@ -173,6 +157,23 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U,
|
||||
typename =
|
||||
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||
Maybe& operator=(const Maybe<U>& aOther)
|
||||
{
|
||||
if (aOther.isSome()) {
|
||||
if (mIsSome) {
|
||||
ref() = aOther.ref();
|
||||
} else {
|
||||
emplace(*aOther);
|
||||
}
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Maybe& operator=(Maybe&& aOther)
|
||||
{
|
||||
MOZ_ASSERT(this != &aOther, "Self-moves are prohibited");
|
||||
@@ -191,6 +192,25 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename U,
|
||||
typename =
|
||||
typename std::enable_if<std::is_convertible<U, T>::value>::type>
|
||||
Maybe& operator=(Maybe<U>&& aOther)
|
||||
{
|
||||
if (aOther.isSome()) {
|
||||
if (mIsSome) {
|
||||
ref() = Move(aOther.ref());
|
||||
} else {
|
||||
emplace(Move(*aOther));
|
||||
}
|
||||
aOther.reset();
|
||||
} else {
|
||||
reset();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* Methods that check whether this Maybe contains a value */
|
||||
explicit operator bool() const { return isSome(); }
|
||||
bool isSome() const { return mIsSome; }
|
||||
@@ -443,11 +463,12 @@ public:
|
||||
* if you need to construct a Maybe value that holds a const, volatile, or
|
||||
* reference value, you need to use emplace() instead.
|
||||
*/
|
||||
template<typename T>
|
||||
Maybe<typename RemoveCV<typename RemoveReference<T>::Type>::Type>
|
||||
template<typename T,
|
||||
typename U = typename std::remove_cv<
|
||||
typename std::remove_reference<T>::type>::type>
|
||||
Maybe<U>
|
||||
Some(T&& aValue)
|
||||
{
|
||||
typedef typename RemoveCV<typename RemoveReference<T>::Type>::Type U;
|
||||
Maybe<U> value;
|
||||
value.emplace(Forward<T>(aValue));
|
||||
return value;
|
||||
|
||||
Reference in New Issue
Block a user