Skip to content

Commit 62f4ceb

Browse files
lukewarlowawesomekling
authored andcommitted
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.
1 parent 6147557 commit 62f4ceb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Libraries/LibWeb/HTML/HTMLDialogElement.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ void HTMLDialogElement::request_close(Optional<String> return_value)
242242
// 1. If this does not have an open attribute, then return.
243243
if (!has_attribute(AttributeNames::open))
244244
return;
245-
// 2. Assert: this's close watcher is not null.
246-
VERIFY(m_close_watcher);
245+
// 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
246+
if (!m_close_watcher) {
247+
close_the_dialog(move(return_value));
248+
return;
249+
}
247250
// 3. Set dialog's enable close watcher for requestClose() to true.
248251
// ADHOC: Implemented slightly differently to the spec, as the spec is unnecessarily complex.
249252
m_close_watcher->set_enabled(true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
3+
<!-- This test passes if it does not crash. -->
4+
5+
<dialog id="dialog" open>Dialog</dialog>
6+
7+
<script>
8+
window.onload = () => {
9+
dialog.requestClose();
10+
}
11+
</script>

0 commit comments

Comments
 (0)