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

Restructuring Document::importNode() code.

Makes importNode() code match to the DOM specification.
This CL has no behavior changes

Bug: 812089
Change-Id: I9aa7bf1401ba2e5b4342547e49ea7b567616801c
Reviewed-on: https://chromium-review.googlesource.com/923230Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537694}
parent ab5e2e89
...@@ -1241,47 +1241,37 @@ Node* Document::importNode(Node* imported_node, ...@@ -1241,47 +1241,37 @@ Node* Document::importNode(Node* imported_node,
bool deep, bool deep,
ExceptionState& exception_state) { ExceptionState& exception_state) {
// https://dom.spec.whatwg.org/#dom-document-importnode // https://dom.spec.whatwg.org/#dom-document-importnode
// TODO(tkent): Share code with cloneNode(). crbug.com/812089
CloneChildrenFlag clone_children =
deep ? CloneChildrenFlag::kClone : CloneChildrenFlag::kSkip;
switch (imported_node->getNodeType()) {
case kTextNode:
case kCdataSectionNode:
case kProcessingInstructionNode:
case kCommentNode:
case kDocumentTypeNode:
case kElementNode:
return imported_node->Clone(*this, clone_children);
case kAttributeNode: // 1. If node is a document or shadow root, then throw a "NotSupportedError"
// The following code doesn't create an Attr with namespace. See // DOMException.
// crbug.com/812105. if (imported_node->IsDocumentNode()) {
return Attr::Create( exception_state.ThrowDOMException(
*this, kNotSupportedError,
QualifiedName(g_null_atom, "The node provided is a document, which may not be imported.");
AtomicString(ToAttr(imported_node)->name()), return nullptr;
g_null_atom), }
ToAttr(imported_node)->value()); if (imported_node->IsShadowRoot()) {
case kDocumentFragmentNode: // ShadowRoot nodes should not be explicitly importable. Either they are
if (imported_node->IsShadowRoot()) { // imported along with their host node, or created implicitly.
// ShadowRoot nodes should not be explicitly importable. exception_state.ThrowDOMException(
// Either they are imported along with their host node, or created kNotSupportedError,
// implicitly. "The node provided is a shadow root, which may not be imported.");
exception_state.ThrowDOMException( return nullptr;
kNotSupportedError,
"The node provided is a shadow root, which may not be imported.");
return nullptr;
}
return imported_node->Clone(*this, clone_children);
case kDocumentNode:
exception_state.ThrowDOMException(
kNotSupportedError,
"The node provided is a document, which may not be imported.");
return nullptr;
} }
NOTREACHED(); // 2. Return a clone of node, with context object and the clone children flag
return nullptr; // set if deep is true.
if (imported_node->IsAttributeNode()) {
// The following code doesn't create an Attr with namespace. See
// crbug.com/812105.
return Attr::Create(
*this,
QualifiedName(g_null_atom, AtomicString(ToAttr(imported_node)->name()),
g_null_atom),
ToAttr(imported_node)->value());
}
return imported_node->Clone(
*this, deep ? CloneChildrenFlag::kClone : CloneChildrenFlag::kSkip);
} }
Node* Document::adoptNode(Node* source, ExceptionState& exception_state) { Node* Document::adoptNode(Node* source, ExceptionState& exception_state) {
......
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