summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/Layout/LayoutCheckBox.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-09-11 18:37:18 +0200
committerAndreas Kling <kling@serenityos.org>2020-09-11 18:42:43 +0200
commitb62043dbca047cb83aa6acd3d9b6bd65c54ef15e (patch)
treec78822c27572e683ea90b10cab0441d87335ba56 /Libraries/LibWeb/Layout/LayoutCheckBox.cpp
parent71092226bd0f705e499146aa3ffde166762c2e87 (diff)
downloadserenity-b62043dbca047cb83aa6acd3d9b6bd65c54ef15e.zip
LibWeb: Protect LayoutCheckBox against crashes after event dispatch
After dispatching a "change" event due to the checked state being modified, we may have been removed from the layout tree. Make LayoutCheckBox protect itself to prevent this from crashing. Also, add a little test page for checkboxes. :^)
Diffstat (limited to 'Libraries/LibWeb/Layout/LayoutCheckBox.cpp')
-rw-r--r--Libraries/LibWeb/Layout/LayoutCheckBox.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/Libraries/LibWeb/Layout/LayoutCheckBox.cpp b/Libraries/LibWeb/Layout/LayoutCheckBox.cpp
index febab14800..f1d76c3352 100644
--- a/Libraries/LibWeb/Layout/LayoutCheckBox.cpp
+++ b/Libraries/LibWeb/Layout/LayoutCheckBox.cpp
@@ -80,6 +80,9 @@ void LayoutCheckBox::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& po
if (!m_tracking_mouse || button != GUI::MouseButton::Left)
return;
+ // NOTE: Changing the checked state of the DOM node may run arbitrary JS, which could disappear this node.
+ NonnullRefPtr protect = *this;
+
bool is_inside = enclosing_int_rect(absolute_rect()).contains(position);
if (is_inside)
node().set_checked(!node().checked());