1616#include " mozilla/dom/FontFaceBinding.h"
1717#include " mozilla/dom/FontFaceSetImpl.h"
1818
19- namespace mozilla {
20- namespace dom {
19+ namespace mozilla ::dom {
2120
2221// -- FontFaceBufferSource ---------------------------------------------------
2322
@@ -122,7 +121,9 @@ void FontFaceImpl::InitializeSourceURL(const nsACString& aURL) {
122121 IgnoredErrorResult rv;
123122 SetDescriptor (eCSSFontDesc_Src, aURL, rv);
124123 if (rv.Failed ()) {
125- mOwner ->MaybeReject (NS_ERROR_DOM_SYNTAX_ERR);
124+ mOwner ->MaybeReject (FontFaceLoadedRejectReason::Syntax,
125+ nsPrintfCString (" Invalid source url %s" ,
126+ PromiseFlatCString (aURL).get ()));
126127 SetStatus (FontFaceLoadStatus::Error);
127128 }
128129}
@@ -402,9 +403,10 @@ void FontFaceImpl::UpdateOwnerPromise() {
402403 mOwner ->MaybeResolve ();
403404 } else if (mStatus == FontFaceLoadStatus::Error) {
404405 if (mSourceType == eSourceType_Buffer) {
405- mOwner ->MaybeReject (NS_ERROR_DOM_SYNTAX_ERR);
406+ mOwner ->MaybeReject (FontFaceLoadedRejectReason::Syntax,
407+ nsCString (" Invalid source buffer" _ns));
406408 } else {
407- mOwner ->MaybeReject (NS_ERROR_DOM_NETWORK_ERR );
409+ mOwner ->MaybeReject (FontFaceLoadedRejectReason::Network, nsCString () );
408410 }
409411 }
410412
@@ -443,7 +445,10 @@ bool FontFaceImpl::SetDescriptor(nsCSSFontDesc aFontDesc,
443445 bool changed;
444446 if (!Servo_FontFaceRule_SetDescriptor (GetData (), aFontDesc, &aValue, url,
445447 &changed)) {
446- aRv.ThrowSyntaxError (" Invalid font descriptor" );
448+ aRv.ThrowSyntaxError (
449+ nsPrintfCString (" Invalid font descriptor %s: %s" ,
450+ nsCSSProps::GetStringValue (aFontDesc).get (),
451+ PromiseFlatCString (aValue).get ()));
447452 return false ;
448453 }
449454
@@ -465,11 +470,18 @@ bool FontFaceImpl::SetDescriptors(const nsACString& aFamily,
465470
466471 mDescriptors = Servo_FontFaceRule_CreateEmpty ().Consume ();
467472
473+ nsCString errorMessage;
468474 // Helper to call SetDescriptor and return true on success, false on failure.
469- auto setDesc = [= ](nsCSSFontDesc aDesc, const nsACString& aVal) -> bool {
475+ auto setDesc = [& ](nsCSSFontDesc aDesc, const nsACString& aVal) -> bool {
470476 IgnoredErrorResult rv;
471477 SetDescriptor (aDesc, aVal, rv);
472- return !rv.Failed ();
478+ if (!rv.Failed ()) {
479+ return true ;
480+ }
481+ errorMessage = nsPrintfCString (" Invalid font descriptor %s: %s" ,
482+ nsCSSProps::GetStringValue (aDesc).get (),
483+ PromiseFlatCString (aVal).get ());
484+ return false ;
473485 };
474486
475487 // Parse all of the mDescriptors in aInitializer, which are the values
@@ -497,7 +509,8 @@ bool FontFaceImpl::SetDescriptors(const nsACString& aFamily,
497509 mDescriptors = Servo_FontFaceRule_CreateEmpty ().Consume ();
498510
499511 if (mOwner ) {
500- mOwner ->MaybeReject (NS_ERROR_DOM_SYNTAX_ERR);
512+ mOwner ->MaybeReject (FontFaceLoadedRejectReason::Syntax,
513+ std::move (errorMessage));
501514 }
502515
503516 SetStatus (FontFaceLoadStatus::Error);
@@ -860,5 +873,4 @@ void FontFaceImpl::Entry::RemoveFontFace(FontFaceImpl* aFontFace) {
860873 CheckUserFontSetLocked ();
861874}
862875
863- } // namespace dom
864- } // namespace mozilla
876+ } // namespace mozilla::dom
0 commit comments