1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

Issue #2259 - Add JS::StackGCVector and JS::RootedVector

Based-on: m-c 1521732/{1,3}, 1527881
This commit is contained in:
Martok
2023-06-18 16:42:14 +02:00
committed by roytam1
parent 4c2e378613
commit f8f7aed528
3 changed files with 54 additions and 1 deletions
+35 -1
View File
@@ -130,6 +130,17 @@ class GCVector
}
};
// AllocPolicy is optional. It has a default value declared in TypeDecls.h
template <typename T, typename AllocPolicy>
class MOZ_STACK_CLASS StackGCVector : public GCVector<T, 8, AllocPolicy> {
public:
using Base = GCVector<T, 8, AllocPolicy>;
private:
// Inherit constructor from GCVector.
using Base::Base;
};
} // namespace JS
namespace js {
@@ -191,7 +202,7 @@ class MutableWrappedPtrOperations<JS::GCVector<T, Capacity, AllocPolicy>, Wrappe
void clearAndFree() { vec().clearAndFree(); }
template<typename U> bool append(U&& aU) { return vec().append(mozilla::Forward<U>(aU)); }
template<typename... Args> bool emplaceBack(Args&&... aArgs) {
return vec().emplaceBack(mozilla::Forward<Args...>(aArgs...));
return vec().emplaceBack(mozilla::Forward<Args>(aArgs)...);
}
template<typename U, size_t O, class BP>
bool appendAll(const mozilla::Vector<U, O, BP>& aU) { return vec().appendAll(aU); }
@@ -223,6 +234,29 @@ class MutableWrappedPtrOperations<JS::GCVector<T, Capacity, AllocPolicy>, Wrappe
void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); }
};
template <typename Wrapper, typename T, typename AllocPolicy>
class WrappedPtrOperations<JS::StackGCVector<T, AllocPolicy>, Wrapper> :
public WrappedPtrOperations<typename JS::StackGCVector<T, AllocPolicy>::Base,
Wrapper> {};
template <typename Wrapper, typename T, typename AllocPolicy>
class MutableWrappedPtrOperations<JS::StackGCVector<T, AllocPolicy>, Wrapper> :
public MutableWrappedPtrOperations<typename JS::StackGCVector<T, AllocPolicy>::Base,
Wrapper> {};
} // namespace js
namespace JS {
// An automatically rooted GCVector for stack use.
template <typename T>
class RootedVector : public Rooted<StackGCVector<T>> {
using Vec = StackGCVector<T>;
using Base = Rooted<Vec>;
public:
explicit RootedVector(JSContext* cx) : Base(cx, Vec(cx)) {}
};
} // namespace JS
#endif // js_GCVector_h
+15
View File
@@ -30,6 +30,10 @@ class JSAddonId;
struct jsid;
namespace js {
class TempAllocPolicy;
}; // namespace js
namespace JS {
typedef unsigned char Latin1Char;
@@ -40,6 +44,8 @@ template <typename T> class Handle;
template <typename T> class MutableHandle;
template <typename T> class Rooted;
template <typename T> class PersistentRooted;
template <typename T> class RootedVector;
template <typename T, typename AllocPolicy = js::TempAllocPolicy> class StackGCVector;
typedef Handle<JSFunction*> HandleFunction;
typedef Handle<jsid> HandleId;
@@ -48,6 +54,7 @@ typedef Handle<JSScript*> HandleScript;
typedef Handle<JSString*> HandleString;
typedef Handle<JS::Symbol*> HandleSymbol;
typedef Handle<Value> HandleValue;
typedef Handle<StackGCVector<Value>> HandleValueVector;
typedef MutableHandle<JSFunction*> MutableHandleFunction;
typedef MutableHandle<jsid> MutableHandleId;
@@ -56,6 +63,7 @@ typedef MutableHandle<JSScript*> MutableHandleScript;
typedef MutableHandle<JSString*> MutableHandleString;
typedef MutableHandle<JS::Symbol*> MutableHandleSymbol;
typedef MutableHandle<Value> MutableHandleValue;
typedef MutableHandle<StackGCVector<Value>> MutableHandleValueVector;
typedef Rooted<JSObject*> RootedObject;
typedef Rooted<JSFunction*> RootedFunction;
@@ -65,6 +73,8 @@ typedef Rooted<JS::Symbol*> RootedSymbol;
typedef Rooted<jsid> RootedId;
typedef Rooted<JS::Value> RootedValue;
typedef RootedVector<JS::Value> RootedValueVector;
typedef PersistentRooted<JSFunction*> PersistentRootedFunction;
typedef PersistentRooted<jsid> PersistentRootedId;
typedef PersistentRooted<JSObject*> PersistentRootedObject;
@@ -73,6 +83,11 @@ typedef PersistentRooted<JSString*> PersistentRootedString;
typedef PersistentRooted<JS::Symbol*> PersistentRootedSymbol;
typedef PersistentRooted<Value> PersistentRootedValue;
template <typename T>
using HandleVector = Handle<StackGCVector<T>>;
template <typename T>
using MutableHandleVector = MutableHandle<StackGCVector<T>>;
} // namespace JS
#endif /* js_TypeDecls_h */
+4
View File
@@ -90,6 +90,10 @@ using JS::AutoValueVector;
using JS::AutoIdVector;
using JS::AutoObjectVector;
using JS::RootedValueVector;
using JS::HandleValueVector;
using JS::MutableHandleValueVector;
using JS::ValueVector;
using JS::IdVector;
using JS::ScriptVector;