From 37d074109957e5d4c49c89ff69d39362ce729d8c Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 27 Nov 2025 09:54:47 +0000 Subject: [PATCH] LibWeb/HTML: Implement HTMLTemplateElement.content to spec No real behaviour change - it just means we VERIFY before returning the value we returned before. --- Libraries/LibWeb/HTML/HTMLTemplateElement.cpp | 10 ++++++++++ Libraries/LibWeb/HTML/HTMLTemplateElement.h | 2 ++ Libraries/LibWeb/HTML/HTMLTemplateElement.idl | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp b/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp index c3de44efe2c..8d705de62dd 100644 --- a/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp @@ -76,6 +76,16 @@ WebIDL::ExceptionOr HTMLTemplateElement::cloned(Node& copy, bool subtree) return {}; } +// https://html.spec.whatwg.org/multipage/scripting.html#dom-template-content +GC::Ref HTMLTemplateElement::content_for_bindings() const +{ + // 1. Assert: this's template contents is not a ShadowRoot node. + VERIFY(!m_content->is_shadow_root()); + + // 2. Return this's template contents. + return *m_content; +} + void HTMLTemplateElement::set_template_contents(GC::Ref contents) { m_content = contents; diff --git a/Libraries/LibWeb/HTML/HTMLTemplateElement.h b/Libraries/LibWeb/HTML/HTMLTemplateElement.h index 9b5f910ba7c..5a0dfbcc9ff 100644 --- a/Libraries/LibWeb/HTML/HTMLTemplateElement.h +++ b/Libraries/LibWeb/HTML/HTMLTemplateElement.h @@ -21,6 +21,8 @@ public: GC::Ref content() { return *m_content; } GC::Ref const content() const { return *m_content; } + GC::Ref content_for_bindings() const; + void set_template_contents(GC::Ref); virtual void adopted_from(DOM::Document&) override; diff --git a/Libraries/LibWeb/HTML/HTMLTemplateElement.idl b/Libraries/LibWeb/HTML/HTMLTemplateElement.idl index 3301ba68d05..49d24a7c499 100644 --- a/Libraries/LibWeb/HTML/HTMLTemplateElement.idl +++ b/Libraries/LibWeb/HTML/HTMLTemplateElement.idl @@ -7,7 +7,7 @@ interface HTMLTemplateElement : HTMLElement { [HTMLConstructor] constructor(); - readonly attribute DocumentFragment content; + [ImplementedAs=content_for_bindings] readonly attribute DocumentFragment content; [Reflect=shadowrootmode, Enumerated=ShadowRootMode, CEReactions] attribute DOMString shadowRootMode; [Reflect=shadowrootdelegatesfocus, CEReactions] attribute boolean shadowRootDelegatesFocus; [Reflect=shadowrootclonable, CEReactions] attribute boolean shadowRootClonable;