diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -877,27 +877,31 @@ public:
     return *reinterpret_cast<const FallibleTArray<E>*>(this);
   }
 
   // The array's assignment operator performs a 'deep' copy of the given
   // array.  It is optimized to reuse existing storage if possible.
   // @param aOther The array object to copy.
   self_type& operator=(const self_type& aOther)
   {
-    ReplaceElementsAt(0, Length(), aOther.Elements(), aOther.Length());
+    if (this != &aOther) {
+      ReplaceElementsAt(0, Length(), aOther.Elements(), aOther.Length());
+    }
     return *this;
   }
 
   // The array's move assignment operator steals the underlying data from
   // the other array.
   // @param other  The array object to move from.
   self_type& operator=(self_type&& aOther)
   {
-    Clear();
-    SwapElements(aOther);
+    if (this != &aOther) {
+      Clear();
+      SwapElements(aOther);
+    }
     return *this;
   }
 
   // Return true if this array has the same length and the same
   // elements as |aOther|.
   template<typename Allocator>
   bool operator==(const nsTArray_Impl<E, Allocator>& aOther) const
   {
diff --git a/xpcom/tests/gtest/TestTArray.cpp b/xpcom/tests/gtest/TestTArray.cpp
--- a/xpcom/tests/gtest/TestTArray.cpp
+++ b/xpcom/tests/gtest/TestTArray.cpp
@@ -30,17 +30,17 @@ const nsTArray<int>& FakeHugeArray()
   if (sArray.IsEmpty()) {
     sArray.AppendElement();
     ((nsTArrayHeader*)sArray.DebugGetHeader())->mLength = UINT32_MAX;
   }
   return sArray;
 }
 #endif
 
-TEST(TArray, assign)
+TEST(TArray, Assign)
 {
   nsTArray<int> array;
   array.Assign(DummyArray());
   ASSERT_EQ(DummyArray(), array);
 
   ASSERT_TRUE(array.Assign(DummyArray(), fallible));
   ASSERT_EQ(DummyArray(), array);
 
@@ -49,9 +49,20 @@ TEST(TArray, assign)
 #endif
 
   nsTArray<int> array2;
   array2.Assign(Move(array));
   ASSERT_TRUE(array.IsEmpty());
   ASSERT_EQ(DummyArray(), array2);
 }
 
+TEST(TArray, AssignmentOperatorSelfAssignment)
+{
+  nsTArray<int> array;
+  array = DummyArray();
+
+  array = array;
+  ASSERT_EQ(DummyArray(), array);
+  array = Move(array);
+  ASSERT_EQ(DummyArray(), array);
+}
+
 } // namespace TestTArray