Bug 417840 - "ASSERTION: Shouldn't be observing anymore" removing 'ref' attribute. r+sr=jst, a=blocking1.9+.
authorbent.mozilla@gmail.com
Tue, 19 Feb 2008 14:21:45 -0800
changeset 11884 b94c700f3857fc4d459cc1fc52ebc0bc61514882
parent 11883 98c806b8331f754fa1737e202d207352dea5d1e5
child 11885 2a4550a18d319c7f5088c4aa3a69298e6ba35367
push idunknown
push userunknown
push dateunknown
reviewersblocking1.9
bugs417840
milestone1.9b4pre
Bug 417840 - "ASSERTION: Shouldn't be observing anymore" removing 'ref' attribute. r+sr=jst, a=blocking1.9+.
content/xul/templates/src/nsXULTemplateBuilder.cpp
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -213,16 +213,21 @@ nsXULTemplateBuilder::InitGlobals()
     const size_t bucketsizes[] = { sizeof(nsTemplateMatch) };
     return mPool.Init("nsXULTemplateBuilder", bucketsizes, 1, 256);
 }
 
 
 void
 nsXULTemplateBuilder::Uninit(PRBool aIsFinal)
 {
+    if (mObservedDocument) {
+        gObserverService->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
+        mObservedDocument = nsnull;
+    }
+
     if (mQueryProcessor)
         mQueryProcessor->Done();
 
     for (PRInt32 q = mQuerySets.Length() - 1; q >= 0; q--) {
         nsTemplateQuerySet* qs = mQuerySets[q];
         delete qs;
     }
 
@@ -231,18 +236,16 @@ nsXULTemplateBuilder::Uninit(PRBool aIsF
     mMatchMap.EnumerateRead(DestroyMatchList, &mPool);
     mMatchMap.Clear();
 
     mRootResult = nsnull;
     mRefVariable = nsnull;
     mMemberVariable = nsnull;
 
     mQueriesCompiled = PR_FALSE;
-
-    NS_ASSERTION(!mObservedDocument, "Shouldn't be observing anymore!");
 }
 
 static PLDHashOperator
 TraverseMatchList(nsISupports* aKey, nsTemplateMatch* aMatch, void* aContext)
 {
     nsCycleCollectionTraversalCallback *cb =
         static_cast<nsCycleCollectionTraversalCallback*>(aContext);
 
@@ -1102,21 +1105,16 @@ void
 nsXULTemplateBuilder::ContentRemoved(nsIDocument* aDocument,
                                      nsIContent* aContainer,
                                      nsIContent* aChild,
                                      PRInt32 aIndexInContainer)
 {
     if (mRoot && nsContentUtils::ContentIsDescendantOf(mRoot, aChild)) {
         nsRefPtr<nsXULTemplateBuilder> kungFuDeathGrip(this);
 
-        if (mObservedDocument) {
-            gObserverService->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
-            mObservedDocument = nsnull;
-        }
-
         if (mQueryProcessor)
             mQueryProcessor->Done();
 
         // use false since content is going away anyway
         Uninit(PR_FALSE);
 
         aDocument->RemoveObserver(this);
 
@@ -1141,21 +1139,16 @@ nsXULTemplateBuilder::ContentRemoved(nsI
 
 void
 nsXULTemplateBuilder::NodeWillBeDestroyed(const nsINode* aNode)
 {
     // The call to RemoveObserver could release the last reference to
     // |this|, so hold another reference.
     nsRefPtr<nsXULTemplateBuilder> kungFuDeathGrip(this);
 
-    if (mObservedDocument) {
-        gObserverService->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
-        mObservedDocument = nsnull;
-    }
-
     // Break circular references
     if (mQueryProcessor)
         mQueryProcessor->Done();
 
     mDataSource = nsnull;
     mDB = nsnull;
     mCompDB = nsnull;
     mRoot = nsnull;