forked from WebKit/WebKit-http
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Node::replaceChild() can create bad DOM topology with MutationEvent
https://bugs.webkit.org/show_bug.cgi?id=92619 Reviewed by Ryosuke Niwa. Source/WebCore: Node::replaceChild() calls insertBeforeCommon() after dispatching a MutationEvent event for removeChild(). But insertBeforeCommon() expects call sites to check the invariant and doesn't have suffient check. So a MutationEvent handler can let some bad tree topology to slip into insertBeforeCommon(). This change adds a guard for checking the invariant using checkReplaceChild() between removeChild() and insertBeforeCommon(). Test: fast/events/mutation-during-replace-child.html * dom/ContainerNode.cpp: (WebCore::ContainerNode::replaceChild): Added a guard. LayoutTests: * fast/events/mutation-during-replace-child-expected.txt: Added. * fast/events/mutation-during-replace-child.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@124156 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Showing
5 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
LayoutTests/fast/events/mutation-during-replace-child-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Ensures that replaceChild() throws an exception if mutation even handler does something wrong | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS target.replaceChild(newChild, oldChild); threw exception Error: HIERARCHY_REQUEST_ERR: DOM Exception 3. | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
32 changes: 32 additions & 0 deletions
32
LayoutTests/fast/events/mutation-during-replace-child.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../js/resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<div id="target"> | ||
<b></b><b id="oldChild"></b><b></b> | ||
</div> | ||
<div id="newChild"></div> | ||
</div> | ||
|
||
<script> | ||
description("Ensures that replaceChild() throws an exception if mutation even handler does something wrong"); | ||
var target = document.getElementById('target'); | ||
var oldChild = document.getElementById('oldChild'); | ||
var newChild = document.getElementById('newChild'); | ||
|
||
function handler(){ | ||
document.removeEventListener("DOMNodeRemoved", handler, false); | ||
newChild.parentNode.removeChild(newChild); | ||
target.parentNode.removeChild(target); | ||
newChild.appendChild(target); | ||
} | ||
document.addEventListener("DOMNodeRemoved", handler, false); | ||
shouldThrow("target.replaceChild(newChild, oldChild);", "'Error: HIERARCHY_REQUEST_ERR: DOM Exception 3'"); | ||
</script> | ||
<script src="../js/resources/js-test-post.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters