Bug 1465983 part 2 - Don't resolve FontFaceSet's ready promise in its constructor. r=heycam
authorJonathan Watt <jwatt@jwatt.org>
Tue, 22 May 2018 12:53:11 +0100
changeset 421385 023d0b84b7a9d8cdde7b9eb6e8fbc30faeae220d
parent 421384 94409f81ab0e75db962f24b29cb8a7f1bc3a71f2
child 421386 180d4930b0cfdd9a95d78de7ce850151915d762e
push id34093
push useraiakab@mozilla.com
push dateTue, 05 Jun 2018 21:58:58 +0000
treeherdermozilla-central@da28b92efe6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1465983
milestone62.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 1465983 part 2 - Don't resolve FontFaceSet's ready promise in its constructor. r=heycam
layout/style/FontFaceSet.cpp
--- a/layout/style/FontFaceSet.cpp
+++ b/layout/style/FontFaceSet.cpp
@@ -117,23 +117,16 @@ FontFaceSet::FontFaceSet(nsPIDOMWindowIn
   , mBypassCache(false)
   , mPrivateBrowsing(false)
 {
   MOZ_ASSERT(mDocument, "We should get a valid document from the caller!");
 
   mStandardFontLoadPrincipal =
     new gfxFontSrcPrincipal(mDocument->NodePrincipal());
 
-  // If the pref is not set, don't create the Promise (which the page wouldn't
-  // be able to get to anyway) as it causes the window.FontFaceSet constructor
-  // to be created.
-  if (aWindow && PrefEnabled()) {
-    mResolveLazilyCreatedReadyPromise = true;
-  }
-
   // Record the state of the "bypass cache" flags from the docshell now,
   // since we want to look at them from style worker threads, and we can
   // only get to the docshell through a weak pointer (which is only
   // possible on the main thread).
   //
   // In theory the load type of a docshell could change after the document
   // is loaded, but handling that doesn't seem too important.
   if (nsCOMPtr<nsIDocShell> docShell = mDocument->GetDocShell()) {
@@ -1693,19 +1686,22 @@ FontFaceSet::DispatchLoadingEventAndRepl
   if (PrefEnabled()) {
     if (mReady &&
         mReady->State() != Promise::PromiseState::Pending) {
       if (GetParentObject()) {
         ErrorResult rv;
         mReady = Promise::Create(GetParentObject(), rv);
       }
     }
-    if (!mReady) {
-      mResolveLazilyCreatedReadyPromise = false;
-    }
+
+    // We may previously have been in a state where all fonts had finished
+    // loading and we'd set mResolveLazilyCreatedReadyPromise to make sure that
+    // if we lazily create mReady for a consumer that we resolve it before
+    // returning it.  We're now loading fonts, so we need to clear that flag.
+    mResolveLazilyCreatedReadyPromise = false;
   }
 }
 
 void
 FontFaceSet::UpdateHasLoadingFontFaces()
 {
   mHasLoadingFontFacesIsDirty = false;
   mHasLoadingFontFaces = false;