Bug 1421420 - Hold onto a weak reference to the grid container frame across reflow flushes triggered by devtools. r=dholbert, a=gchang
authorBrad Werth <bwerth@mozilla.com>
Tue, 28 Nov 2017 15:05:48 -0800
changeset 442661 7649c04f02c36e8fc07c1e87637b1cea9f3ba823
parent 442660 70d5016333a434cb406e1714deb837bcafa07079
child 442662 a5ffba3f346184e9fbe361cc9e34bca257378ca6
push id8292
push userryanvm@gmail.com
push dateSat, 02 Dec 2017 17:35:08 +0000
treeherdermozilla-beta@7649c04f02c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, gchang
bugs1421420
milestone58.0
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
layout/generic/nsGridContainerFrame.cpp
--- 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()));