Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Unified Diff: Source/core/dom/Document.cpp

Issue 779173002: Be more strict about multiple documentElements (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « Source/core/dom/Document.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698