Bug 553808, assertion setting template datasources, r=smaug, a=blocking
authorNeil Deakin <neil@mozilla.com>
Tue, 26 Oct 2010 11:17:00 -0400
changeset 56502 3e08f8844f876c63b4d42f25a76dfd39fa50ee41
parent 56501 6fa85db3902e2a0c3a5fa78f0ee8065a00d36483
child 56503 5c176a0420cf2540cca3b89d8a88bd326bb328c2
child 56601 c9a91f0eda04bc9d6ca4ae199b2234b32f7d6664
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerssmaug, blocking
bugs553808
milestone2.0b8pre
Bug 553808, assertion setting template datasources, r=smaug, a=blocking
content/xul/templates/src/nsXULTemplateBuilder.cpp
content/xul/templates/src/nsXULTemplateBuilder.h
content/xul/templates/tests/chrome/test_tmpl_errors.xul
--- a/content/xul/templates/src/nsXULTemplateBuilder.cpp
+++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp
@@ -1134,23 +1134,18 @@ nsXULTemplateBuilder::AttributeChanged(n
         // beneath the element.
         if (aAttribute == nsGkAtoms::ref)
             nsContentUtils::AddScriptRunner(
                 NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableRebuild));
 
         // Check for a change to the 'datasources' attribute. If so, setup
         // mDB by parsing the new value and rebuild.
         else if (aAttribute == nsGkAtoms::datasources) {
-            Uninit(PR_FALSE);  // Reset results
-            
-            PRBool shouldDelay;
-            LoadDataSources(aDocument, &shouldDelay);
-            if (!shouldDelay)
-                nsContentUtils::AddScriptRunner(
-                    NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableRebuild));
+            nsContentUtils::AddScriptRunner(
+                NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableLoadAndRebuild));
         }
     }
 }
 
 void
 nsXULTemplateBuilder::ContentRemoved(nsIDocument* aDocument,
                                      nsIContent* aContainer,
                                      nsIContent* aChild,
@@ -1158,18 +1153,19 @@ nsXULTemplateBuilder::ContentRemoved(nsI
                                      nsIContent* aPreviousSibling)
 {
     if (mRoot && nsContentUtils::ContentIsDescendantOf(mRoot, aChild)) {
         nsRefPtr<nsXULTemplateBuilder> kungFuDeathGrip(this);
 
         if (mQueryProcessor)
             mQueryProcessor->Done();
 
-        // use false since content is going away anyway
-        Uninit(PR_FALSE);
+        // Pass false to Uninit since content is going away anyway
+        nsContentUtils::AddScriptRunner(
+            NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitFalse));
 
         aDocument->RemoveObserver(this);
 
         nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(aDocument);
         if (xuldoc)
             xuldoc->SetTemplateBuilderFor(mRoot, nsnull);
 
         // clear the template state when removing content so that template
@@ -1196,17 +1192,18 @@ nsXULTemplateBuilder::NodeWillBeDestroye
     if (mQueryProcessor)
         mQueryProcessor->Done();
 
     mDataSource = nsnull;
     mDB = nsnull;
     mCompDB = nsnull;
     mRoot = nsnull;
 
-    Uninit(PR_TRUE);
+    nsContentUtils::AddScriptRunner(
+        NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitTrue));
 }
 
 
 
 
 //----------------------------------------------------------------------
 //
 // Implementation methods
--- a/content/xul/templates/src/nsXULTemplateBuilder.h
+++ b/content/xul/templates/src/nsXULTemplateBuilder.h
@@ -147,16 +147,30 @@ public:
 
     static PRBool
     IsTemplateElement(nsIContent* aContent);
 
     virtual nsresult
     RebuildAll() = 0; // must be implemented by subclasses
 
     void RunnableRebuild() { Rebuild(); }
+    void RunnableLoadAndRebuild() {
+      Uninit(PR_FALSE);  // Reset results
+
+      nsCOMPtr<nsIDocument> doc = mRoot ? mRoot->GetDocument() : nsnull;
+      if (doc) {
+        PRBool shouldDelay;
+        LoadDataSources(doc, &shouldDelay);
+        if (!shouldDelay) {
+          Rebuild();
+        }
+      }
+    }
+    void UninitFalse() { Uninit(PR_FALSE); }
+    void UninitTrue() { Uninit(PR_TRUE); }
 
     /**
      * Find the <template> tag that applies for this builder
      */
     nsresult
     GetTemplateRoot(nsIContent** aResult);
 
     /**
--- a/content/xul/templates/tests/chrome/test_tmpl_errors.xul
+++ b/content/xul/templates/tests/chrome/test_tmpl_errors.xul
@@ -22,18 +22,17 @@ SimpleTest.waitForExplicitFinish();
 
 var consoleService = Components.classes["@mozilla.org/consoleservice;1"].
                        getService(Components.interfaces.nsIConsoleService);
 
 function checkConsole(expectedError)
 {
   var out = {};
   consoleService.getMessageArray(out, {});
-  var messages = out.value || [];
-  is(messages[0].message, expectedError, "logged message " + expectedError);
+  is(out.value[0].message, expectedError, "logged message " + expectedError);
 }
 
 // each test consists of a pre function executed before the template build, an
 // expected error message, and a post function executed after the template build
 var tests = [
 
 // <queryset> used in invalid location
 {