Implement NodeIterator #21

Open
Raynos opened this Issue Oct 29, 2011 · 5 comments

Projects

None yet

2 participants

@Raynos
Owner
Raynos commented Oct 29, 2011

No description provided.

@termi
Collaborator
termi commented Jan 28, 2012

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
Owner
Raynos commented Jan 28, 2012
  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
Collaborator
termi commented Jan 28, 2012

"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
Owner
Raynos commented Jan 28, 2012

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

@termi
Collaborator
termi commented Jan 28, 2012

It's true, but in this case shim does the behavior that not in major browsers.

Any way termi1uc1/DOM-shim@26cb56d

  • silent failure: function NodeIterator() {}
  • aggressive failure: function NodeIterator() { throwDOMException(9) }

something like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment