mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibWeb: Reject invalid keyframe offset values
This commit is contained in:
parent
e13cd914a9
commit
73aadddbc1
Notes:
sideshowbarker
2024-07-17 14:36:19 +09:00
Author: https://github.com/mattco98
Commit: 73aadddbc1
Pull-request: https://github.com/SerenityOS/serenity/pull/24514
3 changed files with 14 additions and 4 deletions
|
@ -5,6 +5,9 @@ KeyframeEffect with infinite endDelay value: threw an exception
|
||||||
KeyframeEffect with NaN endDelay value: threw an exception
|
KeyframeEffect with NaN endDelay value: threw an exception
|
||||||
KeyframeEffect with NaN iterations: threw an exception
|
KeyframeEffect with NaN iterations: threw an exception
|
||||||
KeyframeEffect with non-"auto" string duration: 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 infinite options value: did not throw an exception
|
||||||
KeyframeEffect with finite 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
|
KeyframeEffect with infinite iterations: did not throw an exception
|
||||||
|
|
|
@ -19,6 +19,10 @@
|
||||||
checkException('KeyframeEffect with NaN endDelay value', () => new KeyframeEffect(null, null, { endDelay: NaN }));
|
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 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-"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
|
// Test valid values
|
||||||
checkException('KeyframeEffect with infinite options value', () => new KeyframeEffect(null, null, Infinity));
|
checkException('KeyframeEffect with infinite options value', () => new KeyframeEffect(null, null, Infinity));
|
||||||
|
|
|
@ -57,10 +57,13 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
|
||||||
{
|
{
|
||||||
auto& vm = realm.vm();
|
auto& vm = realm.vm();
|
||||||
|
|
||||||
Function<WebIDL::ExceptionOr<Optional<double>>(JS::Value)> to_nullable_double = [&vm](JS::Value value) -> WebIDL::ExceptionOr<Optional<double>> {
|
Function<WebIDL::ExceptionOr<Optional<double>>(JS::Value)> to_offset = [&vm](JS::Value value) -> WebIDL::ExceptionOr<Optional<double>> {
|
||||||
if (value.is_undefined())
|
if (value.is_undefined())
|
||||||
return Optional<double> {};
|
return Optional<double> {};
|
||||||
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<WebIDL::ExceptionOr<String>(JS::Value)> to_string = [&vm](JS::Value value) -> WebIDL::ExceptionOr<String> {
|
Function<WebIDL::ExceptionOr<String>(JS::Value)> to_string = [&vm](JS::Value value) -> WebIDL::ExceptionOr<String> {
|
||||||
|
@ -102,7 +105,7 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
|
||||||
composite = JS::PrimitiveString::create(vm, "auto"_string);
|
composite = JS::PrimitiveString::create(vm, "auto"_string);
|
||||||
|
|
||||||
if constexpr (AL == AllowLists::Yes) {
|
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));
|
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));
|
auto easing_maybe_list = TRY(convert_value_to_maybe_list(realm, easing, to_string));
|
||||||
|
@ -117,7 +120,7 @@ static WebIDL::ExceptionOr<KeyframeType<AL>> process_a_keyframe_like_object(JS::
|
||||||
keyframe_output.easing = move(easing_values);
|
keyframe_output.easing = move(easing_values);
|
||||||
});
|
});
|
||||||
} else {
|
} 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.easing = TRY(to_string(easing));
|
||||||
keyframe_output.composite = TRY(to_composite_operation(composite));
|
keyframe_output.composite = TRY(to_composite_operation(composite));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue