Skip to content

Commit a25cb67

Browse files
committed
LibWeb/HTML: Update spec text related to template's content
Corresponds to: whatwg/html@aa52274
1 parent 39ad783 commit a25cb67

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

Libraries/LibWeb/DOM/Document.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,15 +4499,16 @@ void Document::decrement_throw_on_dynamic_markup_insertion_counter(Badge<HTML::H
44994499
// https://html.spec.whatwg.org/multipage/scripting.html#appropriate-template-contents-owner-document
45004500
GC::Ref<DOM::Document> Document::appropriate_template_contents_owner_document()
45014501
{
4502-
// 1. If doc is not a Document created by this algorithm, then:
4502+
// 1. If document is not a Document created by this algorithm:
45034503
if (!created_for_appropriate_template_contents()) {
4504-
// 1. If doc does not yet have an associated inert template document, then:
4504+
// 1. If document does not yet have an associated inert template document:
45054505
if (!m_associated_inert_template_document) {
4506-
// 1. Let new doc be a new Document (whose browsing context is null). This is "a Document created by this algorithm" for the purposes of the step above.
4506+
// 1. Let newDocument be a new Document (whose browsing context is null). This is "a Document created by
4507+
// this algorithm" for the purposes of the step above.
45074508
auto new_document = HTML::HTMLDocument::create(realm());
45084509
new_document->m_created_for_appropriate_template_contents = true;
45094510

4510-
// 2. If doc is an HTML document, mark new doc as an HTML document also.
4511+
// 2. If document is an HTML document, then mark newDocument as an HTML document also.
45114512
if (document_type() == Type::HTML)
45124513
new_document->set_document_type(Type::HTML);
45134514

@@ -4516,13 +4517,13 @@ GC::Ref<DOM::Document> Document::appropriate_template_contents_owner_document()
45164517
// Spec issue: https://github.com/whatwg/html/issues/11955
45174518
new_document->set_allow_declarative_shadow_roots(allow_declarative_shadow_roots());
45184519

4519-
// 3. Set doc's associated inert template document to new doc.
4520+
// 3. Set document's associated inert template document to newDocument.
45204521
m_associated_inert_template_document = new_document;
45214522
}
4522-
// 2. Set doc to doc's associated inert template document.
4523+
// 2. Set document to document's associated inert template document.
45234524
return *m_associated_inert_template_document;
45244525
}
4525-
// 2. Return doc.
4526+
// 2. Return document.
45264527
return *this;
45274528
}
45284529

Libraries/LibWeb/HTML/HTMLTemplateElement.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,17 @@ void HTMLTemplateElement::initialize(JS::Realm& realm)
2525
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTemplateElement);
2626
Base::initialize(realm);
2727

28-
m_content = realm.create<DOM::DocumentFragment>(m_document->appropriate_template_contents_owner_document());
29-
m_content->set_host(this);
28+
// https://html.spec.whatwg.org/multipage/scripting.html#template-contents
29+
// When a template element is created, the user agent must run the following steps to establish the template contents:
30+
// 1. Let document be the template element's node document's appropriate template contents owner document.
31+
auto document = m_document->appropriate_template_contents_owner_document();
32+
33+
// 2. Create a DocumentFragment object whose node document is document and host is the template element.
34+
auto document_fragment = realm.create<DOM::DocumentFragment>(document);
35+
document_fragment->set_host(this);
36+
37+
// 3. Set the template element's template contents to the newly created DocumentFragment object.
38+
m_content = document_fragment;
3039
}
3140

3241
void HTMLTemplateElement::visit_edges(Cell::Visitor& visitor)
@@ -38,11 +47,11 @@ void HTMLTemplateElement::visit_edges(Cell::Visitor& visitor)
3847
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-adopt-ext
3948
void HTMLTemplateElement::adopted_from(DOM::Document&)
4049
{
41-
// 1. Let doc be node's node document's appropriate template contents owner document.
42-
auto doc = document().appropriate_template_contents_owner_document();
50+
// 1. Let document be node's node document's appropriate template contents owner document.
51+
auto document = this->document().appropriate_template_contents_owner_document();
4352

44-
// 2. Adopt node's template contents (a DocumentFragment object) into doc.
45-
doc->adopt_node(content());
53+
// 2. Adopt node's template contents (a DocumentFragment object) into document.
54+
document->adopt_node(content());
4655
}
4756

4857
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext

Libraries/LibWeb/HTML/Parser/HTMLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
12631263
// 4. Set shadow's declarative to true.
12641264
shadow.set_declarative(true);
12651265

1266-
// 5. Set template's template contents property to shadow.
1266+
// 5. Set template's template contents to shadow.
12671267
as<HTMLTemplateElement>(*template_).set_template_contents(shadow);
12681268

12691269
// 6. Set shadow's available to element internals to true.

0 commit comments

Comments
 (0)