diff --git a/Tests/LibWeb/Text/expected/XHTML/script-execution.txt b/Tests/LibWeb/Text/expected/XHTML/script-execution.txt new file mode 100644 index 00000000000..631b0a07517 --- /dev/null +++ b/Tests/LibWeb/Text/expected/XHTML/script-execution.txt @@ -0,0 +1 @@ + PASS diff --git a/Tests/LibWeb/Text/expected/XHTML/script-execution.xhtml.txt b/Tests/LibWeb/Text/expected/XHTML/script-execution.xhtml.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Tests/LibWeb/Text/input/XHTML/script-execution.xhtml b/Tests/LibWeb/Text/input/XHTML/script-execution.xhtml new file mode 100644 index 00000000000..54efaf24618 --- /dev/null +++ b/Tests/LibWeb/Text/input/XHTML/script-execution.xhtml @@ -0,0 +1,10 @@ + + + + + + diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index b07b546cd6b..e13bba6a454 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1724,7 +1724,7 @@ WebIDL::ExceptionOr> Document::create_event(StringView i return JS::NonnullGCPtr(*event); } -void Document::set_pending_parsing_blocking_script(Badge, HTML::HTMLScriptElement* script) +void Document::set_pending_parsing_blocking_script(HTML::HTMLScriptElement* script) { m_pending_parsing_blocking_script = script; } diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 1d8d2a578c5..569fe1455e0 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -286,7 +286,7 @@ public: WebIDL::ExceptionOr> create_event(StringView interface); JS::NonnullGCPtr create_range(); - void set_pending_parsing_blocking_script(Badge, HTML::HTMLScriptElement*); + void set_pending_parsing_blocking_script(HTML::HTMLScriptElement*); HTML::HTMLScriptElement* pending_parsing_blocking_script() { return m_pending_parsing_blocking_script.ptr(); } JS::NonnullGCPtr take_pending_parsing_blocking_script(Badge); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index 8fab5828423..4c812342684 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -536,7 +536,7 @@ void HTMLScriptElement::prepare_script() // 5. Otherwise: else { // 1. Set el's parser document's pending parsing-blocking script to el. - m_parser_document->set_pending_parsing_blocking_script({}, this); + m_parser_document->set_pending_parsing_blocking_script(this); // FIXME: 2. Block rendering on el. @@ -563,7 +563,7 @@ void HTMLScriptElement::prepare_script() && is_parser_inserted() && m_parser_document->has_a_style_sheet_that_is_blocking_scripts()) { // 1. Set el's parser document's pending parsing-blocking script to el. - m_parser_document->set_pending_parsing_blocking_script({}, this); + m_parser_document->set_pending_parsing_blocking_script(this); // 2. Set el's ready to be parser-executed to true. (The parser will handle executing the script.) m_ready_to_be_parser_executed = true; diff --git a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp index a6dfaca4b07..165066e35e4 100644 --- a/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp +++ b/Userland/Libraries/LibWeb/XML/XMLDocumentBuilder.cpp @@ -117,25 +117,27 @@ void XMLDocumentBuilder::element_end(const XML::Name& name) // and then prepare the script element. auto& script_element = static_cast(*m_current_node); script_element.prepare_script(Badge {}); + // If this causes there to be a pending parsing-blocking script, then the user agent must run the following steps: - if (m_document->pending_parsing_blocking_script()) { - // Block this instance of the XML parser, such that the event loop will not run tasks that invoke it. + if (auto pending_parsing_blocking_script = m_document->pending_parsing_blocking_script()) { + // 1. Block this instance of the XML parser, such that the event loop will not run tasks that invoke it. // NOTE: Noop. - // Spin the event loop until the parser's Document has no style sheet that is blocking scripts and the pending parsing-blocking script's "ready to be parser-executed" flag is set. - if (m_document->has_a_style_sheet_that_is_blocking_scripts() || !script_element.is_ready_to_be_parser_executed()) { + // 2. Spin the event loop until the parser's Document has no style sheet that is blocking scripts and the pending parsing-blocking script's "ready to be parser-executed" flag is set. + if (m_document->has_a_style_sheet_that_is_blocking_scripts() || !pending_parsing_blocking_script->is_ready_to_be_parser_executed()) { HTML::main_thread_event_loop().spin_until([&] { - return !m_document->has_a_style_sheet_that_is_blocking_scripts() && script_element.is_ready_to_be_parser_executed(); + return !m_document->has_a_style_sheet_that_is_blocking_scripts() && pending_parsing_blocking_script->is_ready_to_be_parser_executed(); }); } - // Unblock this instance of the XML parser, such that tasks that invoke it can again be run. + // 3. Unblock this instance of the XML parser, such that tasks that invoke it can again be run. // NOTE: Noop. - // Execute the pending parsing-blocking script. - script_element.execute_script(); + // 4. Execute the script element given by the pending parsing-blocking script. + pending_parsing_blocking_script->execute_script(); - // There is no longer a pending parsing-blocking script. + // 5. Set the pending parsing-blocking script to null. + m_document->set_pending_parsing_blocking_script(nullptr); } } else if (m_scripting_support == XMLScriptingSupport::Enabled && m_current_node->is_svg_script_element()) { // https://www.w3.org/TR/SVGMobile12/struct.html#ProgressiveRendering