mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:55:08 +00:00
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. :^)
This commit is contained in:
parent
71092226bd
commit
b62043dbca
3 changed files with 15 additions and 0 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue