Re: [whatwg/dom] Some tweaks for traverse algo and others (#87)

>do you have a test for that?

Consider the following DOM and script:

```
<div id="root"><div id="n1"><div id="n2"><div id="n3"></div></div></div></div>

<script>
const walker = document.createTreeWalker(
  document.getElementById('root'),
  NodeFilter.SHOW_ELEMENT,
  (e) => {
    return e.id === 'n2' ?
      NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
  }
);
let node;
while(node = walker.nextNode()){
  console.log(node.id);
}
</script>
```

Tracing the [TreeWalker.nextNode()](https://dom.spec.whatwg.org/#dom-treewalker-nextnode) method in the current spec, the above nextNode() would return
 n1, *then node n3*; but UAs return only n1 (tested in FireFox, Chrome).

- The 1st call of nextNode():
  (currentNode is 'root'.)
1. In the loop 3.1:
  Returns node n1, with filtering result FILTER_ACCEPT.
  (currentNode becomes n1.)

- The 2nd call of nextNode():
1. In the loop 3.1:
  Breaks at the node n2, with filtering result FILTER_REJECT.
  The node variable is set to node n2.
1. step 3.2:
  node variable is set to n2's first chlid, which is the node n3.
  (This does not seem to match the actual behavior.)
1. step 3.3, 3.4:
  The result of filtering n3 is FILTER_ACCEPT, and returns n3.

I think the step 3.2 is also contrary to the semantics of FILTER_REJECT, “reject all inclisive descemdants”.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/87#issuecomment-374385254

Received on Monday, 19 March 2018 21:29:15 UTC