[Font Loading] Crash when a single load request causes multiple fonts to fail loading
[WebKit-https.git] / Source / WebCore / css / FontFaceSet.cpp
index ad5aa48a158a6bb2bb278e5cf1735856b2978164..3f9f58b8c5b99267cda599d0056d84ab949ee8d9 100644 (file)
@@ -236,12 +236,16 @@ void FontFaceSet::faceFinished(CSSFontFace& face, CSSFontFace::Status newStatus)
 
     for (auto& pendingPromise : iterator->value) {
         if (newStatus == CSSFontFace::Status::Success) {
 
     for (auto& pendingPromise : iterator->value) {
         if (newStatus == CSSFontFace::Status::Success) {
-            if (pendingPromise->hasOneRef())
+            if (pendingPromise->hasOneRef() && !pendingPromise->hasReachedTerminalState) {
                 pendingPromise->promise.resolve(pendingPromise->faces);
                 pendingPromise->promise.resolve(pendingPromise->faces);
+                pendingPromise->hasReachedTerminalState = true;
+            }
         } else {
             ASSERT(newStatus == CSSFontFace::Status::Failure);
         } else {
             ASSERT(newStatus == CSSFontFace::Status::Failure);
-            // The first resolution wins, so we can just reject early now.
-            pendingPromise->promise.reject(DOMCoreException::create(ExceptionCodeDescription(NETWORK_ERR)));
+            if (!pendingPromise->hasReachedTerminalState) {
+                pendingPromise->promise.reject(DOMCoreException::create(ExceptionCodeDescription(NETWORK_ERR)));
+                pendingPromise->hasReachedTerminalState = true;
+            }
         }
     }
 
         }
     }