Raynos / DOM-shim

Shims out the entire DOM4 API
http://raynos.github.com/DOM-shim/test/test.html
155 stars 15 forks source link

Implement NodeIterator #21

Open Raynos opened 12 years ago

termi commented 12 years ago

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
Raynos commented 12 years ago
  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.
termi commented 12 years ago

"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.

Raynos commented 12 years ago

Why does it matter. It's completely undefined behaviour. There is no specification that says it should throw exceptions. It either does

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 ;)

termi commented 12 years ago

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

something like this