Raynos / DOM-shim

Shims out the entire DOM4 API

Home Page:http://raynos.github.com/DOM-shim/test/test.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement NodeIterator

Raynos opened this issue · comments

There are a few questions of Implement NodeIterator (as for Implement NodeFilter and TreeWalker):

  1. Whic Excention we need to raise when user try to create object directly (new NodeIterator()): TypeError: Illegal constructor without code property as Chrome and FF do or DOMException: NOT_SUPPORTED_ERR with code == 9 as Opera do?
  2. Do we need to export NodeIterator interface in window object, so user can do document.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
  1. NodeIterator is just an interface. Doing new NodeIterator(); is undefined behaviour. I would normally just do window.NodeIterator = function () {} so basically throw no exceptions at all.
  2. The polyfill should allow document.createNodeIterator() instance NodeIterator to work. I would also do window.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