You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Main difference is that a chunk of the "clone a node" steps are pulled
out into a "clone a single node" algorithm.
Reflects these spec PRs:
whatwg/dom#1332whatwg/dom#1334
Though this code is quite old so there may also be older spec changes
included here.
// 1. If document is not given, let document be node’s node document.
1031
+
// To clone a node given a node node and an optional document document (default node’s node document),
1032
+
// boolean subtree (default false), and node-or-null parent (default null):
1032
1033
if (!document)
1033
-
document = m_document.ptr();
1034
-
GC::Ptr<Node> copy;
1034
+
document = m_document;
1035
1035
1036
-
// 2. If node is an element, then:
1037
-
if (is<Element>(this)) {
1038
-
// 1. Let copy be the result of creating an element, given document, node’s local name, node’s namespace, node’s namespace prefix, and node’s is value, with the synchronous custom elements flag unset.
1039
-
auto& element = *verify_cast<Element>(this);
1040
-
auto element_copy = DOM::create_element(*document, element.local_name(), element.namespace_uri(), element.prefix(), element.is_value(), false).release_value_but_fixme_should_propagate_errors();
1036
+
// 1. Assert: node is not a document or node is document.
1037
+
VERIFY(!is_document() || this == document);
1041
1038
1042
-
// 2. For each attribute in node’s attribute list:
// 2. Let copy be the result of cloning a single node given node and document.
1040
+
auto copy = TRY(clone_single_node(*document));
1049
1041
1050
-
}
1051
-
// 3. Otherwise, let copy be a node that implements the same interfaces as node, and fulfills these additional requirements, switching on the interface node implements:
// 5. If subtree is true, then for each child of node’s children, in tree order:
1050
+
// clone a node given child with document set to document, subtree set to subtree, and parent set to copy.
1051
+
if (subtree) {
1052
+
for (auto child = first_child(); child; child = child->next_sibling()) {
1053
+
TRY(child->clone_node(document, subtree, copy));
1054
+
}
1122
1055
}
1123
1056
1124
-
// FIXME: 4. Set copy’s node document and document to copy, if copy is a document, and set copy’s node document to document otherwise.
1125
-
1126
-
// 5. Run any cloning steps defined for node in other applicable specifications and pass copy, node, document and the clone children flag if set, as parameters.
1127
-
TRY(cloned(*copy, clone_children));
1128
-
1129
-
// 6. If the clone children flag is set, clone all the children of node and append them to copy, with document as specified and the clone children flag being set.
1130
-
if (clone_children) {
1131
-
for (auto child = first_child(); child; child = child->next_sibling()) {
// 1. Set copy to the result of creating an element, given document, node’s local name, node’s namespace, node’s namespace prefix, and node’s is value.
1094
+
auto& element = *verify_cast<Element>(this);
1095
+
auto element_copy = TRY(DOM::create_element(document, element.local_name(), element.namespace_uri(), element.prefix(), element.is_value()));
1148
1096
1149
-
// 4. For each child child of node’s shadow root, in tree order:
1150
-
// append the result of cloning child with document and the clone children flag set, to copy’s shadow root.
1151
-
for (auto child = node_shadow_root.first_child(); child; child = child->next_sibling()) {
// FIXME: 1. Let copyAttribute be the result of cloning a single node given attribute and document.
1100
+
// 2. Append copyAttribute to copy.
1101
+
element_copy->append_attribute(name, value);
1102
+
});
1103
+
copy = move(element_copy);
1104
+
}
1105
+
1106
+
// 3. Otherwise, set copy to a node that implements the same interfaces as node, and fulfills these additional requirements, switching on the interface node implements:
0 commit comments