script: Implement DocumentOrShadowDOM.adoptedStylesheet with FrozenArray (#38163)

Spec:
https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets

Implement `DocumentOrShadowDOM.adoptedStylesheet`. Due to
`ObservableArray` being a massive issue on its own, it will be as it was
a `FrozenArray` at first. This approach is similar to how Gecko
implement adopted stylesheet. See
https://phabricator.services.mozilla.com/D144547#change-IXyOzxxFn8sU.

All of the changes will be gated behind a preference
`dom_adoptedstylesheet_enabled`.

Adopted stylesheet is implemented by adding the setter and getter of it.
While the getter works like a normal attribute getter, the setter need
to consider the inner working of document and shadow root StylesheetSet,
specifically the ordering and the invalidations. Particularly for
setter, we will clear all of the adopted stylesheet within the
StylesheetSet and readd them. Possible optimization exist, but the focus
should be directed to implementing `ObservableArray`.

More context about the implementations
https://hackmd.io/vtJAn4UyS_O0Idvk5dCO_w.

Testing: Existing WPT Coverage
Fixes: https://github.com/servo/servo/issues/37561

---------

Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
This commit is contained in:
Jo Steven Novaryo 2025-07-23 16:16:01 +08:00 committed by GitHub
parent d2e5137201
commit f523445fc3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 434 additions and 139 deletions

View file

@ -1,4 +1,5 @@
prefs: [
"dom_adoptedstylesheet_enabled:true",
"dom_indexeddb_enabled:true",
"dom_serviceworker_enabled:true",
"dom_testutils_enabled:true",

View file

@ -1,3 +0,0 @@
[layer-replaceSync-clears-stale.html]
[replaceSync clears stale layer statements]
expected: FAIL

View file

@ -1,4 +0,0 @@
[CSSStyleSheet-constructable-concat.html]
expected: TIMEOUT
[adoptedStyleSheets should allow .concat on empty starting values]
expected: FAIL

View file

@ -1,9 +0,0 @@
[CSSStyleSheet-constructable-invalidation.html]
[mutating constructed CSSStyleSheet applied to root invalidates styles]
expected: FAIL
[mutating constructed CSSStyleSheet applied to shadowdom invalidates styles]
expected: FAIL
[mutating dependent constructed CSSStyleSheet applied to shadowdom invalidates styles]
expected: FAIL

View file

@ -1,7 +1,4 @@
[CSSStyleSheet-constructable.html]
[document.adoptedStyleSheets should initially have length 0.]
expected: FAIL
[new CSSStyleSheet produces empty CSSStyleSheet]
expected: FAIL
@ -17,12 +14,6 @@
[Re-attaching shadow host with adopted stylesheets work]
expected: FAIL
[Attaching a shadow root that already has adopted stylesheets work]
expected: FAIL
[Re-attaching shadow host and updating attributes work]
expected: FAIL
[Changes to constructed stylesheets through CSSOM is reflected]
expected: FAIL
@ -35,12 +26,6 @@
[Stylesheet constructed on iframe cannot be used in the main Document]
expected: FAIL
[Adding non-constructed stylesheet to AdoptedStyleSheets is not allowed when the owner document of the stylesheet is in the same document tree as the AdoptedStyleSheets]
expected: FAIL
[Adding non-constructed stylesheet to AdoptedStyleSheets is not allowed when the owner document of the stylesheet and the AdoptedStyleSheets are in different document trees]
expected: FAIL
[CSSStyleSheet.replaceSync correctly updates the style of its adopters synchronously]
expected: FAIL

View file

@ -1,9 +0,0 @@
[adoptedstylesheets-modify-array-and-sheet.html]
[Add the two sheets. Text should be red.]
expected: FAIL
[Flip the two sheet. Still red.]
expected: FAIL
[Modify the color declaration. Should now be green.]
expected: FAIL

View file

@ -4,6 +4,3 @@
[shadowRoot.adoptedStyleSheets should allow mutation in-place]
expected: FAIL
[adoptedStyleSheets should return true for isArray()]
expected: FAIL

View file

@ -395,18 +395,6 @@
[CSSStyleSheet interface: calling replace(USVString) on sheet with too few arguments must throw TypeError]
expected: FAIL
[Document interface: attribute adoptedStyleSheets]
expected: FAIL
[Document interface: document must inherit property "adoptedStyleSheets" with the proper type]
expected: FAIL
[Document interface: new Document() must inherit property "adoptedStyleSheets" with the proper type]
expected: FAIL
[ShadowRoot interface: attribute adoptedStyleSheets]
expected: FAIL
[CSSImportRule interface: attribute supportsText]
expected: FAIL

View file

@ -1,3 +0,0 @@
[observable-array-no-leak-of-internals.window.html]
[ObservableArray's internals won't leak]
expected: FAIL