Skip to content

Commit 523c53a

Browse files
AtkinsSJpbrw
authored andcommitted
LibWeb/HTML: Update cloning steps to current spec algorithms
Reflects the changes in whatwg/html#10859 I've also added missing calls to the Base::cloned() method, and modified a couple of spec links to point to the multipage version. I took the liberty to fix a spec typo, and submitted a PR for it: whatwg/html#10892
1 parent f5f7948 commit 523c53a

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

Libraries/LibWeb/HTML/HTMLInputElement.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,9 +1660,11 @@ void HTMLInputElement::apply_presentational_hints(GC::Ref<CSS::CascadedPropertie
16601660
}
16611661

16621662
// https://html.spec.whatwg.org/multipage/input.html#the-input-element%3Aconcept-node-clone-ext
1663-
WebIDL::ExceptionOr<void> HTMLInputElement::cloned(DOM::Node& copy, bool)
1663+
WebIDL::ExceptionOr<void> HTMLInputElement::cloned(DOM::Node& copy, bool subtree)
16641664
{
1665-
// The cloning steps for input elements must propagate the value, dirty value flag, checkedness, and dirty checkedness flag from the node being cloned to the copy.
1665+
TRY(Base::cloned(copy, subtree));
1666+
1667+
// The cloning steps for input elements given node, copy, and subtree are to propagate the value, dirty value flag, checkedness, and dirty checkedness flag from node to copy.
16661668
auto& input_clone = verify_cast<HTMLInputElement>(copy);
16671669
input_clone.m_value = m_value;
16681670
input_clone.m_dirty_value = m_dirty_value;

Libraries/LibWeb/HTML/HTMLOrSVGElement.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void HTMLOrSVGElement<ElementBase>::blur()
5656
// User agents may selectively or uniformly ignore calls to this method for usability reasons.
5757
}
5858

59-
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
59+
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
6060
template<typename ElementBase>
6161
void HTMLOrSVGElement<ElementBase>::attribute_changed(FlyString const& local_name, Optional<String> const&, Optional<String> const& value, Optional<FlyString> const& namespace_)
6262
{
@@ -76,17 +76,17 @@ void HTMLOrSVGElement<ElementBase>::attribute_changed(FlyString const& local_nam
7676
}
7777
}
7878

79-
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
79+
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
8080
template<typename ElementBase>
8181
WebIDL::ExceptionOr<void> HTMLOrSVGElement<ElementBase>::cloned(DOM::Node& copy, bool)
8282
{
83-
// The cloning steps for elements that include HTMLOrSVGElement must set the
84-
// [[CryptographicNonce]] slot on the copy to the value of the slot on the element being cloned.
83+
// The cloning steps for elements that include HTMLOrSVGElement given node, copy, and subtree
84+
// are to set copy's [[CryptographicNonce]] to node's [[CryptographicNonce]].
8585
static_cast<ElementBase&>(copy).m_cryptographic_nonce = m_cryptographic_nonce;
8686
return {};
8787
}
8888

89-
// https://html.spec.whatwg.org/#dom-noncedelement-nonce
89+
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#dom-noncedelement-nonce
9090
template<typename ElementBase>
9191
void HTMLOrSVGElement<ElementBase>::inserted()
9292
{

Libraries/LibWeb/HTML/HTMLTemplateElement.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,24 @@ void HTMLTemplateElement::adopted_from(DOM::Document&)
4646
}
4747

4848
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext
49-
WebIDL::ExceptionOr<void> HTMLTemplateElement::cloned(Node& copy, bool clone_children)
49+
WebIDL::ExceptionOr<void> HTMLTemplateElement::cloned(Node& copy, bool subtree)
5050
{
51-
// 1. If the clone children flag is not set in the calling clone algorithm, return.
52-
if (!clone_children)
51+
TRY(Base::cloned(copy, subtree));
52+
53+
// The cloning steps for template elements given node, copy, and subtree are:
54+
55+
// 1. If subtree is false, then return.
56+
if (!subtree)
5357
return {};
5458

55-
// 2. Let copied contents be the result of cloning all the children of node's template contents,
56-
// with document set to copy's template contents's node document, and with the clone children flag set.
57-
// 3. Append copied contents to copy's template contents.
58-
auto& template_clone = verify_cast<HTMLTemplateElement>(copy);
59+
// 2. For each child of node's template contents's children, in tree order:
60+
// clone a node given child with document set to copy's template contents's node document,
61+
// subtree set to true, and parent set to copy's template contents.
62+
auto& template_copy = verify_cast<HTMLTemplateElement>(copy);
5963
for (auto child = content()->first_child(); child; child = child->next_sibling()) {
60-
auto cloned_child = TRY(child->clone_node(&template_clone.content()->document(), true));
61-
TRY(template_clone.content()->append_child(cloned_child));
64+
TRY(child->clone_node(&template_copy.content()->document(), true, template_copy.content()));
6265
}
66+
6367
return {};
6468
}
6569

Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ void HTMLTextAreaElement::clear_algorithm()
136136
}
137137

138138
// https://html.spec.whatwg.org/multipage/forms.html#the-textarea-element:concept-node-clone-ext
139-
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool)
139+
WebIDL::ExceptionOr<void> HTMLTextAreaElement::cloned(DOM::Node& copy, bool subtree)
140140
{
141-
// The cloning steps for textarea elements must propagate the raw value and dirty value flag from the node being cloned to the copy.
141+
TRY(Base::cloned(copy, subtree));
142+
143+
// The cloning steps for textarea elements given node, copy, and subtree are to propagate the raw value and dirty value flag from node to copy.
142144
auto& textarea_copy = verify_cast<HTMLTextAreaElement>(copy);
143145
textarea_copy.m_raw_value = m_raw_value;
144146
textarea_copy.m_dirty_value = m_dirty_value;

0 commit comments

Comments
 (0)