Bug 1514511 - Don't flush if the document is in the bfcache. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 26 Jan 2019 08:57:59 +0100
changeset 515540 8f22c3daa581e0f5c89f7ee6a8e74f6a00e3d7fd
parent 515539 da799f611f33fc367cb49193872709c2cd89fd8a
child 515552 aee9ebe9b9b2432993e8a3cc1f1cf33ab4e2a240
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1514511
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1514511 - Don't flush if the document is in the bfcache. r=bzbarsky I think this is slightly better fix given the amount of offenders we have that don't make sure this is the case. Generally we get through the flush just fine, but there's code that relies on nsIDocument::GetShell to return something meaningful, like the styleset code that gets a pres context. Differential Revision: https://phabricator.services.mozilla.com/D14689
layout/base/PresShell.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -4065,20 +4065,26 @@ void PresShell::DoFlushPendingNotificati
   // If layout could possibly trigger scripts, then it's only safe to flush if
   // it's safe to run script.
   bool hasHadScriptObject;
   if (mDocument->GetScriptHandlingObject(hasHadScriptObject) ||
       hasHadScriptObject) {
     isSafeToFlush = isSafeToFlush && nsContentUtils::IsSafeToRunScript();
   }
 
+  // Don't flush if the doc is already in the bfcache.
+  if (MOZ_UNLIKELY(mDocument->GetShell() != this)) {
+    MOZ_DIAGNOSTIC_ASSERT(!mDocument->GetShell(),
+                          "Where did this shell come from?");
+    isSafeToFlush = false;
+  }
+
   MOZ_DIAGNOSTIC_ASSERT(!mIsDestroying || !isSafeToFlush);
   MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mViewManager);
   MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mDocument->HasShellOrBFCacheEntry());
-  MOZ_DIAGNOSTIC_ASSERT(mIsDestroying || mDocument->GetShell() == this);
 
   // Make sure the view manager stays alive.
   RefPtr<nsViewManager> viewManager = mViewManager;
   bool didStyleFlush = false;
   bool didLayoutFlush = false;
   if (isSafeToFlush) {
     // Record that we are in a flush, so that our optimization in
     // Document::FlushPendingNotifications doesn't skip any re-entrant