Pārlūkot izejas kodu

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.
Sam Atkins 7 mēneši atpakaļ
vecāks
revīzija
c405c4bcf1

+ 6 - 3
Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp

@@ -219,7 +219,7 @@ Optional<PropertyID> 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<CSSStyleValue> property_initial_value(JS::Realm&, PropertyID);
+NonnullRefPtr<CSSStyleValue> property_initial_value(Optional<JS::Realm&>, PropertyID);
 
 enum class ValueType {
     Angle,
@@ -661,17 +661,20 @@ bool property_affects_stacking_context(PropertyID property_id)
     }
 }
 
-NonnullRefPtr<CSSStyleValue> property_initial_value(JS::Realm& context_realm, PropertyID property_id)
+NonnullRefPtr<CSSStyleValue> property_initial_value(Optional<JS::Realm&> context_realm, PropertyID property_id)
 {
     static Array<RefPtr<CSSStyleValue>, 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) {
 )~~~");