Commit fc9b71a6 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Range.insertNode() should accept ShadowRoot argument.

The DOM specification [1] doesn't ask any special handling for ShadowRoot in
Range.insertNode.  So we should treat a ShadowRoot same as DocumentFragment.

[1] https://dom.spec.whatwg.org/#concept-range-insert

Bug: 732220
Change-Id: Id907833514abcd447d5458a973a7a077cc3297c4
Reviewed-on: https://chromium-review.googlesource.com/530607Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478565}
parent 64db6199
<!DOCTYPE html>
<body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
var range = document.createRange();
var rangeContainer = document.createElement('div');
range.setStart(rangeContainer, 0);
range.setEnd(rangeContainer, 0);
var shadowRoot = document.createElement('span').attachShadow({mode: "open"});
var h1 = shadowRoot.appendChild(document.createElement('h1'));
range.insertNode(shadowRoot);
assert_equals(rangeContainer.firstChild, h1);
}, 'Test if Range.prototype.insertNode() should accept ShadowRoot input.');
</script>
</body>
......@@ -885,8 +885,7 @@ void Range::insertNode(Node* new_node, ExceptionState& exception_state) {
Node::NodeType new_node_type = new_node->getNodeType();
int num_new_children;
if (new_node_type == Node::kDocumentFragmentNode &&
!new_node->IsShadowRoot()) {
if (new_node_type == Node::kDocumentFragmentNode) {
// check each child node, not the DocumentFragment itself
num_new_children = 0;
for (Node* c = ToDocumentFragment(new_node)->firstChild(); c;
......@@ -921,8 +920,7 @@ void Range::insertNode(Node* new_node, ExceptionState& exception_state) {
}
}
// InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation,
// ShadowRoot or Document node.
// InvalidNodeTypeError: Raised if new_node is an Attr or Document node.
switch (new_node_type) {
case Node::kAttributeNode:
case Node::kDocumentNode:
......@@ -932,13 +930,6 @@ void Range::insertNode(Node* new_node, ExceptionState& exception_state) {
"' node, which may not be inserted here.");
return;
default:
if (new_node->IsShadowRoot()) {
exception_state.ThrowDOMException(kInvalidNodeTypeError,
"The node to be inserted is a shadow "
"root, which may not be inserted "
"here.");
return;
}
break;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment