Skip to content

Truly independent web browser

LibWeb: Skip substitution for `if()` conditions without ASFs

Callum Law01f322de2dbe
diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
index 503eea2c66a..c1a54ec585a 100644
--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs
+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
@@ -23,6 +23,7 @@ use crate::css::ffi_support::{FfiUtf16View, OwnedArc};
use crate::css::function_signature::FunctionSignature;
use crate::css::parser::arbitrary_substitution::{
arbitrary_substitution_function, arguments_are_valid, collect_arbitrary_substitution_function_presence,
+ contains_arbitrary_substitution_function,
};
use crate::css::parser::component_value::{
ComponentKind, ComponentSerializationMode, ComponentValue, ComponentValueList, ComponentValueSlice,
@@ -2876,10 +2877,14 @@ fn replace_if_function(
let Some(colon) = branch.iter().position(ComponentValue::is_colon) else {
return TokenResolution::Invalid;
};
- let condition = match substitute_tokens(store, registry, &branch[..colon], context, recursion_depth + 1) {
- TokenResolution::Resolved(tokens) => Cow::Owned(tokens.into_vec()),
- TokenResolution::Invalid | TokenResolution::Cyclic => Cow::Borrowed(&branch[..colon]),
- TokenResolution::NotHandled => return TokenResolution::NotHandled,
+ let condition = if contains_arbitrary_substitution_function(&branch[..colon]) {
+ match substitute_tokens(store, registry, &branch[..colon], context, recursion_depth + 1) {
+ TokenResolution::Resolved(tokens) => Cow::Owned(tokens.into_vec()),
+ TokenResolution::Invalid | TokenResolution::Cyclic => Cow::Borrowed(&branch[..colon]),
+ TokenResolution::NotHandled => return TokenResolution::NotHandled,
+ }
+ } else {
+ Cow::Borrowed(&branch[..colon])
};
match evaluate_if_condition(store, registry, &condition, context, recursion_depth + 1) {
ConditionEvaluation::Match(true) => {