LibWeb: Stop passing Realm unnecessarily to parse CSS properties

Also use the parse_css_value() helper in cases where we previously
constructed a Parser manually.
This commit is contained in:
Sam Atkins 2024-12-05 11:52:43 +00:00 committed by Alexander Kalenik
commit bc77f84359
Notes: github-actions[bot] 2024-12-05 19:00:42 +00:00
11 changed files with 20 additions and 46 deletions

View file

@ -155,7 +155,7 @@ WebIDL::ExceptionOr<void> AnimationEffect::update_timing(OptionalEffectTiming ti
// [CSS-EASING-1], throw a TypeError and abort this procedure.
RefPtr<CSS::CSSStyleValue const> easing_value;
if (timing.easing.has_value()) {
easing_value = parse_easing_string(realm(), timing.easing.value());
easing_value = parse_easing_string(timing.easing.value());
if (!easing_value)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid easing function"sv };
VERIFY(easing_value->is_easing());
@ -589,11 +589,9 @@ Optional<double> AnimationEffect::transformed_progress() const
return m_timing_function.evaluate_at(directed_progress.value(), before_flag);
}
RefPtr<CSS::CSSStyleValue const> AnimationEffect::parse_easing_string(JS::Realm& realm, StringView value)
RefPtr<CSS::CSSStyleValue const> AnimationEffect::parse_easing_string(StringView value)
{
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), value);
if (auto style_value = parser.parse_as_css_value(CSS::PropertyID::AnimationTimingFunction)) {
if (auto style_value = parse_css_value(CSS::Parser::ParsingContext(), value, CSS::PropertyID::AnimationTimingFunction)) {
if (style_value->is_easing())
return style_value;
}

View file

@ -65,7 +65,7 @@ class AnimationEffect : public Bindings::PlatformObject {
GC_DECLARE_ALLOCATOR(AnimationEffect);
public:
static RefPtr<CSS::CSSStyleValue const> parse_easing_string(JS::Realm& realm, StringView value);
static RefPtr<CSS::CSSStyleValue const> parse_easing_string(StringView value);
EffectTiming get_timing() const;
ComputedEffectTiming get_computed_timing() const;

View file

@ -542,9 +542,7 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
if (!property_id.has_value())
continue;
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), value_string);
if (auto style_value = parser.parse_as_css_value(*property_id)) {
if (auto style_value = parse_css_value(CSS::Parser::ParsingContext(), value_string, *property_id)) {
// Handle 'initial' here so we don't have to get the default value of the property every frame in StyleComputer
if (style_value->is_initial())
style_value = CSS::property_initial_value(*property_id);
@ -558,7 +556,7 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
//
// If parsing the "easing" property fails, throw a TypeError and abort this procedure.
auto easing_string = keyframe.easing.get<String>();
auto easing_value = AnimationEffect::parse_easing_string(realm, easing_string);
auto easing_value = AnimationEffect::parse_easing_string(easing_string);
if (!easing_value)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) };
@ -570,7 +568,7 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
// interface, and if any of the values fail to parse, throw a TypeError and abort this procedure.
for (auto& unused_easing : unused_easings) {
auto easing_string = unused_easing.get<String>();
auto easing_value = AnimationEffect::parse_easing_string(realm, easing_string);
auto easing_value = AnimationEffect::parse_easing_string(easing_string);
if (!easing_value)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid animation easing value: \"{}\"", easing_string)) };
}