mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +00:00
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".
This commit is contained in:
parent
df7e64d103
commit
07c4bf03b5
3 changed files with 25 additions and 5 deletions
|
@ -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);
|
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
|
// https://dom.spec.whatwg.org/#dom-document-importnode
|
||||||
ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> node, bool deep)
|
ExceptionOr<JS::NonnullGCPtr<Node>> Document::import_node(JS::NonnullGCPtr<Node> node, bool deep)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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>> 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; }
|
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; }
|
QuirksMode mode() const { return m_quirks_mode; }
|
||||||
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
|
bool in_quirks_mode() const { return m_quirks_mode == QuirksMode::Yes; }
|
||||||
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
|
void set_quirks_mode(QuirksMode mode) { m_quirks_mode = mode; }
|
||||||
|
@ -398,7 +402,13 @@ private:
|
||||||
String m_source;
|
String m_source;
|
||||||
|
|
||||||
JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;
|
JS::GCPtr<HTML::HTMLScriptElement> m_pending_parsing_blocking_script;
|
||||||
|
|
||||||
Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_when_parsing_has_finished;
|
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;
|
Vector<JS::Handle<HTML::HTMLScriptElement>> m_scripts_to_execute_as_soon_as_possible;
|
||||||
|
|
||||||
QuirksMode m_quirks_mode { QuirksMode::No };
|
QuirksMode m_quirks_mode { QuirksMode::No };
|
||||||
|
|
|
@ -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)
|
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)) {
|
|| (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.
|
// 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, run the following steps:
|
||||||
when_the_script_is_ready([this] {
|
when_the_script_is_ready([this] {
|
||||||
// 1. If the element is not now the first element in the list of scripts
|
// 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,
|
// 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.
|
// 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;
|
return;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// 2. Execution: Execute the script block corresponding to the first script element
|
// 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.
|
// 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
|
// 3. Remove the first element from this list of scripts that will execute in order
|
||||||
// as soon as possible.
|
// 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
|
// 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
|
// not empty and the first entry has already been marked as ready, then jump back
|
||||||
// to the step labeled execution.
|
// 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;
|
continue;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue