Open Bug 1238662 Opened 8 years ago Updated 2 years ago

Improve XPathResult and NodeIterator by providing Symbol.iterator implementation for them

Categories

(Core :: DOM: Core & HTML, defect)

43 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: michalwadas, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0
Build ID: 20160105164030

Steps to reproduce:

const iterator = document.createNodeIterator(document);
for(var element of iterator) {}


Actual results:

TypeError: iterator[Symbol.iterator] is not a function


Expected results:

It should iterate trough result using Symbol.iterator.

Such change won't break backward compatibility.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Component: JavaScript Engine → DOM
A NodeIterator can be moved backwards.  Would need some careful definition of exactly what the iterator behavior is supposed to be: does it just blindly tail-call nextNode, does it snapshot the iterator and then reset its state, or something else?

Really, the right thing to do might be to make a NodeIterator itself an iterator (as in, give it a next() method that wraps nextNode up into the ES iteration protocol and a Symbol.iterator property pointing to itself).  That would make the for-of thing work, at least.  Please feel free to raise this as a spec issue at https://github.com/whatwg/dom/issues/new
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.