RESOLVED FIXED 160640
a.replaceChild(a, a) should throw a HierarchyRequestError
https://bugs.webkit.org/show_bug.cgi?id=160640
Summary a.replaceChild(a, a) should throw a HierarchyRequestError
Chris Dumez
Reported 2016-08-06 16:16:10 PDT
a.replaceChild(a, a) should throw a HierarchyRequestError, because 'a' is a host-including inclusive ancestor of 'a': - https://dom.spec.whatwg.org/#concept-node-replace However, the call is merely ignored in WebKit.
Attachments
Patch (4.08 KB, patch)
2016-08-06 16:17 PDT, Chris Dumez
no flags
Patch (6.48 KB, patch)
2016-08-06 19:54 PDT, Chris Dumez
no flags
Chris Dumez
Comment 1 2016-08-06 16:17:31 PDT
Darin Adler
Comment 2 2016-08-06 18:37:53 PDT
Comment on attachment 285506 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=285506&action=review > Source/WebCore/dom/ContainerNode.cpp:407 > + if (&oldChild == &newChild) // nothing to do > + return true; Why move this past the NOT_FOUND_ERR check too and not just the validity check? Since this check is fast and it seems like a case we would like to optimize, I’d like this to remain as early in the function as practical.
Chris Dumez
Comment 3 2016-08-06 18:45:30 PDT
Comment on attachment 285506 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=285506&action=review >> Source/WebCore/dom/ContainerNode.cpp:407 >> + return true; > > Why move this past the NOT_FOUND_ERR check too and not just the validity check? Since this check is fast and it seems like a case we would like to optimize, I’d like this to remain as early in the function as practical. But the whole point is that we should throw in cases we are expected to throw. If you call b.replaceChild(a, a) and a is not a child of b, then we need to throw a NotFoundError. Note that this "optimization" does not seem to be in the specification so chances are we will eventually have to skip it in cases where it is observable.
Darin Adler
Comment 4 2016-08-06 19:09:01 PDT
Makes sense; I misread the check as somehow comparing the parents of oldChild and newChild. We should add a test for the NOT_FOUND case when the two are the same since it seems we did not have one. If there had been a test I would not have been confused.
Chris Dumez
Comment 5 2016-08-06 19:21:13 PDT
(In reply to comment #4) > Makes sense; I misread the check as somehow comparing the parents of > oldChild and newChild. We should add a test for the NOT_FOUND case when the > two are the same since it seems we did not have one. If there had been a > test I would not have been confused. Good point, I'll add a test before landing.
Chris Dumez
Comment 6 2016-08-06 19:54:57 PDT
WebKit Commit Bot
Comment 7 2016-08-06 20:24:23 PDT
Comment on attachment 285517 [details] Patch Clearing flags on attachment: 285517 Committed r204237: <http://trac.webkit.org/changeset/204237>
WebKit Commit Bot
Comment 8 2016-08-06 20:24:28 PDT
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.