Closed Bug 1780657 Opened 2 years ago Closed 7 months ago

Array.from returning empty from FontFaceSet Iterable

Categories

(Core :: DOM: CSS Object Model, defect)

Firefox 102
defect

Tracking

()

RESOLVED DUPLICATE of bug 1311198

People

(Reporter: brenley.me, Unassigned)

References

Details

Steps to reproduce:

Go to any page with fonts in Firefox, e.g. https://www.amazon.com/dp/B09HQHD3CP/

Add the following into the console:

document.fonts.ready.then(function(fonts) {
  console.log(Array.from(fonts.values()))
});

Actual results:

An empty array is logged

Expected results:

Expect an array containing the FontFace for each item in the Iterable FontFaceSet

Summary: Array returning empty from FontFaceSet Iterable → Array.from returning empty from FontFaceSet Iterable

Note that fonts works as an Iterable: for (let font of document.fonts) { console.log(font) }

But fonts.values() does not: for (let font of document.fonts.values()) { console.log(font) }

Uncaught TypeError: document.fonts.values() is not iterable
    <anonymous> debugger eval code:1

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript Engine' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Component: JavaScript Engine → DOM: Core & HTML
Component: DOM: Core & HTML → DOM: CSS Object Model

Looks like our impl doesn't consider FontFaceSet to be an Iterable (but should).

See see bug 1729089 comment 2 and other comments there.

Until this is fixed, I think it can be worked around (somewhat clumsily) by manually calling "next()" on the object that fonts.values() returns -- it has a next() method, though it's not strictly an Iterable right now.

e.g. this should work in all browsers (and you could use similar code to construct an Array if you really want one as in comment 0):

document.fonts.ready.then(function(fonts) {
  kindaIterable = fonts.values();
  let count = 0;
  while (true) {
    let f = kindaIterable.next();
    if (f.done) {
      console.log("No more");
      break;
    }
    count++;
    console.log(`Found font in family: ${f.value.family}`);
  }
  console.log(count);
});
Severity: -- → S3
Status: UNCONFIRMED → NEW
Depends on: 1729089
Ever confirmed: true

I think we can just consider this a duplicate of bug 1311198, really. It looks like that (making FontFaceSet into a setlike) is the way forward here, and it should make this Just Work.

Status: NEW → RESOLVED
Closed: 7 months ago
Duplicate of bug: 1311198
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.