Bugzilla – Bug 17648
[Awaiting ES6] Add iterators
Last modified: 2014-02-12 21:13:00 UTC
heycam suggests at least NodeList/HTMLCollection need this, but if they can have [ArrayClass] that would be better. https://bugs.webkit.org/show_bug.cgi?id=81573 suggests [ArrayClass] is probably not going to happen, but who knows, it is not resolved wontfix just yet.
I think this should be done in WebIDL for all interfaces that support indexed properties, fwiw.
heycam, what do you think?
Iterators have already been added to the spec, so if people want to write explicit ones for their interfaces they can.
But I like the idea of having iterators by default for objects that support indexed properties. This could be overridden if you explicitly declare an iterator.
The ES6 draft has changed a lot since I looked at it last. :) I can't see mention of iterator() methods on objects any more, which is what Web IDL is written against at the moment. Maybe that strawman changed before being added to the spec. I can see in section 12.6.4 (dealing with for-in and for-of loops), the runtime semantics of the "For In/Of Expression Evaluation" abstract operation, step 7.b says:
Let keys be the result of performing Invoke with arguments obj, %iterator%, and an empty List.
but there doesn't seem to be a definition for this intrinsic object %iterator%. Maybe that's meant to be an intrinsic symbol @@iterator? Anyway, it feels like the spec isn't quite done on this yet, so perhaps I should wait a bit.
Thread at http://www.w3.org/mid/520FE9BF.firstname.lastname@example.org mentioned this bug too.
Given that we could theoretically snapshot live lists, I asked arv, he said "I think we should keep them live. ArrayIterator is live. Doing `NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]` works fine with live lists."
Fwiw, that's basically what Gecko implements right now. We've had a few complaints about it, in the usual way. Live lists suck to work with. :(