Commit 91aff562 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Code cleanup: Reorder code in ContainerNode::InsertBefore().

so that it matches to the DOM specification more.
This CL has no behavior changes.

Bug: 730412
Change-Id: I8881f2286e098238e255553bea8d2e1ab8b13ca4
Reviewed-on: https://chromium-review.googlesource.com/530924Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#478563}
parent 0a7a89f4
......@@ -356,10 +356,15 @@ Node* ContainerNode::InsertBefore(Node* new_child,
DCHECK(new_child);
// https://dom.spec.whatwg.org/#concept-node-pre-insert
// insertBefore(node, 0) is equivalent to appendChild(node)
// insertBefore(node, null) is equivalent to appendChild(node)
if (!ref_child)
return AppendChild(new_child, exception_state);
// 1. Ensure pre-insertion validity of node into parent before child.
if (!EnsurePreInsertionValidity(*new_child, ref_child, nullptr,
exception_state))
return new_child;
// 2. Let reference child be child.
// 3. If reference child is node, set it to node’s next sibling.
if (ref_child == new_child) {
......@@ -368,11 +373,7 @@ Node* ContainerNode::InsertBefore(Node* new_child,
return AppendChild(new_child, exception_state);
}
// 1. Ensure pre-insertion validity of node into parent before child.
if (!EnsurePreInsertionValidity(*new_child, ref_child, nullptr,
exception_state))
return new_child;
// 4. Adopt node into parent’s node document.
NodeVector targets;
DOMTreeMutationDetector detector(*new_child, *this);
if (!CollectChildrenAndRemoveFromOldParent(*new_child, targets,
......@@ -384,6 +385,7 @@ Node* ContainerNode::InsertBefore(Node* new_child,
return new_child;
}
// 5. Insert node into parent before reference child.
NodeVector post_insertion_notification_targets;
{
ChildListMutationScope mutation(*this);
......
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