Backed out changeset 1ca5723f69d4 (bug 1186780) for dom crashes
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Mon, 27 Jul 2015 08:01:09 +0200
changeset 254683 d1df3bc0b4fda6e61fad6c6e96eedcb3b77cdae8
parent 254682 f388b16123561fa8305e432a66132c4ac397c625
child 254684 443625267e009568d990bef1f966ba9a1e473284
push id16714
push userryanvm@gmail.com
push dateMon, 27 Jul 2015 14:43:15 +0000
treeherderb2g-inbound@d576f2cec511 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1186780
milestone42.0a1
backs out1ca5723f69d4af4cd3492c4bb8d3a06bd1fed774
Backed out changeset 1ca5723f69d4 (bug 1186780) for dom crashes
dom/events/DataContainerEvent.cpp
dom/events/DataContainerEvent.h
dom/xbl/nsXBLDocumentInfo.cpp
xpcom/glue/nsBaseHashtable.h
xpcom/glue/nsInterfaceHashtable.h
xpcom/glue/nsRefPtrHashtable.h
--- a/dom/events/DataContainerEvent.cpp
+++ b/dom/events/DataContainerEvent.cpp
@@ -23,21 +23,21 @@ DataContainerEvent::DataContainerEvent(E
       doc->WarnOnceAbout(nsIDocument::eDataContainerEvent);
     }
   }
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(DataContainerEvent)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DataContainerEvent, Event)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK(mData)
+  tmp->mData.Clear();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(DataContainerEvent, Event)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mData)
+  tmp->mData.EnumerateRead(TraverseEntry, &cb);
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(DataContainerEvent, Event)
 NS_IMPL_RELEASE_INHERITED(DataContainerEvent, Event)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DataContainerEvent)
   NS_INTERFACE_MAP_ENTRY(nsIDOMDataContainerEvent)
 NS_INTERFACE_MAP_END_INHERITING(Event)
@@ -76,16 +76,28 @@ DataContainerEvent::SetData(JSContext* a
     nsContentUtils::XPConnect()->JSToVariant(aCx, aVal, getter_AddRefs(val));
   if (NS_FAILED(rv)) {
     aRv = rv;
     return;
   }
   aRv = SetData(aKey, val);
 }
 
+PLDHashOperator
+DataContainerEvent::TraverseEntry(const nsAString& aKey,
+                                  nsIVariant* aDataItem,
+                                  void* aUserArg)
+{
+  nsCycleCollectionTraversalCallback *cb =
+    static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
+  cb->NoteXPCOMChild(aDataItem);
+
+  return PL_DHASH_NEXT;
+}
+
 } // namespace dom
 } // namespace mozilla
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsresult
 NS_NewDOMDataContainerEvent(nsIDOMEvent** aInstancePtrResult,
--- a/dom/events/DataContainerEvent.h
+++ b/dom/events/DataContainerEvent.h
@@ -46,15 +46,18 @@ public:
 
   void SetData(JSContext* aCx, const nsAString& aKey,
                JS::Handle<JS::Value> aVal, ErrorResult& aRv);
 
 protected:
   ~DataContainerEvent() {}
 
 private:
+  static PLDHashOperator
+    TraverseEntry(const nsAString& aKey, nsIVariant* aDataItem, void* aUserArg);
+
   nsInterfaceHashtable<nsStringHashKey, nsIVariant> mData;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_DataContainerEvent_h_
--- a/dom/xbl/nsXBLDocumentInfo.cpp
+++ b/dom/xbl/nsXBLDocumentInfo.cpp
@@ -34,48 +34,71 @@
 
 using namespace mozilla;
 using namespace mozilla::scache;
 using namespace mozilla::dom;
 
 static const char kXBLCachePrefix[] = "xblcache";
 
 /* Implementation file */
+
+static PLDHashOperator
+TraverseProtos(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
+{
+  nsCycleCollectionTraversalCallback *cb =
+    static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
+  aProto->Traverse(*cb);
+  return PL_DHASH_NEXT;
+}
+
+static PLDHashOperator
+UnlinkProto(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
+{
+  aProto->Unlink();
+  return PL_DHASH_NEXT;
+}
+
+struct ProtoTracer
+{
+  const TraceCallbacks &mCallbacks;
+  void *mClosure;
+};
+
+static PLDHashOperator
+TraceProtos(const nsACString &aKey, nsXBLPrototypeBinding *aProto, void* aClosure)
+{
+  ProtoTracer* closure = static_cast<ProtoTracer*>(aClosure);
+  aProto->Trace(closure->mCallbacks, closure->mClosure);
+  return PL_DHASH_NEXT;
+}
+
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocumentInfo)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLDocumentInfo)
   if (tmp->mBindingTable) {
-    for (auto iter = tmp->mBindingTable->ConstIter();
-         !iter.Done(); iter.Next()) {
-      iter.UserData()->Unlink();
-    }
+    tmp->mBindingTable->EnumerateRead(UnlinkProto, nullptr);
   }
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDocument)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo)
   if (tmp->mDocument &&
       nsCCUncollectableMarker::InGeneration(cb, tmp->mDocument->GetMarkedCCGeneration())) {
     NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
     return NS_SUCCESS_INTERRUPTED_TRAVERSE;
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDocument)
   if (tmp->mBindingTable) {
-    for (auto iter = tmp->mBindingTable->ConstIter();
-         !iter.Done(); iter.Next()) {
-      iter.UserData()->Traverse(cb);
-    }
+    tmp->mBindingTable->EnumerateRead(TraverseProtos, &cb);
   }
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXBLDocumentInfo)
   if (tmp->mBindingTable) {
-    for (auto iter = tmp->mBindingTable->ConstIter();
-         !iter.Done(); iter.Next()) {
-      iter.UserData()->Trace(aCallbacks, aClosure);
-    }
+    ProtoTracer closure = { aCallbacks, aClosure };
+    tmp->mBindingTable->EnumerateRead(TraceProtos, &closure);
   }
 NS_IMPL_CYCLE_COLLECTION_TRACE_END
 
 static void
 UnmarkXBLJSObject(JS::GCCellPtr aPtr, const char* aName, void* aClosure)
 {
   JS::ExposeObjectToActiveJS(aPtr.toObject());
 }
--- a/xpcom/glue/nsBaseHashtable.h
+++ b/xpcom/glue/nsBaseHashtable.h
@@ -338,16 +338,51 @@ protected:
     void* userArg;
   };
 
   static size_t s_SizeOfStub(PLDHashEntryHdr* aEntry,
                              mozilla::MallocSizeOf aMallocSizeOf,
                              void* aArg);
 };
 
+class nsCycleCollectionTraversalCallback;
+
+struct MOZ_STACK_CLASS nsBaseHashtableCCTraversalData
+{
+  nsBaseHashtableCCTraversalData(nsCycleCollectionTraversalCallback& aCallback,
+                                 const char* aName,
+                                 uint32_t aFlags)
+    : mCallback(aCallback)
+    , mName(aName)
+    , mFlags(aFlags)
+  {
+  }
+
+  nsCycleCollectionTraversalCallback& mCallback;
+  const char* mName;
+  uint32_t mFlags;
+
+};
+
+template<typename K, typename T>
+PLDHashOperator
+ImplCycleCollectionTraverse_EnumFunc(K aKey,
+                                     T aData,
+                                     void* aUserData)
+{
+  nsBaseHashtableCCTraversalData* userData =
+    static_cast<nsBaseHashtableCCTraversalData*>(aUserData);
+
+  CycleCollectionNoteChild(userData->mCallback,
+                           aData,
+                           userData->mName,
+                           userData->mFlags);
+  return PL_DHASH_NEXT;
+}
+
 //
 // nsBaseHashtableET definitions
 //
 
 template<class KeyClass, class DataType>
 nsBaseHashtableET<KeyClass, DataType>::nsBaseHashtableET(KeyTypePointer aKey)
   : KeyClass(aKey)
   , mData()
--- a/xpcom/glue/nsInterfaceHashtable.h
+++ b/xpcom/glue/nsInterfaceHashtable.h
@@ -64,19 +64,20 @@ ImplCycleCollectionUnlink(nsInterfaceHas
 
 template<typename K, typename T>
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
                             const nsInterfaceHashtable<K, T>& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
-  for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) {
-    CycleCollectionNoteChild(aCallback, iter.UserData(), aName, aFlags);
-  }
+  nsBaseHashtableCCTraversalData userData(aCallback, aName, aFlags);
+
+  aField.EnumerateRead(ImplCycleCollectionTraverse_EnumFunc<typename K::KeyType, T*>,
+                       &userData);
 }
 
 //
 // nsInterfaceHashtable definitions
 //
 
 template<class KeyClass, class Interface>
 bool
--- a/xpcom/glue/nsRefPtrHashtable.h
+++ b/xpcom/glue/nsRefPtrHashtable.h
@@ -79,19 +79,20 @@ ImplCycleCollectionUnlink(nsRefPtrHashta
 
 template<typename K, typename T>
 inline void
 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
                             nsRefPtrHashtable<K, T>& aField,
                             const char* aName,
                             uint32_t aFlags = 0)
 {
-  for (auto iter = aField.ConstIter(); !iter.Done(); iter.Next()) {
-    CycleCollectionNoteChild(aCallback, iter.UserData(), aName, aFlags);
-  }
+  nsBaseHashtableCCTraversalData userData(aCallback, aName, aFlags);
+
+  aField.EnumerateRead(ImplCycleCollectionTraverse_EnumFunc<typename K::KeyType, T*>,
+                       &userData);
 }
 
 //
 // nsRefPtrHashtable definitions
 //
 
 template<class KeyClass, class RefPtr>
 bool