diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index af4430c3ca..81bd541624 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1244,6 +1244,16 @@ Vector> Document::take_scripts_to_execute_as return move(m_scripts_to_execute_as_soon_as_possible); } +void Document::add_script_to_execute_in_order_as_soon_as_possible(Badge, HTML::HTMLScriptElement& script) +{ + m_scripts_to_execute_in_order_as_soon_as_possible.append(JS::make_handle(script)); +} + +Vector> Document::take_scripts_to_execute_in_order_as_soon_as_possible(Badge) +{ + return move(m_scripts_to_execute_in_order_as_soon_as_possible); +} + // https://dom.spec.whatwg.org/#dom-document-importnode ExceptionOr> Document::import_node(JS::NonnullGCPtr node, bool deep) { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index eefdf3f281..f4b2ece073 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -211,6 +211,10 @@ public: Vector> take_scripts_to_execute_as_soon_as_possible(Badge); Vector>& scripts_to_execute_as_soon_as_possible() { return m_scripts_to_execute_as_soon_as_possible; } + void add_script_to_execute_in_order_as_soon_as_possible(Badge, HTML::HTMLScriptElement&); + Vector> take_scripts_to_execute_in_order_as_soon_as_possible(Badge); + Vector>& scripts_to_execute_in_order_as_soon_as_possible() { return m_scripts_to_execute_in_order_as_soon_as_possible; } + QuirksMode mode() const { return m_quirks_mode; } bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; } void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; } @@ -398,7 +402,13 @@ private: String m_source; JS::GCPtr m_pending_parsing_blocking_script; + Vector> m_scripts_to_execute_when_parsing_has_finished; + + // https://html.spec.whatwg.org/multipage/scripting.html#list-of-scripts-that-will-execute-in-order-as-soon-as-possible + Vector> m_scripts_to_execute_in_order_as_soon_as_possible; + + // https://html.spec.whatwg.org/multipage/scripting.html#set-of-scripts-that-will-execute-as-soon-as-possible Vector> m_scripts_to_execute_as_soon_as_possible; QuirksMode m_quirks_mode { QuirksMode::No }; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index d6a26f4221..6635370d69 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -376,29 +376,29 @@ void HTMLScriptElement::prepare_script() else if ((m_script_type == ScriptType::Classic && has_attribute(HTML::AttributeNames::src) && !has_attribute(HTML::AttributeNames::async) && !m_non_blocking) || (m_script_type == ScriptType::Module && !has_attribute(HTML::AttributeNames::async) && !m_non_blocking)) { // Add the element to the end of the list of scripts that will execute in order as soon as possible associated with the element's preparation-time document. - m_preparation_time_document->add_script_to_execute_as_soon_as_possible({}, *this); + m_preparation_time_document->add_script_to_execute_in_order_as_soon_as_possible({}, *this); // When the script is ready, run the following steps: when_the_script_is_ready([this] { // 1. If the element is not now the first element in the list of scripts // that will execute in order as soon as possible to which it was added above, // then mark the element as ready but return without executing the script yet. - if (this != m_preparation_time_document->scripts_to_execute_as_soon_as_possible().first().ptr()) + if (this != m_preparation_time_document->scripts_to_execute_in_order_as_soon_as_possible().first().ptr()) return; for (;;) { // 2. Execution: Execute the script block corresponding to the first script element // in this list of scripts that will execute in order as soon as possible. - m_preparation_time_document->scripts_to_execute_as_soon_as_possible().first()->execute_script(); + m_preparation_time_document->scripts_to_execute_in_order_as_soon_as_possible().first()->execute_script(); // 3. Remove the first element from this list of scripts that will execute in order // as soon as possible. - (void)m_preparation_time_document->scripts_to_execute_as_soon_as_possible().take_first(); + (void)m_preparation_time_document->scripts_to_execute_in_order_as_soon_as_possible().take_first(); // 4. If this list of scripts that will execute in order as soon as possible is still // not empty and the first entry has already been marked as ready, then jump back // to the step labeled execution. - if (!m_preparation_time_document->scripts_to_execute_as_soon_as_possible().is_empty() && m_preparation_time_document->scripts_to_execute_as_soon_as_possible().first()->m_script_ready) + if (!m_preparation_time_document->scripts_to_execute_in_order_as_soon_as_possible().is_empty() && m_preparation_time_document->scripts_to_execute_in_order_as_soon_as_possible().first()->m_script_ready) continue; break;