From c09b792b9bf7964abfe2141b61d78eca663b25d8 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 29 Nov 2024 14:36:17 +0000 Subject: [PATCH] LibWeb: Allow calling property_initial_value() without a Realm In this situation we're only able to get initial values that have already been parsed. It's a little sketchy but doesn't seem to break anything. --- .../CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index b909d12bf6c1..57e6f2fe8d75 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -219,7 +219,7 @@ Optional property_id_from_string(StringView); [[nodiscard]] FlyString const& string_from_property_id(PropertyID); [[nodiscard]] FlyString const& camel_case_string_from_property_id(PropertyID); bool is_inherited_property(PropertyID); -NonnullRefPtr property_initial_value(JS::Realm&, PropertyID); +NonnullRefPtr property_initial_value(Optional, PropertyID); enum class ValueType { Angle, @@ -661,17 +661,20 @@ bool property_affects_stacking_context(PropertyID property_id) } } -NonnullRefPtr property_initial_value(JS::Realm& context_realm, PropertyID property_id) +NonnullRefPtr property_initial_value(Optional context_realm, PropertyID property_id) { static Array, to_underlying(last_property_id) + 1> initial_values; if (auto initial_value = initial_values[to_underlying(property_id)]) return initial_value.release_nonnull(); + // We need a Realm to parse any new values. + VERIFY(context_realm.has_value()); + // Lazily parse initial values as needed. // This ensures the shorthands will always be able to get the initial values of their longhands. // This also now allows a longhand have its own longhand (like background-position-x). - Parser::ParsingContext parsing_context(context_realm); + Parser::ParsingContext parsing_context(context_realm.value()); switch (property_id) { )~~~");