Implement NodeIterator
Raynos opened this issue · comments
There are a few questions of Implement NodeIterator (as for Implement NodeFilter and TreeWalker):
- Whic Excention we need to raise when user try to create object directly (
new NodeIterator()
):TypeError: Illegal constructor
withoutcode
property as Chrome and FF do orDOMException: NOT_SUPPORTED_ERR
withcode == 9
as Opera do? - Do we need to export NodeIterator interface in
window
object, so user can dodocument.createNodeIterator(...) instanceof NodeIterator
or not?- Chrome does not provide direct access to these interfaces. So
document.createNodeIterator(...) instanceof NodeIterator
is illegal - FF and Opera allow direct access to these interfaces. So
document.createNodeIterator(...) instanceof NodeIterator
is legal
- Chrome does not provide direct access to these interfaces. So
- NodeIterator is just an interface. Doing
new NodeIterator();
is undefined behaviour. I would normally just dowindow.NodeIterator = function () {}
so basically throw no exceptions at all. - The polyfill should allow
document.createNodeIterator() instance NodeIterator
to work. I would also dowindow.NodeIterator = document.createNodeIterator(document).constructor;
in Chrome.
"no exceptions at all" for new NodeIterator()
I don't think it a good idea. I think it must throw extension as in major browsers.
Why does it matter. It's completely undefined behaviour. There is no specification that says it should throw exceptions. It either does
- Returns an empty object which is useless
- Throws an exception when invoked.
Either way you cant do anything with the function, one is a silent failure the other is an aggressive failure. Note that the silent failure option is less bytes ;)
It's true, but in this case shim does the behavior that not in major browsers.
Any way https://github.com/termi1uc1/DOM-shim/commit/26cb56d2357f7bcda13c3b1eaa14894a4f94f55c
- silent failure:
function NodeIterator() {}
- aggressive failure:
function NodeIterator() { throwDOMException(9) }
something like this