diff --git a/js/public/RootingAPI.h b/js/public/RootingAPI.h index 528a15ae1f18..81a9f3020b6f 100644 --- a/js/public/RootingAPI.h +++ b/js/public/RootingAPI.h @@ -237,7 +237,7 @@ AssertGCThingIsNotAnObjectSubclass(js::gc::Cell* cell) {} * Type T must be a public GC pointer type. */ template -class Heap : public js::HeapBase> +class MOZ_NON_MEMMOVABLE Heap : public js::HeapBase> { // Please note: this can actually also be used by nsXBLMaybeCompiled, for legacy reasons. static_assert(js::IsHeapConstructibleType::value, @@ -1173,6 +1173,14 @@ class JS_PUBLIC_API(ObjectPtr) explicit ObjectPtr(JSObject* obj) : value(obj) {} + ObjectPtr(const ObjectPtr& other) : value(other.value) {} + + ObjectPtr(ObjectPtr&& other) + : value(other.value) + { + other.value = nullptr; + } + /* Always call finalize before the destructor. */ ~ObjectPtr() { MOZ_ASSERT(!value); } diff --git a/js/src/gc/Barrier.h b/js/src/gc/Barrier.h index b0486f94949d..dc6af50bb079 100644 --- a/js/src/gc/Barrier.h +++ b/js/src/gc/Barrier.h @@ -318,8 +318,11 @@ struct InternalBarrierMethods }; // Base class of all barrier types. +// +// This is marked non-memmovable since post barriers added by derived classes +// can add pointers to class instances to the store buffer. template -class BarrieredBase +class MOZ_NON_MEMMOVABLE BarrieredBase { protected: // BarrieredBase is not directly instantiable. diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h index 424a50ba421e..4e9b57126bfb 100644 --- a/xpcom/ds/nsTArray.h +++ b/xpcom/ds/nsTArray.h @@ -37,6 +37,7 @@ namespace JS { template class Heap; +class ObjectPtr; } /* namespace JS */ class nsRegion; @@ -708,7 +709,7 @@ struct nsTArray_CopyWithConstructors template struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_CopyChooser { - typedef nsTArray_CopyWithMemutils Type; + using Type = nsTArray_CopyWithMemutils; }; // @@ -719,14 +720,18 @@ struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_CopyChooser template<> \ struct nsTArray_CopyChooser \ { \ - typedef nsTArray_CopyWithConstructors Type; \ + using Type = nsTArray_CopyWithConstructors; \ }; -template -struct nsTArray_CopyChooser> -{ - typedef nsTArray_CopyWithConstructors> Type; -}; +#define DECLARE_USE_COPY_CONSTRUCTORS_FOR_TEMPLATE(T) \ + template \ + struct nsTArray_CopyChooser> \ + { \ + using Type = nsTArray_CopyWithConstructors>; \ + }; + +DECLARE_USE_COPY_CONSTRUCTORS_FOR_TEMPLATE(JS::Heap) +DECLARE_USE_COPY_CONSTRUCTORS_FOR_TEMPLATE(std::function) DECLARE_USE_COPY_CONSTRUCTORS(nsRegion) DECLARE_USE_COPY_CONSTRUCTORS(nsIntRegion) @@ -740,13 +745,7 @@ DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::indexedDB::SerializedStructuredClone DECLARE_USE_COPY_CONSTRUCTORS(JSStructuredCloneData) DECLARE_USE_COPY_CONSTRUCTORS(mozilla::dom::MessagePortMessage) DECLARE_USE_COPY_CONSTRUCTORS(mozilla::SourceBufferTask) - -template -struct nsTArray_CopyChooser> -{ - typedef nsTArray_CopyWithConstructors> Type; -}; - +DECLARE_USE_COPY_CONSTRUCTORS(JS::ObjectPtr) // // Base class for nsTArray_Impl that is templated on element type and derived