Bug 1293985 part 2 - Make EnumerateSubDocuments resilient to adding/removing sub-documents. r=tn a=lizzard
authorMats Palmgren <mats@mozilla.com>
Fri, 19 Aug 2016 19:56:20 +0200
changeset 342412 e454d5a9aa40c7a9ec8d3c8459592e349406a275
parent 342411 7f2fa6e2e0bb1b47a9897ce191a0684adf18d0ac
child 342413 858d5a1cf8956b72c6a120fadddb67dcb853c9e4
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstn, lizzard
bugs1293985
milestone49.0
Bug 1293985 part 2 - Make EnumerateSubDocuments resilient to adding/removing sub-documents. r=tn a=lizzard
dom/base/nsDocument.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -8834,21 +8834,28 @@ struct SubDocEnumArgs
 
 void
 nsDocument::EnumerateSubDocuments(nsSubDocEnumFunc aCallback, void *aData)
 {
   if (!mSubDocuments) {
     return;
   }
 
+  // PLDHashTable::Iterator can't handle modifications while iterating so we
+  // copy all entries to an array first before calling any callbacks.
+  AutoTArray<nsCOMPtr<nsIDocument>, 8> subdocs;
   for (auto iter = mSubDocuments->Iter(); !iter.Done(); iter.Next()) {
     auto entry = static_cast<SubDocMapEntry*>(iter.Get());
     nsIDocument* subdoc = entry->mSubDocument;
-    bool next = subdoc ? aCallback(subdoc, aData) : true;
-    if (!next) {
+    if (subdoc) {
+      subdocs.AppendElement(subdoc);
+    }
+  }
+  for (auto subdoc : subdocs) {
+    if (!aCallback(subdoc, aData)) {
       break;
     }
   }
 }
 
 #ifdef DEBUG_bryner
 #define DEBUG_PAGE_CACHE
 #endif