diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index f8d554853f9..1328e569f01 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -3105,6 +3105,15 @@ void StyleComputer::unload_fonts_from_sheet(CSSStyleSheet& sheet) } } +static NonnullRefPtr custom_property_initial_value(FlyString const& name) +{ + // FIXME: Look-up initial value for registered properties. (@property) + (void)name; + + // For non-registered properties, the initial value is the guaranteed-invalid value. + return GuaranteedInvalidStyleValue::create(); +} + NonnullRefPtr StyleComputer::compute_value_of_custom_property(DOM::AbstractElement abstract_element, FlyString const& name, Optional guarded_contexts) { // https://drafts.csswg.org/css-variables/#propdef- @@ -3112,19 +3121,17 @@ NonnullRefPtr StyleComputer::compute_value_of_custom_proper // FIXME: These should probably be part of ComputedProperties. auto value = abstract_element.get_custom_property(name); - if (!value) - return GuaranteedInvalidStyleValue::create(); - - // Initial value is the guaranteed-invalid value. - if (value->is_initial()) - return GuaranteedInvalidStyleValue::create(); + if (!value || value->is_initial()) + return custom_property_initial_value(name); // Unset is the same as inherit for inherited properties, and by default all custom properties are inherited. - // FIXME: Update handling of css-wide keywords once we support @property properly. + // FIXME: Support non-inherited registered custom properties. if (value->is_inherit() || value->is_unset()) { + if (!abstract_element.parent_element()) + return custom_property_initial_value(name); auto inherited_value = DOM::AbstractElement { const_cast(*abstract_element.parent_element()) }.get_custom_property(name); if (!inherited_value) - return GuaranteedInvalidStyleValue::create(); + return custom_property_initial_value(name); return inherited_value.release_nonnull(); } diff --git a/Tests/LibWeb/Text/expected/css/custom-property-unset-on-root.txt b/Tests/LibWeb/Text/expected/css/custom-property-unset-on-root.txt new file mode 100644 index 00000000000..50586a4cbfb --- /dev/null +++ b/Tests/LibWeb/Text/expected/css/custom-property-unset-on-root.txt @@ -0,0 +1 @@ +PASS! (Didn't crash) diff --git a/Tests/LibWeb/Text/input/css/custom-property-unset-on-root.html b/Tests/LibWeb/Text/input/css/custom-property-unset-on-root.html new file mode 100644 index 00000000000..ecf5f070dab --- /dev/null +++ b/Tests/LibWeb/Text/input/css/custom-property-unset-on-root.html @@ -0,0 +1,12 @@ + + + +