[whatwg/dom] NodeIterator's pre-removing steps does not match browsers (#907)

The following is a reduced example from the [wpt](https://github.com/web-platform-tests/wpt/blob/master/dom/traversal/NodeIterator-removal.html), where "paras[0]" is the node being removed and "paras[0].firstChild" is the node used to create the NodeIterator.
```js
const div = document.createElement('div');
const p = document.createElement('p');
const t = p.appendChild(document.createTextNode('Hello'));
div.appendChild(p);

const iter = document.createNodeIterator(t);
div.removeChild(p);
```

The html structure is:
```html
<div>
  <p>Hello</p>
</div>
```

The NodeIterator's pre-removing steps:
1. The node being removed (`p`) is an inclusive ancestor of node iterator's reference (`t`), so this passes.
2. The node iterator's `pointer before reference` starts out as `true`, so this passes.
    1. There is no following node that is an inclusive descendant of node iterator's `root` (`t`) that is also not an inclusive descendant of the node being removed (`p`), which means next is null.
    2. Next is null, so we move to the next step.
    3. **Because next is null, node iterator's `pointer before reference` gets set to false.**
3. **The node being removed (`p`) has no previous sibling, so node iterator's `reference` gets set to the removed node's (`p`) parent, which is `div`.**

Following the spec, the NodeIterator gets changed to the following:
```js
NodeIterator {
  root: t,
  referenceNode: div,
  pointerBeforeReferenceNode: false
}
```

Browsers, however, seem to leave the NodeIterator unchanged, which matches the test expectations:
```js
NodeIterator {
  root: t,
  referenceNode: t,
  pointerBeforeReferenceNode: true
}
```

-- 
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/907

Received on Monday, 26 October 2020 20:57:04 UTC