mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 05:55:13 +00:00
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:
parent
ecd25ce6c7
commit
7bb69bb9bf
Notes:
sideshowbarker
2024-07-19 06:06:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7bb69bb9bf9
2 changed files with 16 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue