LibWeb: Implement immediate execution in HTMLScriptElement preparation

In some cases, Dr. HTML says we should execute the script right away
even if other scripts are running.
This commit is contained in:
Andreas Kling 2020-05-26 15:55:18 +02:00
parent ecd25ce6c7
commit 7bb69bb9bf
Notes: sideshowbarker 2024-07-19 06:06:38 +09:00
2 changed files with 16 additions and 2 deletions

View File

@ -115,6 +115,17 @@ void HTMLScriptElement::inserted_into(Node& new_parent)
document().interpreter().run(*program);
}
void HTMLScriptElement::execute_script()
{
auto parser = JS::Parser(JS::Lexer(m_script_source));
auto program = parser.parse_program();
if (parser.has_errors()) {
parser.print_errors();
return;
}
document().interpreter().run(*program);
}
void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
{
if (m_already_started)
@ -216,13 +227,15 @@ void HTMLScriptElement::prepare_script(Badge<HTMLDocumentParser>)
}
else {
ASSERT_NOT_REACHED();
// Immediately execute the script block, even if other scripts are already executing.
execute_script();
}
}
void HTMLScriptElement::script_became_ready()
{
ASSERT(m_script_ready_callback);
if (!m_script_ready_callback)
return;
m_script_ready_callback();
m_script_ready_callback = nullptr;
}

View File

@ -48,6 +48,7 @@ public:
private:
void script_became_ready();
void when_the_script_is_ready(Function<void()>);
void execute_script();
WeakPtr<Document> m_parser_document;
WeakPtr<Document> m_preparation_time_document;