mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 09:39:39 +00:00
LibWeb: Don't crash when querying detached circle element properties
This commit is contained in:
parent
cab0cb5b13
commit
3518f39b60
Notes:
sideshowbarker
2024-07-17 05:06:13 +09:00
Author: https://github.com/tcl3
Commit: 3518f39b60
Pull-request: https://github.com/SerenityOS/serenity/pull/23687
Reviewed-by: https://github.com/awesomekling
3 changed files with 23 additions and 6 deletions
1
Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt
Normal file
1
Tests/LibWeb/Text/expected/SVG/svg-circle-detached.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't crash)
|
10
Tests/LibWeb/Text/input/SVG/svg-circle-detached.html
Normal file
10
Tests/LibWeb/Text/input/SVG/svg-circle-detached.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const circleElement = document.createElementNS("http://www.w3.org/2000/svg", "circle");
|
||||||
|
const cx = circleElement.cx;
|
||||||
|
const cy = circleElement.cy;
|
||||||
|
const r = circleElement.r;
|
||||||
|
println("PASS (didn't crash)");
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -85,8 +85,10 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::cx() const
|
||||||
{
|
{
|
||||||
// FIXME: Create a proper animated value when animations are supported.
|
// FIXME: Create a proper animated value when animations are supported.
|
||||||
auto make_length = [&] {
|
auto make_length = [&] {
|
||||||
if (auto cx = computed_css_values()->length_percentage(CSS::PropertyID::Cx); cx.has_value())
|
if (auto const* style = computed_css_values(); style) {
|
||||||
return SVGLength::from_length_percentage(realm(), *cx);
|
if (auto cx = style->length_percentage(CSS::PropertyID::Cx); cx.has_value())
|
||||||
|
return SVGLength::from_length_percentage(realm(), *cx);
|
||||||
|
}
|
||||||
return SVGLength::create(realm(), 0, 0.0f);
|
return SVGLength::create(realm(), 0, 0.0f);
|
||||||
};
|
};
|
||||||
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
||||||
|
@ -97,8 +99,10 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::cy() const
|
||||||
{
|
{
|
||||||
// FIXME: Create a proper animated value when animations are supported.
|
// FIXME: Create a proper animated value when animations are supported.
|
||||||
auto make_length = [&] {
|
auto make_length = [&] {
|
||||||
if (auto cy = computed_css_values()->length_percentage(CSS::PropertyID::Cy); cy.has_value())
|
if (auto const* style = computed_css_values(); style) {
|
||||||
return SVGLength::from_length_percentage(realm(), *cy);
|
if (auto cy = style->length_percentage(CSS::PropertyID::Cy); cy.has_value())
|
||||||
|
return SVGLength::from_length_percentage(realm(), *cy);
|
||||||
|
}
|
||||||
return SVGLength::create(realm(), 0, 0.0f);
|
return SVGLength::create(realm(), 0, 0.0f);
|
||||||
};
|
};
|
||||||
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
||||||
|
@ -109,8 +113,10 @@ JS::NonnullGCPtr<SVGAnimatedLength> SVGCircleElement::r() const
|
||||||
{
|
{
|
||||||
// FIXME: Create a proper animated value when animations are supported.
|
// FIXME: Create a proper animated value when animations are supported.
|
||||||
auto make_length = [&] {
|
auto make_length = [&] {
|
||||||
if (auto r = computed_css_values()->length_percentage(CSS::PropertyID::R); r.has_value())
|
if (auto const* style = computed_css_values(); style) {
|
||||||
return SVGLength::from_length_percentage(realm(), *r);
|
if (auto r = computed_css_values()->length_percentage(CSS::PropertyID::R); r.has_value())
|
||||||
|
return SVGLength::from_length_percentage(realm(), *r);
|
||||||
|
}
|
||||||
return SVGLength::create(realm(), 0, 0.0f);
|
return SVGLength::create(realm(), 0, 0.0f);
|
||||||
};
|
};
|
||||||
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
return SVGAnimatedLength::create(realm(), make_length(), make_length());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue