Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: f54bd14d678756e6db8225d3be608a577b9878e3
https://github.com/WebKit/WebKit/commit/f54bd14d678756e6db8225d3be608a577b9878e3
Author: Ahmad Saleem <[email protected]>
Date: 2026-03-10 (Tue, 10 Mar 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/html/the-xhtml-syntax/parsing-xhtml-documents/xml-stylesheet-blocking-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/svg/styling/style-sheet-interfaces-expected.txt
M Source/WebCore/xml/parser/XMLDocumentParser.cpp
M Source/WebCore/xml/parser/XMLDocumentParser.h
M Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
Log Message:
-----------
XMLDocumentParser should defer inline script execution until pending
stylesheets have loaded
https://bugs.webkit.org/show_bug.cgi?id=268620
rdar://122574381
Reviewed by Ryosuke Niwa.
This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.
The HTMLDocumentParser already defers inline script execution when
stylesheets are still loading (e.g. @import subsheets) via
HTMLScriptRunner::isPendingScriptReady(). The XMLDocumentParser, used
for SVG and XHTML documents, lacked this deferral — it executed inline
<script> elements immediately in endElementNs() regardless of pending
stylesheet loads. This caused scripts to run before @import rules had
been fetched, so CSSOM queries against those sheets would fail.
Adopt the same pattern used by HTMLDocumentParser: when
endElementNs() encounters a ready-to-execute inline script and
Document::haveStylesheetsLoaded() returns false, stash the script in
m_scriptWaitingForStylesheets and pause parsing. The existing
notification chain in ScriptableDocumentParser —
didRemoveAllPendingStylesheet() → executeScriptsWaitingForStylesheetsSoon()
→ executeScriptsWaitingForStylesheets() then fires the deferred script and
resumes parsing once all sheets are loaded.
* Source/WebCore/xml/parser/XMLDocumentParser.cpp:
(WebCore::XMLDocumentParser::detach):
(WebCore::XMLDocumentParser::hasScriptsWaitingForStylesheets const):
(WebCore::XMLDocumentParser::executeScriptsWaitingForStylesheets):
* Source/WebCore/xml/parser/XMLDocumentParser.h:
* Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp:
(WebCore::XMLDocumentParser::~XMLDocumentParser):
(WebCore::XMLDocumentParser::endElementNs):
*
LayoutTests/imported/w3c/web-platform-tests/svg/styling/style-sheet-interfaces-expected.txt:
Progression
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/106-import-xhtml-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/106-noimport-xhtml-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/150-import-xhtml-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/execution-timing/150-noimport-xhtml-expected.txt:
Ditto
*
LayoutTests/imported/w3c/web-platform-tests/html/the-xhtml-syntax/parsing-xhtml-documents/xml-stylesheet-blocking-expected.txt:
Ditto
Canonical link: https://commits.webkit.org/308980@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications