@@ -1154,7 +1154,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
11541154 // -> A start tag whose tag name is "template"
11551155 if (token.is_start_tag () && token.tag_name () == HTML::TagNames::template_) {
11561156 // Run these steps:
1157- // 1. Let template start tag be the start tag.
1157+ // 1. Let templateStartTag be the start tag.
11581158 auto const & template_start_tag = token;
11591159
11601160 // 2. Insert a marker at the end of the list of active formatting elements.
@@ -1191,7 +1191,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
11911191 }
11921192
11931193 // 9. If any of the following are false:
1194- // - templateStartTag's shadowrootmode is not in the none state;
1194+ // - templateStartTag's shadowrootmode is not in the None state;
11951195 // - document's allow declarative shadow roots is true; or
11961196 // - the adjusted current node is not the topmost element in the stack of open elements,
11971197 if (!shadowrootmode.has_value ()
@@ -1213,13 +1213,13 @@ void HTMLParser::handle_in_head(HTMLToken& token)
12131213 auto mode = shadowrootmode.value ();
12141214
12151215 // 4. Let clonable be true if templateStartTag has a shadowrootclonable attribute; otherwise false.
1216- auto clonable = template_start_tag.attribute (HTML::AttributeNames::shadowrootclonable). has_value ( );
1216+ auto clonable = template_start_tag.has_attribute (HTML::AttributeNames::shadowrootclonable);
12171217
12181218 // 5. Let serializable be true if templateStartTag has a shadowrootserializable attribute; otherwise false.
1219- auto serializable = template_start_tag.attribute (HTML::AttributeNames::shadowrootserializable). has_value ( );
1219+ auto serializable = template_start_tag.has_attribute (HTML::AttributeNames::shadowrootserializable);
12201220
12211221 // 6. Let delegatesFocus be true if templateStartTag has a shadowrootdelegatesfocus attribute; otherwise false.
1222- auto delegates_focus = template_start_tag.attribute (HTML::AttributeNames::shadowrootdelegatesfocus). has_value ( );
1222+ auto delegates_focus = template_start_tag.has_attribute (HTML::AttributeNames::shadowrootdelegatesfocus);
12231223
12241224 // 7. If declarativeShadowHostElement is a shadow host, then insert an element at the adjusted insertion location with template.
12251225 if (declarative_shadow_host_element.is_shadow_host ()) {
@@ -1231,31 +1231,39 @@ void HTMLParser::handle_in_head(HTMLToken& token)
12311231
12321232 // 8. Otherwise:
12331233 else {
1234- // FIXME: The spec substeps here now deal with custom element registries. Update to match that .
1234+ // FIXME: 1. Let registry be null if templateStartTag has a shadowrootcustomelementregistry attribute; otherwise declarativeShadowHostElement's node document's custom element registry .
12351235
1236- // 1 . Attach a shadow root with declarativeShadowHostElement, mode, clonable, serializable, delegatesFocus, and "named".
1237- // If an exception is thrown, then catch it, report the exception, insert an element at the adjusted insertion location with template, and return .
1236+ // 2 . Attach a shadow root with declarativeShadowHostElement, mode, clonable, serializable, delegatesFocus, "named", and registry .
1237+ // FIXME: and registry .
12381238 auto result = declarative_shadow_host_element.attach_a_shadow_root (mode, clonable, serializable, delegates_focus, Bindings::SlotAssignmentMode::Named);
1239+ // If an exception is thrown, then catch it and:
12391240 if (result.is_error ()) {
1240- report_exception ( Bindings::exception_to_throw_completion ( vm (), result. release_error ()), realm ());
1241+ // 1. Insert an element at the adjusted insertion location with template.
12411242 // FIXME: We do manual "insert before" instead of "insert an element at the adjusted insertion location" here
12421243 // Otherwise, the new insertion location will be inside the template's contents, which is not what we want here.
12431244 // This might be a spec bug(?)
12441245 adjusted_insertion_location.parent ->insert_before (*template_, adjusted_insertion_location.insert_before_sibling );
1246+
1247+ // 2. The user agent may report an error to the developer console.
1248+ report_exception (Bindings::exception_to_throw_completion (vm (), result.release_error ()), realm ());
1249+
1250+ // 3. Return.
12451251 return ;
12461252 }
12471253
1248- // 2 . Let shadow be declarativeShadowHostElement's shadow root.
1254+ // 3 . Let shadow be declarativeShadowHostElement's shadow root.
12491255 auto & shadow = *declarative_shadow_host_element.shadow_root ();
12501256
1251- // 3 . Set shadow's declarative to true.
1257+ // 4 . Set shadow's declarative to true.
12521258 shadow.set_declarative (true );
12531259
1254- // 4 . Set template's template contents property to shadow.
1260+ // 5 . Set template's template contents property to shadow.
12551261 as<HTMLTemplateElement>(*template_).set_template_contents (shadow);
12561262
1257- // 5 . Set shadow's available to element internals to true.
1263+ // 6 . Set shadow's available to element internals to true.
12581264 shadow.set_available_to_element_internals (true );
1265+
1266+ // FIXME: 7. If templateStartTag has a shadowrootcustomelementregistry attribute, then set shadow's keep custom element registry null to true.
12591267 }
12601268 }
12611269
0 commit comments