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.
--- 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;