Bug 1115812 patch 19 - Avoid bad kungFuDeathGrip pattern. r=heycam
authorL. David Baron <dbaron@dbaron.org>
Tue, 13 Jan 2015 21:03:12 -0800
changeset 223720 4c7428662fab53e6072810263955b6bcf4a01344
parent 223719 8005d07007d5b874448a77b160dee37b657204b3
child 223721 e12e9be31708823df8f30ebdcbbc4f01223071d0
push id10811
push usercbook@mozilla.com
push dateWed, 14 Jan 2015 13:52:17 +0000
treeherderfx-team@b8d38d19dbd9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1115812
milestone38.0a1
Bug 1115812 patch 19 - Avoid bad kungFuDeathGrip pattern. r=heycam If we need a strong reference to the pres shell, we may as well do it the first time rather than bothering with an extra variable.
layout/base/RestyleManager.cpp
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -1475,29 +1475,28 @@ RestyleManager::RebuildAllStyleData(nsCh
 {
   NS_ASSERTION(!(aExtraHint & nsChangeHint_ReconstructFrame),
                "Should not reconstruct the root of the frame tree.  "
                "Use ReconstructDocElementHierarchy instead.");
 
   NS_UpdateHint(mRebuildAllExtraHint, aExtraHint);
   mRebuildAllRestyleHint |= aRestyleHint;
 
-  nsIPresShell* presShell = mPresContext->GetPresShell();
+  // Processing the style changes could cause a flush that propagates to
+  // the parent frame and thus destroys the pres shell, so we must hold
+  // a reference.
+  nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
   if (!presShell || !presShell->GetRootFrame()) {
     mDoRebuildAllStyleData = false;
     return;
   }
 
   // Make sure that the viewmanager will outlive the presshell
   nsRefPtr<nsViewManager> vm = presShell->GetViewManager();
 
-  // Processing the style changes could cause a flush that propagates to
-  // the parent frame and thus destroys the pres shell.
-  nsCOMPtr<nsIPresShell> kungFuDeathGrip(presShell);
-
   // We may reconstruct frames below and hence process anything that is in the
   // tree. We don't want to get notified to process those items again after.
   presShell->GetDocument()->FlushPendingNotifications(Flush_ContentAndNotify);
 
   nsAutoScriptBlocker scriptBlocker;
 
   mDoRebuildAllStyleData = true;