Issue #1742 - Part 1: Refactor rooting base class templates

Based on Bug 1325406
This commit is contained in:
Moonchild 2022-05-24 06:51:11 +00:00 committed by roytam1
commit 80d7d43961
24 changed files with 239 additions and 512 deletions

View file

@ -1340,20 +1340,18 @@ struct BarrierMethods<JS::Value>
}
};
template <class Outer> class MutableValueOperations;
template <class Wrapper> class MutableValueOperations;
/**
* A class designed for CRTP use in implementing the non-mutating parts of the
* Value interface in Value-like classes. Outer must be a class inheriting
* ValueOperations<Outer> with a visible get() method returning a const
* reference to the Value abstracted by Outer.
* Value interface in Value-like classes. Wrapper must be a class inheriting
* ValueOperations<Wrapper> with a visible get() method returning a const
* reference to the Value abstracted by Wrapper.
*/
template <class Outer>
class ValueOperations
template <class Wrapper>
class WrappedPtrOperations<JS::Value, Wrapper>
{
friend class MutableValueOperations<Outer>;
const JS::Value& value() const { return static_cast<const Outer*>(this)->get(); }
const JS::Value& value() const { return static_cast<const Wrapper*>(this)->get(); }
public:
bool isUndefined() const { return value().isUndefined(); }
@ -1398,17 +1396,17 @@ class ValueOperations
/**
* A class designed for CRTP use in implementing all the mutating parts of the
* Value interface in Value-like classes. Outer must be a class inheriting
* MutableValueOperations<Outer> with visible get() methods returning const and
* non-const references to the Value abstracted by Outer.
* Value interface in Value-like classes. Wrapper must be a class inheriting
* MutableWrappedPtrOperations<Wrapper> with visible get() methods returning const and
* non-const references to the Value abstracted by Wrapper.
*/
template <class Outer>
class MutableValueOperations : public ValueOperations<Outer>
template <class Wrapper>
class MutableWrappedPtrOperations<JS::Value, Wrapper> : public WrappedPtrOperations<JS::Value, Wrapper>
{
protected:
void set(const JS::Value& v) {
// Call Outer::set to trigger any barriers.
static_cast<Outer*>(this)->set(v);
static_cast<Wrapper*>(this)->set(v);
}
public:
@ -1434,13 +1432,9 @@ class MutableValueOperations : public ValueOperations<Outer>
* Augment the generic Heap<T> interface when T = Value with
* type-querying, value-extracting, and mutating operations.
*/
template <>
class HeapBase<JS::Value> : public MutableValueOperations<JS::Heap<JS::Value> >
template <typename Wrapper>
class HeapBase<JS::Value, Wrapper> : public MutableWrappedPtrOperations<JS::Value, Wrapper>
{
typedef JS::Heap<JS::Value> Outer;
friend class ValueOperations<Outer>;
public:
void setNumber(uint32_t ui) {
if (ui > JSVAL_INT_MAX) {
@ -1460,22 +1454,6 @@ class HeapBase<JS::Value> : public MutableValueOperations<JS::Heap<JS::Value> >
}
};
template <>
class HandleBase<JS::Value> : public ValueOperations<JS::Handle<JS::Value> >
{};
template <>
class MutableHandleBase<JS::Value> : public MutableValueOperations<JS::MutableHandle<JS::Value> >
{};
template <>
class RootedBase<JS::Value> : public MutableValueOperations<JS::Rooted<JS::Value> >
{};
template <>
class PersistentRootedBase<JS::Value> : public MutableValueOperations<JS::PersistentRooted<JS::Value>>
{};
/*
* If the Value is a GC pointer type, convert to that type and call |f| with
* the pointer. If the Value is not a GC type, calls F::defaultValue.