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

Unified Diff: third_party/WebKit/Source/core/dom/Range.cpp

Issue 2745443003: DOM Range: surroundContents() should not check if newParent is in ancestors beforehand. (Closed)
Patch Set: . Created 3 years, 9 months 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 | « third_party/WebKit/LayoutTests/shadow-dom/range-surround-contents.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Range.cpp
diff --git a/third_party/WebKit/Source/core/dom/Range.cpp b/third_party/WebKit/Source/core/dom/Range.cpp
index 6dcbf0c142f611fd2919af1e46b77c9985a288af..ddc3f33db165149f0f212c3597461b298dd1f1a3 100644
--- a/third_party/WebKit/Source/core/dom/Range.cpp
+++ b/third_party/WebKit/Source/core/dom/Range.cpp
@@ -1319,6 +1319,7 @@ bool Range::selectNodeContents(Node* refNode, Position& start, Position& end) {
return true;
}
+// https://dom.spec.whatwg.org/#dom-range-surroundcontents
void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) {
if (!newParent) {
// FIXME: Generated bindings code never calls with null, and neither should
@@ -1327,7 +1328,8 @@ void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) {
return;
}
- // InvalidStateError: Raised if the Range partially selects a non-Text node.
+ // 1. If a non-Text node is partially contained in the context object, then
+ // throw an InvalidStateError.
Node* startNonTextContainer = m_start.container();
if (startNonTextContainer->getNodeType() == Node::kTextNode)
startNonTextContainer = startNonTextContainer->parentNode();
@@ -1340,9 +1342,8 @@ void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) {
return;
}
- // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType,
- // Notation,
- // Document, or DocumentFragment node.
+ // 2. If newParent is a Document, DocumentType, or DocumentFragment node, then
+ // throw an InvalidNodeTypeError.
switch (newParent->getNodeType()) {
case Node::kAttributeNode:
case Node::kDocumentFragmentNode:
@@ -1387,31 +1388,29 @@ void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) {
return;
}
- if (newParent->isShadowIncludingInclusiveAncestorOf(m_start.container())) {
- exceptionState.throwDOMException(HierarchyRequestError,
- "The node provided contains the insertion "
- "point; it may not be inserted into "
- "itself.");
- return;
- }
-
- // FIXME: Do we need a check if the node would end up with a child node of a
tkent 2017/03/09 22:36:33 This FIXME comment was bogus. The check already ex
- // type not allowed by the type of node?
-
+ // 4. If newParent has children, replace all with null within newParent.
while (Node* n = newParent->firstChild()) {
toContainerNode(newParent)->removeChild(n, exceptionState);
if (exceptionState.hadException())
return;
}
+
+ // 3. Let fragment be the result of extracting context object.
DocumentFragment* fragment = extractContents(exceptionState);
if (exceptionState.hadException())
return;
+
+ // 5. If newParent has children, replace all with null within newParent.
insertNode(newParent, exceptionState);
if (exceptionState.hadException())
return;
+
+ // 6. Append fragment to newParent.
newParent->appendChild(fragment, exceptionState);
if (exceptionState.hadException())
return;
+
+ // 7. Select newParent within context object.
selectNode(newParent, exceptionState);
}
« no previous file with comments | « third_party/WebKit/LayoutTests/shadow-dom/range-surround-contents.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698