Bug 1315885 - Part 3: Transfer the ownership of ReactionQueue's entry due to re-enter CustomElementReactionsStack::InvokeReactions. r=wchen
authorJohn Dai <jdai@mozilla.com>
Mon, 10 Jul 2017 01:40:00 -0400
changeset 418406 7366a7028d98b508a130687dfd6e1cc1d0a360d0
parent 418405 60f70ae7c82df8329d4cc9bacb31bb5762d46f80
child 418407 62294b20e47f230ebeb09b117c74e4843010eb2f
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1315885
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1315885 - Part 3: Transfer the ownership of ReactionQueue's entry due to re-enter CustomElementReactionsStack::InvokeReactions. r=wchen
dom/base/CustomElementRegistry.cpp
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -983,30 +983,35 @@ CustomElementReactionsStack::InvokeBacku
   if (!mBackupQueue.IsEmpty()) {
     InvokeReactions(mBackupQueue);
   }
 }
 
 void
 CustomElementReactionsStack::InvokeReactions(ElementQueue& aElementQueue)
 {
+  // Note: It's possible to re-enter this method.
   for (uint32_t i = 0; i < aElementQueue.Length(); ++i) {
     nsCOMPtr<Element> element = do_QueryReferent(aElementQueue[i]);
 
     if (!element) {
       continue;
     }
 
     RefPtr<CustomElementData> elementData = element->GetCustomElementData();
     MOZ_ASSERT(elementData, "CustomElementData should exist");
 
-    nsTArray<nsAutoPtr<CustomElementReaction>>& reactions =
-      elementData->mReactionQueue;
+    auto& reactions = elementData->mReactionQueue;
     for (uint32_t j = 0; j < reactions.Length(); ++j) {
-      reactions.ElementAt(j)->Invoke(element);
+      // Transfer the ownership of the entry due to reentrant invocation of
+      // this funciton. The entry will be removed when bug 1379573 is landed.
+      auto reaction(Move(reactions.ElementAt(j)));
+      if (reaction) {
+        reaction->Invoke(element);
+      }
     }
     reactions.Clear();
   }
   aElementQueue.Clear();
 }
 
 //-----------------------------------------------------
 // CustomElementDefinition