Index: Source/core/dom/Document.cpp |
diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
index 63cb1e518c441db49e3ef02308e29485cf4d1bf2..2a39ba3bcdf00131e864e3d56b8e0b20da082772 100644 |
--- a/Source/core/dom/Document.cpp |
+++ b/Source/core/dom/Document.cpp |
@@ -3252,9 +3252,9 @@ bool Document::childTypeAllowed(NodeType type) const |
return false; |
} |
-bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const |
+bool Document::canAcceptChild(const Node& newChild, const Node* oldChild, ExceptionState& exceptionState) const |
{ |
- if (oldChild.nodeType() == newChild.nodeType()) |
+ if (oldChild && oldChild->nodeType() == newChild.nodeType()) |
return true; |
int numDoctypes = 0; |
@@ -3263,7 +3263,7 @@ bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const |
// First, check how many doctypes and elements we have, not counting |
// the child we're about to remove. |
for (Node& c : NodeTraversal::childrenOf(*this)) { |
- if (c == oldChild) |
+ if (oldChild && *oldChild == c) |
esprehn
2014/12/05 19:18:24
it might be nice to rename "c" to "child" while yo
|
continue; |
switch (c.nodeType()) { |
@@ -3287,6 +3287,8 @@ bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const |
case DOCUMENT_FRAGMENT_NODE: |
case DOCUMENT_NODE: |
case TEXT_NODE: |
+ exceptionState.throwDOMException(HierarchyRequestError, "Nodes of type '" + newChild.nodeName() + |
+ "' may not be inserted inside nodes of type '#document'."); |
return false; |
case COMMENT_NODE: |
case PROCESSING_INSTRUCTION_NODE: |
@@ -3306,6 +3308,8 @@ bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const |
case DOCUMENT_FRAGMENT_NODE: |
case DOCUMENT_NODE: |
case TEXT_NODE: |
+ exceptionState.throwDOMException(HierarchyRequestError, "Nodes of type '" + newChild.nodeName() + |
+ "' may not be inserted inside nodes of type '#document'."); |
return false; |
case COMMENT_NODE: |
case PROCESSING_INSTRUCTION_NODE: |
@@ -3319,8 +3323,12 @@ bool Document::canReplaceChild(const Node& newChild, const Node& oldChild) const |
} |
} |
- if (numElements > 1 || numDoctypes > 1) |
+ if (numElements > 1 || numDoctypes > 1) { |
+ exceptionState.throwDOMException(HierarchyRequestError, |
+ String::format("Only one %s on document allowed.", |
+ numElements > 1 ? "element" : "doctype")); |
return false; |
+ } |
return true; |
} |