mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-02 04:27:12 +02:00
LibWeb: Replace spin_until in execute_script with deferred parser start
HTMLScriptElement::execute_script() and SVGScriptElement had spin_until calls waiting for ready_to_run_scripts to become true. The race exists because load_html_document() resolves the session history signal and starts the parser in the same deferred_invoke — so the parser can hit a <script> before update_for_history_step_application() sets the flag. Instead of spinning, defer parser->run() until the document is ready. Document gains a m_deferred_parser_start callback that is invoked when set_ready_to_run_scripts() is called. The callback is cleared before invocation to avoid reentrancy issues (parser->run() can synchronously execute scripts). All three document loading paths (HTML, XML, text) now check ready_to_run_scripts before starting the parser and defer if needed. create_document_for_inline_content() (used for error pages) now calls set_ready_to_run_scripts() before mutating the document, ensuring the invariant holds for all parser paths. The spin_until calls are replaced with VERIFY assertions.
This commit is contained in:
committed by
Alexander Kalenik
parent
df96b69e7a
commit
76d9cc4baf
Notes:
github-actions[bot]
2026-03-29 00:06:28 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/76d9cc4baf4 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8661
@@ -174,8 +174,7 @@ void SVGScriptElement::process_the_script_element()
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-html
|
||||
// Before any script execution occurs, the user agent must wait for scripts may run for the newly-created document to be true for document.
|
||||
if (!m_document->ready_to_run_scripts())
|
||||
HTML::main_thread_event_loop().spin_until(GC::create_function(heap(), [&] { return m_document->ready_to_run_scripts(); }));
|
||||
VERIFY(m_document->ready_to_run_scripts());
|
||||
|
||||
m_script = HTML::ClassicScript::create(script_url.basename(), script_content, realm(), m_document->base_url(), m_source_line_number);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user