@@ -63,7 +63,7 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
6363 } else if (name == HTML::AttributeNames::referrerpolicy) {
6464 m_referrer_policy = ReferrerPolicy::from_string (value.value_or (" " _string)).value_or (ReferrerPolicy::ReferrerPolicy::EmptyString);
6565 } else if (name == HTML::AttributeNames::src) {
66- // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:html -element-post-connection-steps-6
66+ // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:concept -element-attributes-change-ext
6767 // 1. If namespace is not null, then return.
6868 if (namespace_.has_value ())
6969 return ;
@@ -73,8 +73,9 @@ void HTMLScriptElement::attribute_changed(FlyString const& name, Optional<String
7373 if (!value.has_value ())
7474 return ;
7575
76- // 2. If localName is src, then run the script HTML element post-connection steps, given element.
77- post_connection ();
76+ // 2. If localName is src and element is connected, then run the script HTML element post-connection steps, given element.
77+ if (is_connected ())
78+ post_connection ();
7879 } else if (name == HTML::AttributeNames::async) {
7980 // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:script-force-async
8081 // When an async attribute is added to a script element el, the user agent must set el's force async to false.
@@ -631,27 +632,27 @@ void HTMLScriptElement::prepare_script()
631632 }
632633}
633634
634- // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:html-element-post-connection- steps-4
635+ // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:children-changed- steps
635636void HTMLScriptElement::children_changed (ChildrenChangedMetadata const * metadata)
636637{
637638 Base::children_changed (metadata);
638639
639- // 1. Run the script HTML element post-connection steps, given the script element.
640+ // 1. If the script element is not connected, then return.
641+ if (!is_connected ())
642+ return ;
643+
644+ // 2. Run the script HTML element post-connection steps, given the script element.
640645 post_connection ();
641646}
642647
643- // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:prepare-the-script-element-5
648+ // https://html.spec.whatwg.org/multipage/scripting.html#script-processing-model:html-element-post-connection-steps
644649void HTMLScriptElement::post_connection ()
645650{
646- // 1. If insertedNode is not connected, then return.
647- if (!is_connected ())
648- return ;
649-
650- // 2. If insertedNode is parser-inserted, then return.
651+ // 1. If insertedNode is parser-inserted, then return.
651652 if (is_parser_inserted ())
652653 return ;
653654
654- // 3 . Prepare the script element given insertedNode.
655+ // 2 . Prepare the script element given insertedNode.
655656 prepare_script ();
656657}
657658
0 commit comments