From f8f7aed528e155b3571c68fd47bc36b72f680500 Mon Sep 17 00:00:00 2001 From: Martok Date: Sun, 18 Jun 2023 16:42:14 +0200 Subject: [PATCH] Issue #2259 - Add JS::StackGCVector and JS::RootedVector Based-on: m-c 1521732/{1,3}, 1527881 --- js/public/GCVector.h | 36 +++++++++++++++++++++++++++++++++++- js/public/TypeDecls.h | 15 +++++++++++++++ js/src/NamespaceImports.h | 4 ++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/js/public/GCVector.h b/js/public/GCVector.h index 4acf0d1fc5..a92969b576 100644 --- a/js/public/GCVector.h +++ b/js/public/GCVector.h @@ -130,6 +130,17 @@ class GCVector } }; +// AllocPolicy is optional. It has a default value declared in TypeDecls.h +template +class MOZ_STACK_CLASS StackGCVector : public GCVector { + public: + using Base = GCVector; + + private: + // Inherit constructor from GCVector. + using Base::Base; +}; + } // namespace JS namespace js { @@ -191,7 +202,7 @@ class MutableWrappedPtrOperations, Wrappe void clearAndFree() { vec().clearAndFree(); } template bool append(U&& aU) { return vec().append(mozilla::Forward(aU)); } template bool emplaceBack(Args&&... aArgs) { - return vec().emplaceBack(mozilla::Forward(aArgs...)); + return vec().emplaceBack(mozilla::Forward(aArgs)...); } template bool appendAll(const mozilla::Vector& aU) { return vec().appendAll(aU); } @@ -223,6 +234,29 @@ class MutableWrappedPtrOperations, Wrappe void erase(T* aBegin, T* aEnd) { vec().erase(aBegin, aEnd); } }; +template +class WrappedPtrOperations, Wrapper> : + public WrappedPtrOperations::Base, + Wrapper> {}; + +template +class MutableWrappedPtrOperations, Wrapper> : + public MutableWrappedPtrOperations::Base, + Wrapper> {}; + } // namespace js +namespace JS { + +// An automatically rooted GCVector for stack use. +template +class RootedVector : public Rooted> { + using Vec = StackGCVector; + using Base = Rooted; + + public: + explicit RootedVector(JSContext* cx) : Base(cx, Vec(cx)) {} +}; + +} // namespace JS #endif // js_GCVector_h diff --git a/js/public/TypeDecls.h b/js/public/TypeDecls.h index 40d6f1f8a4..2b36ed95b9 100644 --- a/js/public/TypeDecls.h +++ b/js/public/TypeDecls.h @@ -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 class Handle; template class MutableHandle; template class Rooted; template class PersistentRooted; +template class RootedVector; +template class StackGCVector; typedef Handle HandleFunction; typedef Handle HandleId; @@ -48,6 +54,7 @@ typedef Handle HandleScript; typedef Handle HandleString; typedef Handle HandleSymbol; typedef Handle HandleValue; +typedef Handle> HandleValueVector; typedef MutableHandle MutableHandleFunction; typedef MutableHandle MutableHandleId; @@ -56,6 +63,7 @@ typedef MutableHandle MutableHandleScript; typedef MutableHandle MutableHandleString; typedef MutableHandle MutableHandleSymbol; typedef MutableHandle MutableHandleValue; +typedef MutableHandle> MutableHandleValueVector; typedef Rooted RootedObject; typedef Rooted RootedFunction; @@ -65,6 +73,8 @@ typedef Rooted RootedSymbol; typedef Rooted RootedId; typedef Rooted RootedValue; +typedef RootedVector RootedValueVector; + typedef PersistentRooted PersistentRootedFunction; typedef PersistentRooted PersistentRootedId; typedef PersistentRooted PersistentRootedObject; @@ -73,6 +83,11 @@ typedef PersistentRooted PersistentRootedString; typedef PersistentRooted PersistentRootedSymbol; typedef PersistentRooted PersistentRootedValue; + +template +using HandleVector = Handle>; +template +using MutableHandleVector = MutableHandle>; } // namespace JS #endif /* js_TypeDecls_h */ diff --git a/js/src/NamespaceImports.h b/js/src/NamespaceImports.h index e25e0bd6f4..a1d8bca1c3 100644 --- a/js/src/NamespaceImports.h +++ b/js/src/NamespaceImports.h @@ -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;