diff --git a/xpcom/base/nsMaybeWeakPtr.h b/xpcom/base/nsMaybeWeakPtr.h index c2d0376259d5..165a8c23c182 100644 --- a/xpcom/base/nsMaybeWeakPtr.h +++ b/xpcom/base/nsMaybeWeakPtr.h @@ -54,7 +54,7 @@ class nsMaybeWeakPtr { // given object to appear in the array once. template -class nsMaybeWeakPtrArray : public nsTArray> { +class nsMaybeWeakPtrArray : public CopyableTArray> { typedef nsTArray> MaybeWeakArray; nsresult SetMaybeWeakPtr(nsMaybeWeakPtr& aRef, T* aElement, diff --git a/xpcom/ds/nsTObserverArray.h b/xpcom/ds/nsTObserverArray.h index 89d4e7406c7b..9b488704d2b7 100644 --- a/xpcom/ds/nsTObserverArray.h +++ b/xpcom/ds/nsTObserverArray.h @@ -410,6 +410,12 @@ class nsTObserverArray : public nsAutoTObserverArray { explicit nsTObserverArray(size_type aCapacity) { base_type::mArray.SetCapacity(aCapacity); } + + nsTObserverArray Clone() const { + auto result = nsTObserverArray{}; + result.mArray.Assign(this->mArray); + return result; + } }; template diff --git a/xpcom/ds/nsTPriorityQueue.h b/xpcom/ds/nsTPriorityQueue.h index c3397365a0db..b5a02957c018 100644 --- a/xpcom/ds/nsTPriorityQueue.h +++ b/xpcom/ds/nsTPriorityQueue.h @@ -146,7 +146,7 @@ class nsTPriorityQueue { mElements[aIndexB] = temp; } - nsTArray mElements; + CopyableTArray mElements; Compare mCompare; // Comparator object }; diff --git a/xpcom/io/nsPipe3.cpp b/xpcom/io/nsPipe3.cpp index 9c0ab794e9d0..93b102457bdd 100644 --- a/xpcom/io/nsPipe3.cpp +++ b/xpcom/io/nsPipe3.cpp @@ -939,7 +939,7 @@ void nsPipe::OnPipeException(nsresult aReason, bool aOutputOnly) { // OnInputException() can drain the stream and remove it from // mInputList. So iterate over a temp list instead. - nsTArray list(mInputList); + nsTArray list = mInputList.Clone(); for (uint32_t i = 0; i < list.Length(); ++i) { // an output-only exception applies to the input end if the pipe has // zero bytes available. diff --git a/xpcom/tests/gtest/TestTArray.cpp b/xpcom/tests/gtest/TestTArray.cpp index bed33bbc40fa..30655dc01afc 100644 --- a/xpcom/tests/gtest/TestTArray.cpp +++ b/xpcom/tests/gtest/TestTArray.cpp @@ -119,7 +119,7 @@ TEST(TArray, int_AppendElements_TArray_Copy) { nsTArray array; - const nsTArray temp(DummyArray()); + const nsTArray temp(DummyArray().Clone()); int* ptr = array.AppendElements(temp); ASSERT_EQ(&array[0], ptr); ASSERT_EQ(DummyArray(), array); @@ -138,7 +138,7 @@ TEST(TArray, int_AppendElements_TArray_Copy_Fallible) { nsTArray array; - const nsTArray temp(DummyArray()); + const nsTArray temp(DummyArray().Clone()); int* ptr = array.AppendElements(temp, fallible); ASSERT_EQ(&array[0], ptr); ASSERT_EQ(DummyArray(), array); @@ -157,13 +157,13 @@ TEST(TArray, int_AppendElements_TArray_Rvalue) { nsTArray array; - nsTArray temp(DummyArray()); + nsTArray temp(DummyArray().Clone()); int* ptr = array.AppendElements(std::move(temp)); ASSERT_EQ(&array[0], ptr); ASSERT_EQ(DummyArray(), array); ASSERT_TRUE(temp.IsEmpty()); - temp = DummyArray(); + temp = DummyArray().Clone(); ptr = array.AppendElements(std::move(temp)); ASSERT_EQ(&array[DummyArray().Length()], ptr); nsTArray expected; @@ -177,13 +177,13 @@ TEST(TArray, int_AppendElements_TArray_Rvalue_Fallible) { nsTArray array; - nsTArray temp(DummyArray()); + nsTArray temp(DummyArray().Clone()); int* ptr = array.AppendElements(std::move(temp), fallible); ASSERT_EQ(&array[0], ptr); ASSERT_EQ(DummyArray(), array); ASSERT_TRUE(temp.IsEmpty()); - temp = DummyArray(); + temp = DummyArray().Clone(); ptr = array.AppendElements(std::move(temp), fallible); ASSERT_EQ(&array[DummyArray().Length()], ptr); nsTArray expected; @@ -239,7 +239,7 @@ TEST(TArray, AppendElementsSpan) { nsTArray array; - nsTArray temp(DummyArray()); + nsTArray temp(DummyArray().Clone()); Span span = temp; array.AppendElements(span); ASSERT_EQ(DummyArray(), array); @@ -489,7 +489,7 @@ TEST(TArray, int_Assign) TEST(TArray, int_AssignmentOperatorSelfAssignment) { - nsTArray array; + CopyableTArray array; array = DummyArray(); array = *&array; diff --git a/xpcom/tests/gtest/TestTArray2.cpp b/xpcom/tests/gtest/TestTArray2.cpp index 82a647f40a77..139f2d66c419 100644 --- a/xpcom/tests/gtest/TestTArray2.cpp +++ b/xpcom/tests/gtest/TestTArray2.cpp @@ -35,7 +35,7 @@ inline bool operator<(const nsCOMPtr& lhs, const nsCOMPtr& rhs) { template static bool test_basic_array(ElementType* data, size_t dataLen, const ElementType& extra) { - nsTArray ary; + CopyableTArray ary; const nsTArray& cary = ary; ary.AppendElements(data, dataLen); @@ -143,7 +143,7 @@ static bool test_basic_array(ElementType* data, size_t dataLen, []() { return false; })) return false; - nsTArray copy(ary); + nsTArray copy(ary.Clone()); if (!(ary == copy)) return false; for (i = 0; i < copy.Length(); ++i) { if (ary[i] != copy[i]) return false; @@ -380,7 +380,7 @@ TEST(TArray, test_move_array) ASSERT_EQ(Countable::Count(), 8); - nsTArray copyCountableArray(constRefCountableArray); + nsTArray copyCountableArray(constRefCountableArray.Clone()); ASSERT_EQ(Countable::Count(), 12); @@ -426,7 +426,7 @@ TEST(TArray, test_move_array) ASSERT_EQ(Moveable::Count(), 4); - nsTArray copyMoveableArray(constRefMoveableArray); + nsTArray copyMoveableArray(constRefMoveableArray.Clone()); ASSERT_EQ(Moveable::Count(), 8);