Consider a page that does this:
var eventsFired = 0;
var facesSeen = [];
document.fonts.onloadingdone = document.fonts.onloadingerror = function(e) {
++eventsFired;
facesSeen = facesSeen.concat(e.fontfaces);
if (eventsFired == 2) {
document.documentElement.textContent = "Font faces seen: " + facesSeen.length;
}
}
var face = new FontFace("test", "url(http://example.com)");
face.load();
document.fonts.add(face);
document.fonts.ready.then(function() {
document.fonts.clear();
});
What should happen? Per https://drafts.csswg.org/css-font-loading/#switch-the-fontfaceset-to-loaded I believe the ordering will be:
- Step 4 runs, fulfilling (async? It's not very clear) the ready promise.
- Step 5 runs, queues a task.
- The promise handlers get called, which calls
clear on the FontFaceSet. This empties out the [[FailedFonts]] and [[LoadingFonts]] slots.
- The task step 5 of the algorithm queued runs and fires the events. The lists are empty, so
facesSeen should end up as an empty array in the testcase.
But in practice, both Firefox and Chrome have a length-1 array. So presumably they're not implementing the spec. For example, maybe they're doing step 5 substeps 1-3 synchronously, not off a task... (well, I know that's what Firefox is doing, actually). That might be a more author-friendly behavior in this case.
There should really be tests for this, if there aren't any, as well as tests for making sure that the promise handler runs before the events fire...
Consider a page that does this:
What should happen? Per https://drafts.csswg.org/css-font-loading/#switch-the-fontfaceset-to-loaded I believe the ordering will be:
clearon theFontFaceSet. This empties out the [[FailedFonts]] and [[LoadingFonts]] slots.facesSeenshould end up as an empty array in the testcase.But in practice, both Firefox and Chrome have a length-1 array. So presumably they're not implementing the spec. For example, maybe they're doing step 5 substeps 1-3 synchronously, not off a task... (well, I know that's what Firefox is doing, actually). That might be a more author-friendly behavior in this case.
There should really be tests for this, if there aren't any, as well as tests for making sure that the promise handler runs before the events fire...