Skip to content

Truly independent web browser

LibWeb: Hide function locals when resolving element custom properties

Callum Lawa0b9b5c5659d
diff --git a/Libraries/LibWeb/Rust/src/css/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
index 1104b88336d..2df25d97c64 100644
--- a/Libraries/LibWeb/Rust/src/css/custom_properties.rs
+++ b/Libraries/LibWeb/Rust/src/css/custom_properties.rs
@@ -1477,6 +1477,13 @@ fn resolve_custom_property_with_lookup(
return result;
}
+
+ // Pop the function local scopes while we resolve the element level custom property.
+ let mut local_scopes = std::mem::take(&mut context.function_local_scopes);
+ let context_ref = RefCell::new(context);
+ let _guard = ScopeGuard::new(|| context_ref.borrow_mut().function_local_scopes = std::mem::take(&mut local_scopes));
+ let context = &mut **context_ref.borrow_mut();
+
let substitution_context = SubstitutionContextDependency::Property(name.to_owned(), None);
// AD-HOC: The root custom property's unresolved value is passed directly to `resolve_vars()` rather than read
// through this lookup. If it contains a `var()` that refers back to itself, this function is entered while
diff --git a/Tests/LibWeb/Text/expected/css/custom-function-property-owner.txt b/Tests/LibWeb/Text/expected/css/custom-function-property-owner.txt
new file mode 100644
index 00000000000..7ef22e9a431
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/custom-function-property-owner.txt
@@ -0,0 +1 @@
+PASS
diff --git a/Tests/LibWeb/Text/input/css/custom-function-property-owner.html b/Tests/LibWeb/Text/input/css/custom-function-property-owner.html
new file mode 100644
index 00000000000..ccaa3aa78f8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/custom-function-property-owner.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<style>
+ @function --read-source() {
+ --input: FAIL;
+ result: var(--source);
+ }
+ #target {
+ --input: PASS;
+ --source: var(--input);
+ --actual: --read-source();
+ }
+</style>
+<div id="target"></div>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ println(getComputedStyle(document.getElementById("target")).getPropertyValue("--actual").trim());
+ });
+</script>