From 5e1207890497d5186a640e21ce5ca3fdffa7dd09 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 25 Jun 2025 23:47:56 +0200 Subject: [PATCH] [Layout] Hold stronger references to FontFaces. --- layout/style/FontFaceSet.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 5b390d769e..04c04fd372 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -324,10 +324,18 @@ FontFaceSet::Load(JSContext* aCx, nsTArray> promises; - nsTArray faces; - FindMatchingFontFaces(aFont, aText, faces, aRv); - if (aRv.Failed()) { - return nullptr; + nsTArray> faces; + { + nsTArray weakFaces; + FindMatchingFontFaces(aFont, aText, weakFaces, aRv); + if (aRv.Failed()) { + return nullptr; + } + if (!faces.AppendElements(weakFaces, fallible) || + !promises.SetCapacity(weakFaces.Length(), fallible)) { + aRv.Throw(NS_ERROR_FAILURE); + return nullptr; + } } for (FontFace* f : faces) { @@ -335,10 +343,7 @@ FontFaceSet::Load(JSContext* aCx, if (aRv.Failed()) { return nullptr; } - if (!promises.AppendElement(promise, fallible)) { - aRv.Throw(NS_ERROR_FAILURE); - return nullptr; - } + promises.AppendElement(promise); } return Promise::All(aCx, promises, aRv);