Bug 1362924 - Part 1: Stop synchronously running XBL constructors and flushing style in PresShell::Initialize. r=tnikkel a=abillings a=jcristau
authorCameron McCormack <cam@mcc.id.au>
Wed, 05 Jul 2017 08:32:12 +0200
changeset 411818 706e0da8ef144f38f36d47190876bbc8aff7cce8
parent 411817 6b226a670b4892b9b77fd762ba1263e6a128dfd3
child 411819 388ed6dc3c87d44234eca3e0cad78d0214083640
push id7474
push usercbook@mozilla.com
push dateWed, 05 Jul 2017 06:35:00 +0000
treeherdermozilla-beta@388ed6dc3c87 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstnikkel, abillings, jcristau
bugs1362924
milestone55.0
Bug 1362924 - Part 1: Stop synchronously running XBL constructors and flushing style in PresShell::Initialize. r=tnikkel a=abillings a=jcristau MozReview-Commit-ID: 8GUm6Mt5wiK
layout/base/PresShell.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -1693,16 +1693,34 @@ PresShell::EndObservingDocument()
     mDocument->RemoveObserver(this);
   }
 }
 
 #ifdef DEBUG_kipp
 char* nsPresShell_ReflowStackPointerTop;
 #endif
 
+class XBLConstructorRunner : public Runnable
+{
+public:
+  explicit XBLConstructorRunner(nsIDocument* aDocument)
+    : mDocument(aDocument)
+  {
+  }
+
+  NS_IMETHOD Run() override
+  {
+    mDocument->BindingManager()->ProcessAttachedQueue();
+    return NS_OK;
+  }
+
+private:
+  nsCOMPtr<nsIDocument> mDocument;
+};
+
 nsresult
 PresShell::Initialize(nscoord aWidth, nscoord aHeight)
 {
   if (mIsDestroying) {
     return NS_OK;
   }
 
   if (!mDocument) {
@@ -1788,34 +1806,24 @@ PresShell::Initialize(nscoord aWidth, ns
 
       // Something in mFrameConstructor->ContentInserted may have caused
       // Destroy() to get called, bug 337586.
       NS_ENSURE_STATE(!mHaveShutDown);
 
       mFrameConstructor->EndUpdate();
     }
 
-    // nsAutoScriptBlocker going out of scope may have killed us too
-    NS_ENSURE_STATE(!mHaveShutDown);
-
-    // Run the XBL binding constructors for any new frames we've constructed
-    mDocument->BindingManager()->ProcessAttachedQueue();
-
-    // Constructors may have killed us too
+    // nsAutoCauseReflowNotifier (which sets up a script blocker) going out of
+    // scope may have killed us too
     NS_ENSURE_STATE(!mHaveShutDown);
 
-    // Now flush out pending restyles before we actually reflow, in
-    // case XBL constructors changed styles somewhere.
-    {
-      nsAutoScriptBlocker scriptBlocker;
-      mPresContext->RestyleManager()->ProcessPendingRestyles();
-    }
-
-    // And that might have run _more_ XBL constructors
-    NS_ENSURE_STATE(!mHaveShutDown);
+    // Run the XBL binding constructors for any new frames we've constructed.
+    // (Do this in a script runner, since our caller might have a script
+    // blocker on the stack.)
+    nsContentUtils::AddScriptRunner(new XBLConstructorRunner(mDocument));
   }
 
   NS_ASSERTION(rootFrame, "How did that happen?");
 
   // Note: when the frame was created above it had the NS_FRAME_IS_DIRTY bit
   // set, but XBL processing could have caused a reflow which clears it.
   if (MOZ_LIKELY(rootFrame->GetStateBits() & NS_FRAME_IS_DIRTY)) {
     // Unset the DIRTY bits so that FrameNeedsReflow() will work right.