Bug 1421420 - Hold onto a weak reference to the grid container frame across reflow flushes triggered by devtools. r=dholbert, a=gchang
MozReview-Commit-ID: 2lkQr1jbnFd
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -6922,25 +6922,34 @@ nsGridContainerFrame::GetGridFrameWithCo
// if any of our properties are missing, generate them
bool reflowNeeded = (!gridFrame->HasProperty(GridColTrackInfo()) ||
!gridFrame->HasProperty(GridRowTrackInfo()) ||
!gridFrame->HasProperty(GridColumnLineInfo()) ||
!gridFrame->HasProperty(GridRowLineInfo()));
if (reflowNeeded) {
// Trigger a reflow that generates additional grid property data.
+ // Hold onto aFrame while we do this, in case reflow destroys it.
+ AutoWeakFrame weakFrameRef(aFrame);
+
nsIPresShell* shell = gridFrame->PresShell();
gridFrame->AddStateBits(NS_STATE_GRID_GENERATE_COMPUTED_VALUES);
shell->FrameNeedsReflow(gridFrame,
nsIPresShell::eResize,
NS_FRAME_IS_DIRTY);
shell->FlushPendingNotifications(FlushType::Layout);
- // Since the reflow may have side effects, get the grid frame again.
- gridFrame = GetGridContainerFrame(aFrame);
+ // Since the reflow may have side effects, get the grid frame
+ // again. But if the weakFrameRef is no longer valid, then we
+ // must bail out.
+ if (!weakFrameRef.IsAlive()) {
+ return nullptr;
+ }
+
+ gridFrame = GetGridContainerFrame(weakFrameRef.GetFrame());
// Assert the grid properties are present
MOZ_ASSERT(!gridFrame ||
gridFrame->HasProperty(GridColTrackInfo()));
MOZ_ASSERT(!gridFrame ||
gridFrame->HasProperty(GridRowTrackInfo()));
MOZ_ASSERT(!gridFrame ||
gridFrame->HasProperty(GridColumnLineInfo()));