Optimization in Node::appendChild() is not spec-compliant
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2016 03:47:58 +0000 (03:47 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2016 03:47:58 +0000 (03:47 +0000)
commit6b2f30a97b36902a947801dadca7a880c49a663b
tree219fa0498defa47e3a1bb701a7374f23af82e535
parent8564d9701cedc7cc7f100747fd44517bec31ab37
Optimization in Node::appendChild() is not spec-compliant
https://bugs.webkit.org/show_bug.cgi?id=160728

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C test now that more checks are passing.

* web-platform-tests/dom/ranges/Range-mutations-expected.txt:

Source/WebCore:

We have an optimization in Node::appendChild() that avoid doing any work
if the node to be appended is already the last child. This optimization
is not spec-compliant:
- https://dom.spec.whatwg.org/#dom-node-appendchild

The issue is that this is observable via DOM Mutation observers / listeners
or DOM ranges.

To address the issue, this patch drops the optimization in appendChild().
This seems like an odd case to optimize for as I am not convinced it is
common to call parent.appendChild(parent.lastChild). If it turns out to
regress the performance of things we care about though, we could fall
back to do the optimization only when it is not observable.

Test: fast/dom/Node/appendChild-no-op-mutationobserver.html

* dom/ContainerNode.cpp:
(WebCore::ContainerNode::appendChild): Deleted.

LayoutTests:

Add layout test to make sure that mutation events are always fired
when calling Node::appendChild(), even if the new node is already
the last child.

* fast/dom/Node/appendChild-no-op-mutationobserver-expected.txt: Added.
* fast/dom/Node/appendChild-no-op-mutationobserver.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204322 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/dom/Node/appendChild-no-op-mutationobserver-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/Node/appendChild-no-op-mutationobserver.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/dom/ranges/Range-mutations-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp