Skip to content

Commit c541d14

Browse files
committed
LibWeb/HTML: Add spec asserts to HTMLDialogElement::set_close_watcher()
Not sure when this change happened. This does include the fixed assert from here though: whatwg/html@71e70e9
1 parent e217380 commit c541d14

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Libraries/LibWeb/HTML/HTMLDialogElement.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,17 @@ void HTMLDialogElement::close_the_dialog(Optional<String> result, GC::Ptr<DOM::E
419419
// https://html.spec.whatwg.org/multipage/interactive-elements.html#set-the-dialog-close-watcher
420420
void HTMLDialogElement::set_close_watcher()
421421
{
422-
// 1. Set dialog's close watcher to the result of establishing a close watcher given dialog's relevant global object, with:
422+
// 1. Assert: dialog's close watcher is null.
423+
VERIFY(m_close_watcher == nullptr);
424+
425+
// 2. Assert: dialog has an open attribute and dialog's node document is fully active.
426+
VERIFY(has_attribute(AttributeNames::open) && document().is_fully_active());
427+
428+
// 3. Set dialog's close watcher to the result of establishing a close watcher given dialog's relevant global
429+
// object, with:
423430
m_close_watcher = CloseWatcher::establish(*document().window());
424-
// - cancelAction given canPreventClose being to return the result of firing an event named cancel at dialog, with the cancelable attribute initialized to canPreventClose.
431+
// - cancelAction given canPreventClose being to return the result of firing an event named cancel at dialog,
432+
// with the cancelable attribute initialized to canPreventClose.
425433
auto cancel_callback_function = JS::NativeFunction::create(
426434
realm(), [this](JS::VM& vm) {
427435
auto& event = as<DOM::Event>(vm.argument(0).as_object());
@@ -434,7 +442,8 @@ void HTMLDialogElement::set_close_watcher()
434442
0, Utf16FlyString {}, &realm());
435443
auto cancel_callback = realm().heap().allocate<WebIDL::CallbackType>(*cancel_callback_function, realm());
436444
m_close_watcher->add_event_listener_without_options(HTML::EventNames::cancel, DOM::IDLEventListener::create(realm(), cancel_callback));
437-
// - closeAction being to close the dialog given dialog, dialog's request close return value, and dialog's request close source element.
445+
// - closeAction being to close the dialog given dialog, dialog's request close return value, and dialog's
446+
// request close source element.
438447
auto close_callback_function = JS::NativeFunction::create(
439448
realm(), [this](JS::VM&) {
440449
close_the_dialog(m_request_close_return_value, m_request_close_source_element);
@@ -444,8 +453,9 @@ void HTMLDialogElement::set_close_watcher()
444453
0, Utf16FlyString {}, &realm());
445454
auto close_callback = realm().heap().allocate<WebIDL::CallbackType>(*close_callback_function, realm());
446455
m_close_watcher->add_event_listener_without_options(HTML::EventNames::close, DOM::IDLEventListener::create(realm(), close_callback));
447-
// - getEnabledState being to return true if dialog's enable close watcher for requestClose() is true or dialog's computed closed-by state is not None; otherwise false.
448-
// ADHOC: Implemented slightly differently to the spec, as the spec is unnecessarily complex.
456+
// - getEnabledState being to return true if dialog's enable close watcher for request close is true or dialog's
457+
// computed closed-by state is not None; otherwise false.
458+
// AD-HOC: Implemented slightly differently to the spec, as the spec is unnecessarily complex.
449459
// FIXME: This should be set based on dialog closedby state, when implemented.
450460
m_close_watcher->set_enabled(m_is_modal);
451461
}

0 commit comments

Comments
 (0)