From 42bd74780cb9f0d7fff5f4603dba4f40e3074593 Mon Sep 17 00:00:00 2001 From: Yoshi Huang Date: Thu, 21 Sep 2017 18:42:18 +0800 Subject: [PATCH] Bug 1399399 - Move internal classes out of RootingAPI.h. r=jonco --- js/public/RootingAPI.h | 87 +++--------------------------------------- js/src/gc/Rooting.h | 79 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 81 deletions(-) diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index 74a61af93703..e19f162702f8 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -142,6 +142,12 @@ FOR_EACH_PUBLIC_TAGGED_GC_POINTER_TYPE(DECLARE_IS_HEAP_CONSTRUCTIBLE_TYPE) template class PersistentRootedBase : public MutableWrappedPtrOperations {}; +template +class FakeRooted; + +template +class FakeMutableHandle; + namespace gc { struct Cell; template @@ -904,64 +910,6 @@ class HandleBase : public WrappedPtrOperations as() const; }; -/** Interface substitute for Rooted which does not root the variable's memory. */ -template -class MOZ_RAII FakeRooted : public RootedBase> -{ - public: - using ElementType = T; - - template - explicit FakeRooted(CX* cx) : ptr(JS::GCPolicy::initial()) {} - - template - FakeRooted(CX* cx, T initial) : ptr(initial) {} - - DECLARE_POINTER_CONSTREF_OPS(T); - DECLARE_POINTER_ASSIGN_OPS(FakeRooted, T); - DECLARE_NONPOINTER_ACCESSOR_METHODS(ptr); - DECLARE_NONPOINTER_MUTABLE_ACCESSOR_METHODS(ptr); - - private: - T ptr; - - void set(const T& value) { - ptr = value; - } - - FakeRooted(const FakeRooted&) = delete; -}; - -/** Interface substitute for MutableHandle which is not required to point to rooted memory. */ -template -class FakeMutableHandle : public js::MutableHandleBase> -{ - public: - using ElementType = T; - - MOZ_IMPLICIT FakeMutableHandle(T* t) { - ptr = t; - } - - MOZ_IMPLICIT FakeMutableHandle(FakeRooted* root) { - ptr = root->address(); - } - - void set(const T& v) { - *ptr = v; - } - - DECLARE_POINTER_CONSTREF_OPS(T); - DECLARE_NONPOINTER_ACCESSOR_METHODS(*ptr); - DECLARE_NONPOINTER_MUTABLE_ACCESSOR_METHODS(*ptr); - - private: - FakeMutableHandle() {} - DELETE_ASSIGNMENT_OPS(FakeMutableHandle, T); - - T* ptr; -}; - /** * Types for a variable that either should or shouldn't be rooted, depending on * the template parameter allowGC. Used for implementing functions that can @@ -1001,27 +949,6 @@ template class MaybeRooted } }; -template class MaybeRooted -{ - public: - typedef const T& HandleType; - typedef FakeRooted RootType; - typedef FakeMutableHandle MutableHandleType; - - static JS::Handle toHandle(HandleType v) { - MOZ_CRASH("Bad conversion"); - } - - static JS::MutableHandle toMutableHandle(MutableHandleType v) { - MOZ_CRASH("Bad conversion"); - } - - template - static inline T2* downcastHandle(HandleType v) { - return &v->template as(); - } -}; - } /* namespace js */ namespace JS { @@ -1519,6 +1446,4 @@ operator!=(const T& a, std::nullptr_t b) { return !(a == b); } -#undef DELETE_ASSIGNMENT_OPS - #endif /* js_RootingAPI_h */ diff --git a/js/src/gc/Rooting.h b/js/src/gc/Rooting.h index 941dc20082f4..a8f8188c352a 100644 --- a/js/src/gc/Rooting.h +++ b/js/src/gc/Rooting.h @@ -81,6 +81,85 @@ typedef JS::GCVector PropertyNameVector; typedef JS::GCVector ShapeVector; typedef JS::GCVector StringVector; +/** Interface substitute for Rooted which does not root the variable's memory. */ +template +class MOZ_RAII FakeRooted : public RootedBase> +{ + public: + using ElementType = T; + + template + explicit FakeRooted(CX* cx) : ptr(JS::GCPolicy::initial()) {} + + template + FakeRooted(CX* cx, T initial) : ptr(initial) {} + + DECLARE_POINTER_CONSTREF_OPS(T); + DECLARE_POINTER_ASSIGN_OPS(FakeRooted, T); + DECLARE_NONPOINTER_ACCESSOR_METHODS(ptr); + DECLARE_NONPOINTER_MUTABLE_ACCESSOR_METHODS(ptr); + + private: + T ptr; + + void set(const T& value) { + ptr = value; + } + + FakeRooted(const FakeRooted&) = delete; +}; + +/** Interface substitute for MutableHandle which is not required to point to rooted memory. */ +template +class FakeMutableHandle : public js::MutableHandleBase> +{ + public: + using ElementType = T; + + MOZ_IMPLICIT FakeMutableHandle(T* t) { + ptr = t; + } + + MOZ_IMPLICIT FakeMutableHandle(FakeRooted* root) { + ptr = root->address(); + } + + void set(const T& v) { + *ptr = v; + } + + DECLARE_POINTER_CONSTREF_OPS(T); + DECLARE_NONPOINTER_ACCESSOR_METHODS(*ptr); + DECLARE_NONPOINTER_MUTABLE_ACCESSOR_METHODS(*ptr); + + private: + FakeMutableHandle() {} + DELETE_ASSIGNMENT_OPS(FakeMutableHandle, T); + + T* ptr; +}; + +template class MaybeRooted +{ + public: + typedef const T& HandleType; + typedef FakeRooted RootType; + typedef FakeMutableHandle MutableHandleType; + + static JS::Handle toHandle(HandleType v) { + MOZ_CRASH("Bad conversion"); + } + + static JS::MutableHandle toMutableHandle(MutableHandleType v) { + MOZ_CRASH("Bad conversion"); + } + + template + static inline T2* downcastHandle(HandleType v) { + return &v->template as(); + } +}; + } /* namespace js */ #endif /* gc_Rooting_h */