Bug 476526. Release the style context before calling LoadBindings. r+sr=bzbarsky
authorRobert O'Callahan <robert@ocallahan.org>
Fri, 08 May 2009 14:41:12 +1200
changeset 28116 7db881363a22822bbadcbe1f5c400069ebbd40ac
parent 28115 26c4c46fcaac14ede31283854e2bb830c7dece99
child 28117 0dcf7c03b8199a83999fb1fd02f92d6f0a62f423
push id6896
push userrocallahan@mozilla.com
push dateFri, 08 May 2009 03:22:56 +0000
treeherdermozilla-central@c97e93f23f89 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs476526
milestone1.9.2a1pre
Bug 476526. Release the style context before calling LoadBindings. r+sr=bzbarsky
dom/base/nsDOMClassInfo.cpp
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -7554,41 +7554,45 @@ nsElementSH::PostCreate(nsIXPConnectWrap
 
     return NS_OK;
   }
 
   // Get the computed -moz-binding directly from the style context
   nsPresContext *pctx = shell->GetPresContext();
   NS_ENSURE_TRUE(pctx, NS_ERROR_UNEXPECTED);
 
-  // Make sure the style context goes away _before_ we execute the binding
-  // constructor, since the constructor can destroy the relevant presshell.
-  nsRefPtr<nsXBLBinding> binding;
+  // Make sure the style context goes away _before_ we load the binding
+  // since that can destroy the relevant presshell.
+  nsCOMPtr<nsIURI> uri;
+  nsCOMPtr<nsIPrincipal> principal;
   {
     // Scope for the nsRefPtr
     nsRefPtr<nsStyleContext> sc = pctx->StyleSet()->ResolveStyleFor(content,
                                                                     nsnull);
     NS_ENSURE_TRUE(sc, NS_ERROR_FAILURE);
 
     nsCSSValue::URL *bindingURL = sc->GetStyleDisplay()->mBinding;
     if (!bindingURL) {
       // No binding, nothing left to do here.
       return NS_OK;
     }
 
-    // We have a binding that must be installed.
-    PRBool dummy;
-
-    nsCOMPtr<nsIXBLService> xblService(do_GetService("@mozilla.org/xbl;1"));
-    NS_ENSURE_TRUE(xblService, NS_ERROR_NOT_AVAILABLE);
-
-    xblService->LoadBindings(content, bindingURL->mURI,
-                             bindingURL->mOriginPrincipal, PR_FALSE,
-                             getter_AddRefs(binding), &dummy);
-  }
+    uri = bindingURL->mURI;
+    principal = bindingURL->mOriginPrincipal;
+  }
+
+  // We have a binding that must be installed.
+  PRBool dummy;
+
+  nsCOMPtr<nsIXBLService> xblService(do_GetService("@mozilla.org/xbl;1"));
+  NS_ENSURE_TRUE(xblService, NS_ERROR_NOT_AVAILABLE);
+
+  nsRefPtr<nsXBLBinding> binding;
+  xblService->LoadBindings(content, uri, principal, PR_FALSE,
+                           getter_AddRefs(binding), &dummy);
   
   if (binding) {
     if (nsContentUtils::IsSafeToRunScript()) {
       binding->ExecuteAttachedHandler();
     }
     else {
       nsContentUtils::AddScriptRunner(new nsRunnableMethod<nsXBLBinding>(
         binding, &nsXBLBinding::ExecuteAttachedHandler));