Bug 1855506: Add assertions to validate the return value of gfxPlatformFontList::FindAndAddFamilies. r=jfkthame

Differential Revision: https://phabricator.services.mozilla.com/D189413
This commit is contained in:
Daniel Holbert 2023-09-28 17:05:26 +00:00
parent f68d515b21
commit 077578eff4
2 changed files with 27 additions and 5 deletions

View File

@ -1498,6 +1498,31 @@ gfxFontFamily* gfxPlatformFontList::CheckFamily(gfxFontFamily* aFamily) {
return aFamily;
}
bool gfxPlatformFontList::FindAndAddFamilies(
nsPresContext* aPresContext, StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags, gfxFontStyle* aStyle, nsAtom* aLanguage,
gfxFloat aDevToCssSize) {
AutoLock lock(mLock);
#ifdef DEBUG
auto initialLength = aOutput->Length();
#endif
bool didFind =
FindAndAddFamiliesLocked(aPresContext, aGeneric, aFamily, aOutput, aFlags,
aStyle, aLanguage, aDevToCssSize);
#ifdef DEBUG
auto finalLength = aOutput->Length();
// Validate the expectation that the output-array grows if we return true,
// or remains the same (probably empty) if we return false.
MOZ_ASSERT_IF(didFind, finalLength > initialLength);
MOZ_ASSERT_IF(!didFind, finalLength == initialLength);
#endif
return didFind;
}
bool gfxPlatformFontList::FindAndAddFamiliesLocked(
nsPresContext* aPresContext, StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,

View File

@ -332,11 +332,8 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,
FindFamiliesFlags aFlags, gfxFontStyle* aStyle = nullptr,
nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0) {
AutoLock lock(mLock);
return FindAndAddFamiliesLocked(aPresContext, aGeneric, aFamily, aOutput,
aFlags, aStyle, aLanguage, aDevToCssSize);
}
nsAtom* aLanguage = nullptr, gfxFloat aDevToCssSize = 1.0);
virtual bool FindAndAddFamiliesLocked(
nsPresContext* aPresContext, mozilla::StyleGenericFontFamily aGeneric,
const nsACString& aFamily, nsTArray<FamilyAndGeneric>* aOutput,