Skip to content

Invert random() caching behavior to match spec#61964

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
fantasai:random-update
Apr 3, 2026
Merged

Invert random() caching behavior to match spec#61964
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
fantasai:random-update

Conversation

@fantasai
Copy link
Copy Markdown
Contributor

@fantasai fantasai commented Apr 3, 2026

e3d530f

Invert random() caching behavior to match spec
https://bugs.webkit.org/show_bug.cgi?id=311355
rdar://173943833

Reviewed by Sam Weinig.

The CSS spec for random() changed so that the `--foo` in `random(--foo)`
is matched globally to the document rather than scoped to the element.
This is the opposite of the behavior implemented in WebKit, so invert
the behavior and update the keyword to match.

* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-computed.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-computed.tentative.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-serialize.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-serialize.tentative.html:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/calc/CSSCalcTree+Evaluation.cpp:
(WebCore::CSSCalc::evaluate):
* Source/WebCore/css/calc/CSSCalcTree+Parser.cpp:
(WebCore::CSSCalc::consumeOptionalRandomSharingOptions):
(WebCore::CSSCalc::consumeOptionalRandomSharing):
(WebCore::CSSCalc::consumeRandom):
* Source/WebCore/css/calc/CSSCalcTree+Serialization.cpp:
(WebCore::CSSCalc::serializeMathFunctionArguments):
* Source/WebCore/css/calc/CSSCalcTree+Simplification.cpp:
(WebCore::CSSCalc::simplify):
* Source/WebCore/css/calc/CSSCalcTree.h:
* Source/WebCore/style/StyleBuilderState.cpp:
(WebCore::Style::BuilderState::lookupCSSRandomBaseValue const):
* Source/WebCore/style/StyleBuilderState.h:
* Source/WebCore/style/calc/StyleCalculationTree+Conversion.cpp:
(WebCore::Style::Calculation::toStyle):

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

8b17a7c

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-debug ✅ 🛠 gtk3-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2
✅ 🛠 tv ✅ 🛠 mac-safer-cpp
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

@fantasai fantasai self-assigned this Apr 3, 2026
@fantasai fantasai added the CSS Cascading Style Sheets implementation label Apr 3, 2026
@fantasai fantasai requested review from anttijk and nt1m April 3, 2026 07:21
return { };

guard.commit();

return Random::SharingOptions {
.identifier = identifier.value_or(makeRandomSharingAuto(state)),
.elementShared = elementShared
.identifier = identifier.value_or(AtomString { }),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullString() might be more explicit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like an improvement. I will fix it in a follow-up along with some other cleanup that I think should happen here.

@fantasai fantasai added the merge-queue Applied to send a pull request to merge-queue label Apr 3, 2026
https://bugs.webkit.org/show_bug.cgi?id=311355
rdar://173943833

Reviewed by Sam Weinig.

The CSS spec for random() changed so that the `--foo` in `random(--foo)`
is matched globally to the document rather than scoped to the element.
This is the opposite of the behavior implemented in WebKit, so invert
the behavior and update the keyword to match.

* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-computed.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-computed.tentative.html:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-serialize.tentative-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/css-values/random-serialize.tentative.html:
* Source/WebCore/css/CSSValueKeywords.in:
* Source/WebCore/css/calc/CSSCalcTree+Evaluation.cpp:
(WebCore::CSSCalc::evaluate):
* Source/WebCore/css/calc/CSSCalcTree+Parser.cpp:
(WebCore::CSSCalc::consumeOptionalRandomSharingOptions):
(WebCore::CSSCalc::consumeOptionalRandomSharing):
(WebCore::CSSCalc::consumeRandom):
* Source/WebCore/css/calc/CSSCalcTree+Serialization.cpp:
(WebCore::CSSCalc::serializeMathFunctionArguments):
* Source/WebCore/css/calc/CSSCalcTree+Simplification.cpp:
(WebCore::CSSCalc::simplify):
* Source/WebCore/css/calc/CSSCalcTree.h:
* Source/WebCore/style/StyleBuilderState.cpp:
(WebCore::Style::BuilderState::lookupCSSRandomBaseValue const):
* Source/WebCore/style/StyleBuilderState.h:
* Source/WebCore/style/calc/StyleCalculationTree+Conversion.cpp:
(WebCore::Style::Calculation::toStyle):

Canonical link: https://commits.webkit.org/310532@main
@webkit-commit-queue
Copy link
Copy Markdown
Collaborator

Committed 310532@main (e3d530f): https://commits.webkit.org/310532@main

Reviewed commits have been landed. Closing PR #61964 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit e3d530f into WebKit:main Apr 3, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CSS Cascading Style Sheets implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants