Page MenuHomePhabricator

Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio
ClosedPublic

Authored by fredw on Oct 4 2023, 6:39 AM.
Referenced Files
Unknown Object (File)
Nov 13 2025, 12:12 PM
Unknown Object (File)
Nov 13 2025, 12:12 PM
Unknown Object (File)
Nov 8 2025, 8:35 AM
Unknown Object (File)
Nov 8 2025, 8:35 AM
Unknown Object (File)
Nov 7 2025, 1:49 AM
Unknown Object (File)
Nov 7 2025, 1:49 AM
Unknown Object (File)
Nov 4 2025, 9:01 AM
Unknown Object (File)
Nov 4 2025, 9:01 AM
Subscribers

Details

Summary

After bug 1840478, non-inherited custom properties using their initial
values are represented as absent from ComputedCustomProperties in
order to save memory. Wherever the values of such properties are
requested, it is necessary to fallback to any registered initial value.
However, this makes difficult to properly enumerate custom properties
for exposure via the CSSStyleDeclaration.item() API and indeed our
current implementation only exposes the properties actually present in
ComputedCustomProperties.

Additionally, such a representation conflicts with pre-existent
representation of guaranteed-invalid values as absent values, causing
some issues e.g. bad handling of invalid at computed-value time [1] [2].

This patch changes ComputedCustomProperties so that registered initial
values are always stored in the non_inherited map, immediately fixing
the issue with CSSStyleDeclaration.item() and preparing follow-up
work on guaranteed-invalid values.

To avoid excessive increase of memory usage, the non_inherited map
becomes ref-counted. The associated Stylist contains an up-to-date
ComputedCustomProperties with registered custom properties that have
initial values, and the non_inherited map can generally just be
shallow-cloned from it.

A new test get-computed-style-enumeration.html is added to make sure
custom properties are correctly exposed when enumerating
CSSStyleDeclaration as a list. A similar but more restricted version
already exists: cssstyledeclaration-registered-custom-properties.html.
Two test cases are also added to determine-registration.html in order
to cover some issue previously detected during the review of
get_custom_property_initial_values.

[1] https://drafts.csswg.org/css-variables-2/#invalid-at-computed-value-time
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1855946

Test Plan

Event Timeline

fredw planned changes to this revision.Oct 4 2023, 6:39 AM
fredw created this revision.
phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".Oct 4 2023, 6:39 AM
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
fredw requested review of this revision.Oct 4 2023, 8:56 AM
fredw updated this revision to Diff 771174.
fredw retitled this revision from WIP: Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio to Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio.
fredw added a reviewer: emilio.
fredw edited the summary of this revision. (Show Details)

@emilio: I'm not totally satisfied with how the initial values is handled, but sending for review to get some feedback... thanks!

emilio requested changes to this revision.Oct 4 2023, 11:14 AM

Seems sensible at a glance... We should avoid recomputing the initial values over and over tho. Maybe doing it once after stylist rebuild / and when the JS registry changes?

We might need a way to opt out of the registered property initial values for anonymous content, but that's a separate issue.

servo/components/style/custom_properties.rs
326–329

nit: This could be a bit simpler now they are the same type, right?

let mut map = if inherits {
    &mut self.inherited
} else {
    &mut self.non_inherited
};
Arc::make_mut(map.get_or_insert_with(Default::default))
804

Yeah this is not great. I'm ok with making non_inherited an Arc and so on, but we should definitely not go through all the @property rules and script registry once for every element, specially because the Arc as is doesn't accomplish much meaningful sharing...

This revision now requires changes to proceed.Oct 4 2023, 11:14 AM
fredw updated this revision to Diff 771274.
fredw retitled this revision from Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio to WIP: Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio.
fredw updated this revision to Diff 771277.
fredw planned changes to this revision.Oct 4 2023, 1:22 PM
fredw updated this revision to Diff 771304.
fredw requested review of this revision.Oct 5 2023, 7:18 AM
fredw updated this revision to Diff 771776.
fredw retitled this revision from WIP: Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio to Bug 1855629 - Handling of custom properties when enumerating getComputedStyle(). r=emilio.
fredw edited the summary of this revision. (Show Details)
fredw marked an inline comment as done.
fredw edited the summary of this revision. (Show Details)
emilio added a project: testing-approved.
emilio added inline comments.
testing/web-platform/meta/css/css-properties-values-api/registered-property-cssom.html.ini
15

Do you know what are these regressions about? Missing invalidation in RegisterProperty? Something else?

This revision is now accepted and ready to land.Oct 6 2023, 11:09 AM
fredw added inline comments.
testing/web-platform/meta/css/css-properties-values-api/registered-property-cssom.html.ini
15

I had checked and tests after CSS.registerProperty are still working as expected. The problem rather in the conflicts between guaranteed-invalid values VS initial values both represented by absent values. I suspect they were just passing by luck in the past but I will investigate further later after pending patches land.

fredw marked an inline comment as done.