From 62f4cebbee3cdb42de42ae4ba4b43e50503d7a07 Mon Sep 17 00:00:00 2001 From: Luke Warlow Date: Sun, 2 Feb 2025 23:59:01 +0000 Subject: [PATCH] LibWeb: Fix dialog.requestClose() crash The spec previously asserted that close watcher was not null. This could lead to a crash in some situations, so instead we skip to close the dialog. --- Libraries/LibWeb/HTML/HTMLDialogElement.cpp | 7 +++++-- .../the-dialog-element/dialog-requestclose-crash.html | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Crash/wpt-import/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose-crash.html diff --git a/Libraries/LibWeb/HTML/HTMLDialogElement.cpp b/Libraries/LibWeb/HTML/HTMLDialogElement.cpp index ee8f1e30f7e..e3d9f360693 100644 --- a/Libraries/LibWeb/HTML/HTMLDialogElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLDialogElement.cpp @@ -242,8 +242,11 @@ void HTMLDialogElement::request_close(Optional return_value) // 1. If this does not have an open attribute, then return. if (!has_attribute(AttributeNames::open)) return; - // 2. Assert: this's close watcher is not null. - VERIFY(m_close_watcher); + // ADHOC: 2. If this's close watcher is null, then close the dialog this with returnValue, and return. See https://github.com/whatwg/html/pull/10983 + if (!m_close_watcher) { + close_the_dialog(move(return_value)); + return; + } // 3. Set dialog's enable close watcher for requestClose() to true. // ADHOC: Implemented slightly differently to the spec, as the spec is unnecessarily complex. m_close_watcher->set_enabled(true); diff --git a/Tests/LibWeb/Crash/wpt-import/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose-crash.html b/Tests/LibWeb/Crash/wpt-import/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose-crash.html new file mode 100644 index 00000000000..bfa400a7524 --- /dev/null +++ b/Tests/LibWeb/Crash/wpt-import/html/semantics/interactive-elements/the-dialog-element/dialog-requestclose-crash.html @@ -0,0 +1,11 @@ + + + + +Dialog + +