diff options
author | Andreas Kling <kling@serenityos.org> | 2022-09-17 17:36:47 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-09-17 18:53:26 +0200 |
commit | 07c4bf03b59c57b792f5ef4775f9bcf44a8c0194 (patch) | |
tree | f3a716aa16cf021e95b81e81e43f2265f1ca644a /Userland/Libraries | |
parent | df7e64d1036212cc0653895b22384c9601c98f89 (diff) | |
download | serenity-07c4bf03b59c57b792f5ef4775f9bcf44a8c0194.zip |
LibWeb: Add "scripts to execute in order as soon as possible"
Previously, we had accidentally conflated this set with the
similar-but-distinct "scripts to execute as soon as possible".
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.h | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp | 10 |
3 files changed, 25 insertions, 5 deletions
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<JS::Handle<HTML::HTMLScriptElement>> 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>, HTML::HTMLScriptElement& script) +{ + m_scripts_to_execute_in_order_as_soon_as_possible.append(JS::make_handle(script)); +} + +Vector<JS::Handle<HTML::HTMLScriptElement>> Document::take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>) +{ + return move(m_scripts_to_execute_in_order_as_soon_as_possible); +} + // https://dom.spec.whatwg.org/#dom-document-importnode ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> 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<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_as_soon_as_possible(Badge<HTML::HTMLParser>); Vector<JS::Handle<HTML::HTMLScriptElement>>& 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>, HTML::HTMLScriptElement&); + Vector<JS::Handle<HTML::HTMLScriptElement>> take_scripts_to_execute_in_order_as_soon_as_possible(Badge<HTML::HTMLParser>); + Vector<JS::Handle<HTML::HTMLScriptElement>>& 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<HTML::HTMLScriptElement> m_pending_parsing_blocking_script; + Vector<JS::Handle<HTML::HTMLScriptElement>> 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<JS::Handle<HTML::HTMLScriptElement>> 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<JS::Handle<HTML::HTMLScriptElement>> 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; |