diff --git a/Tests/LibWeb/Text/expected/WebAnimations/misc/invalid-values.txt b/Tests/LibWeb/Text/expected/WebAnimations/misc/invalid-values.txt index 49cbed31b5a..27868db8f39 100644 --- a/Tests/LibWeb/Text/expected/WebAnimations/misc/invalid-values.txt +++ b/Tests/LibWeb/Text/expected/WebAnimations/misc/invalid-values.txt @@ -5,6 +5,9 @@ KeyframeEffect with infinite endDelay value: threw an exception KeyframeEffect with NaN endDelay value: threw an exception KeyframeEffect with NaN iterations: threw an exception KeyframeEffect with non-"auto" string duration: threw an exception +KeyframeEffect with non-numeric offset: threw an exception +KeyframeEffect with invalid numeric offset: threw an exception + KeyframeEffect with infinite options value: did not throw an exception KeyframeEffect with finite options value: did not throw an exception KeyframeEffect with infinite iterations: did not throw an exception diff --git a/Tests/LibWeb/Text/input/WebAnimations/misc/invalid-values.html b/Tests/LibWeb/Text/input/WebAnimations/misc/invalid-values.html index bcd274f1a3d..a8d909c75ad 100644 --- a/Tests/LibWeb/Text/input/WebAnimations/misc/invalid-values.html +++ b/Tests/LibWeb/Text/input/WebAnimations/misc/invalid-values.html @@ -19,6 +19,10 @@ checkException('KeyframeEffect with NaN endDelay value', () => new KeyframeEffect(null, null, { endDelay: NaN })); checkException('KeyframeEffect with NaN iterations', () => new KeyframeEffect(null, null, { iterations: NaN })); checkException('KeyframeEffect with non-"auto" string duration', () => new KeyframeEffect(null, null, { duration: 'abc' })) + checkException('KeyframeEffect with non-numeric offset', () => new KeyframeEffect(null, [{ offset: 'abc' }], {})); + checkException('KeyframeEffect with invalid numeric offset', () => new KeyframeEffect(null, [{ offset: -1 }], {})); + + println(''); // Test valid values checkException('KeyframeEffect with infinite options value', () => new KeyframeEffect(null, null, Infinity)); diff --git a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp index 579cc0e1db5..822a2778deb 100644 --- a/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Userland/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -57,10 +57,13 @@ static WebIDL::ExceptionOr> process_a_keyframe_like_object(JS:: { auto& vm = realm.vm(); - Function>(JS::Value)> to_nullable_double = [&vm](JS::Value value) -> WebIDL::ExceptionOr> { + Function>(JS::Value)> to_offset = [&vm](JS::Value value) -> WebIDL::ExceptionOr> { if (value.is_undefined()) return Optional {}; - return TRY(value.to_double(vm)); + auto double_value = TRY(value.to_double(vm)); + if (isnan(double_value) || isinf(double_value)) + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("Invalid offset value: {}", TRY(value.to_string(vm)))) }; + return double_value; }; Function(JS::Value)> to_string = [&vm](JS::Value value) -> WebIDL::ExceptionOr { @@ -102,7 +105,7 @@ static WebIDL::ExceptionOr> process_a_keyframe_like_object(JS:: composite = JS::PrimitiveString::create(vm, "auto"_string); if constexpr (AL == AllowLists::Yes) { - keyframe_output.offset = TRY(convert_value_to_maybe_list(realm, offset, to_nullable_double)); + keyframe_output.offset = TRY(convert_value_to_maybe_list(realm, offset, to_offset)); keyframe_output.composite = TRY(convert_value_to_maybe_list(realm, composite, to_composite_operation)); auto easing_maybe_list = TRY(convert_value_to_maybe_list(realm, easing, to_string)); @@ -117,7 +120,7 @@ static WebIDL::ExceptionOr> process_a_keyframe_like_object(JS:: keyframe_output.easing = move(easing_values); }); } else { - keyframe_output.offset = TRY(to_nullable_double(offset)); + keyframe_output.offset = TRY(to_offset(offset)); keyframe_output.easing = TRY(to_string(easing)); keyframe_output.composite = TRY(to_composite_operation(composite)); }