Open Bug 1799890 Opened 2 years ago Updated 5 months ago

Add helper functions to maplike/setlike to allow iterating contents from C++

Categories

(Core :: DOM: Bindings (WebIDL), enhancement)

enhancement

Tracking

()

People

(Reporter: jjaschke, Unassigned)

References

(Blocks 2 open bugs)

Details

For proper implementation of the WebIDL part of the Highlight API (Bug 1703961) iterator access to the contents of a maplike/setlike from C++ is needed.
Currently, helper functions are provided to add(), delete(), clear() or has()/get() on the setlike/maplike, but it is not possible to iterate / get the contents, e.g. by using begin()..end() or keys().

(Same comment as bug 1311198, unless this is terribly trivial we should probably just fix bug 1311198 instead, then you'd basically just have a C++ collection you iterate over)

See Also: → 1311198

I dig into this a bit, it seems a bit tricky to have a helper method to get all keys as JSAPI only provides JS::MapKeys and JS::SetKeys which returns a javascript iterator, not sure if we have any utility that could easy to iterate over it or maybe we need to try to iterate it by ourself. jandem, would you mind shielding some light here?

Flags: needinfo?(jdemooij)

But yes, it would be nice if we could use spec new model, but I haven't have a chance looking into it, it seems we could reuse the current mechanism for iterable interface for set/map iterators, but what is the data structure we should use for maplike might be a tricky part.

It should just be an Index map (so a hashmap that preserves insertion order).

Just to be sure I understand.. We want a C++ iterator class for iterating over a JS Map or Set object's keys/values?

We do have JS::ForOfIterator, maybe you could make it work with that for now? It's not the fastest thing though.

Flags: needinfo?(jdemooij) → needinfo?(echen)

FYI, I've started looking into doing bug 1311198. It's going to take some time, so yes, if there's a trivial fix we can do to unblock this in the meantime that's ok too.

Blocks: 1852908
Flags: needinfo?(echen)
You need to log in before you can comment on or make changes to this bug.