Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b1913f6615d4becc73eba817d37004685721aa59
      
https://github.com/WebKit/WebKit/commit/b1913f6615d4becc73eba817d37004685721aa59
  Author: Kiet Ho <[email protected]>
  Date:   2026-10-06 (Tue, 06 Oct 2026)

  Changed paths:
    M LayoutTests/TestExpectations
    M 
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-allowed.sub-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-blocked.sub-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/destination/fetch-destination.https-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-style-element/tentative/style-element-basic-import-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-style-element/tentative/style-element-fixed-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-2-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom.html
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking.html
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-parse-error-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/redirect-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/referrer-policies.sub-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/relative-urls-expected.txt
    M 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/repeated-import-expected.txt
    A 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/should-not-be-loaded.js
    M 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/tentative/shadowrootadoptedstylesheets/shadowrootadoptedstylesheets-fetched-module-expected.txt
    A 
LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub-expected.txt
    M Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp
    M Source/JavaScriptCore/jsc.cpp
    M Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp
    M Source/JavaScriptCore/parser/SourceProvider.h
    M Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp
    M Source/JavaScriptCore/runtime/Completion.cpp
    M Source/JavaScriptCore/runtime/JSMicrotask.cpp
    M Source/JavaScriptCore/runtime/JSModuleLoader.cpp
    M Source/JavaScriptCore/runtime/JSModuleLoader.h
    M Source/JavaScriptCore/runtime/ModuleRegistryEntry.cpp
    M Source/JavaScriptCore/runtime/ModuleRegistryEntry.h
    M Source/JavaScriptCore/runtime/ScriptFetchParameters.h
    M Source/JavaScriptCore/runtime/SyntheticModuleRecord.h
    M Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml
    M Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp
    M Source/WebCore/bindings/js/CachedModuleScriptLoader.h
    M Source/WebCore/bindings/js/CachedScriptFetcher.cpp
    M Source/WebCore/bindings/js/JSDOMGlobalObject.cpp
    M Source/WebCore/bindings/js/JSDOMGlobalObject.h
    M Source/WebCore/bindings/js/JSDOMWindowBase.cpp
    M Source/WebCore/bindings/js/ScriptModuleLoader.cpp
    M Source/WebCore/bindings/js/ScriptModuleLoader.h
    M Source/WebCore/bindings/js/WorkerModuleScriptLoader.cpp
    M Source/WebCore/css/CSSStyleSheet.cpp
    M Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
    M Source/WebCore/loader/cache/CachedCSSStyleSheet.h
    M Tools/Scripts/webkitpy/style/checkers/cpp.py

  Log Message:
  -----------
  Implement CSS module scripts
rdar://80917329
https://bugs.webkit.org/show_bug.cgi?id=227967

Reviewed by Ryosuke Niwa and Yusuke Suzuki.

This patch implements importing CSS stylesheets as JavaScript modules, using the
`import ... with { type: 'css' }` and `import(..., { with: { type: 'css' } })`
syntax.

On the JSC side, we add support for the `css` module type, and requests the host
to fetch it. If the host supports CSS modules (like WebCore), it fetches the
stylesheet, constructs a CSSStyleSheet object out of it, wraps it in a
JSCSSStyleSheet, and returns it back to JSC as a JSValue. JSC uses this as the
default export value of the CSS module. If the host doesn't support CSS modules
(like `jsc` command line or workers/worklets), then the import simply fails.

To implement this requires some changes in how script modules loading works. For
JavaScript/WASM/JSON/text, JSC asks the host (e.g WebCore) to fetch the source 
code.
The host fetches the source code and passes it back to JSC so it can turn it 
into
modules. CSS is a WebCore construct however, so only WebCore can parse and 
create
stylesheets out of it, not JSC. So to support CSS, the host now returns either 
source
code or a JSValue. When it's a source code, JSC will parse and create modules 
like
before. When it's a JSValue, JSC assumes the host has already created a module, 
and
it uses that value as the default module export.

This is gated by the CSSModuleScriptsEnabled feature flag, which is disabled by 
default.

There is one failing test only on GTK, which is tracked at webkit.org/b/326330:
- 
imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub.html

Tests: 
imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-allowed.sub.html
       
imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-blocked.sub.html
       
imported/w3c/web-platform-tests/fetch/api/request/destination/fetch-destination.https.html
       
imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/

* LayoutTests/TestExpectations:
* 
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-allowed.sub-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/content-security-policy/style-src/import-style-blocked.sub-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/destination/fetch-destination.https-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-style-element/tentative/style-element-basic-import-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/document-metadata/the-style-element/tentative/style-element-fixed-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-2-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-bom.html:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/charset-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/content-type-checking.html:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/cors-crossorigin-requests-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-parse-error-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-basic-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/import-css-module-dynamic-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/integrity-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/load-error-events-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/redirect-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/referrer-policies.sub-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/relative-urls-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/repeated-import-expected.txt:
* 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/should-not-be-loaded.js:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/shadow-dom/declarative/tentative/shadowrootadoptedstylesheets/shadowrootadoptedstylesheets-fetched-module-expected.txt:
* 
LayoutTests/platform/glib/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub-expected.txt:
 Copied from 
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/credentials.sub-expected.txt.
* Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::scriptTypeForScript):
* Source/JavaScriptCore/jsc.cpp:
(GlobalObject::moduleLoaderFetch):
* Source/JavaScriptCore/parser/NodesAnalyzeModule.cpp:
(JSC::tryCreateAttributes):
* Source/JavaScriptCore/parser/SourceProvider.h:
(JSC::SourceProvider::isModuleType const):
* Source/JavaScriptCore/runtime/AbstractModuleRecord.cpp:
(JSC::AbstractModuleRecord::moduleType const):
* Source/JavaScriptCore/runtime/Completion.cpp:
(JSC::getSourceType):
(JSC::retrieveTypeImportAttribute):
* Source/JavaScriptCore/runtime/JSMicrotask.cpp:
(JSC::moduleRegistryFetchSettled):
(JSC::moduleLoadTopSettled):
* Source/JavaScriptCore/runtime/JSModuleLoader.cpp:
(JSC::JSModuleLoader::provideFetch):
(JSC::JSModuleLoader::hostLoadImportedModule):
(JSC::JSModuleLoader::makeModule):
* Source/JavaScriptCore/runtime/JSModuleLoader.h:
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.cpp:
(JSC::ModuleRegistryEntry::provideFetch):
* Source/JavaScriptCore/runtime/ModuleRegistryEntry.h:
* Source/JavaScriptCore/runtime/ScriptFetchParameters.h:
(JSC::ScriptFetchParameters::parseType):
* Source/JavaScriptCore/runtime/SyntheticModuleRecord.h:
* Source/WTF/Scripts/Preferences/UnifiedWebPreferences.yaml:
* Source/WebCore/bindings/js/CachedModuleScriptLoader.cpp:
(WebCore::CachedModuleScriptLoader::load):
(WebCore::CachedModuleScriptLoader::notifyFinished):
(WebCore::CachedModuleScriptLoader::setCSSStyleSheet):
(WebCore::CachedModuleScriptLoader::notifyFinishedInternal):
* Source/WebCore/bindings/js/CachedModuleScriptLoader.h:
* Source/WebCore/bindings/js/CachedScriptFetcher.cpp:
(WebCore::CachedScriptFetcher::requestResourceWithCache const):
* Source/WebCore/bindings/js/JSDOMGlobalObject.cpp:
(WebCore::JSDOMGlobalObject::moduleTypeIsAllowed):
* Source/WebCore/bindings/js/JSDOMGlobalObject.h:
* Source/WebCore/bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::globalObjectMethodTable):
* Source/WebCore/bindings/js/ScriptModuleLoader.cpp:
(WebCore::ScriptModuleLoader::importModule):
(WebCore::createCSSModuleScript):
(WebCore::ScriptModuleLoader::notifyFinished):
* Source/WebCore/bindings/js/ScriptModuleLoader.h:
* Source/WebCore/bindings/js/WorkerModuleScriptLoader.cpp:
(WebCore::WorkerModuleScriptLoader::load):
* Source/WebCore/css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::replaceSync):
* Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::sheetText const):
* Source/WebCore/loader/cache/CachedCSSStyleSheet.h:
* Tools/Scripts/webkitpy/style/checkers/cpp.py:

Canonical link: https://commits.webkit.org/322887@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to