Skip to content

Commit

Permalink
LibWeb: Allow calling property_initial_value() without a Realm
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AtkinsSJ committed Nov 29, 2024
1 parent 2a9eeda commit c09b792
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
)~~~");

Expand Down

0 comments on commit c09b792

Please sign in to comment.