diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 0142ae02d1..7de18b1fdf 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -430,13 +430,6 @@ WebIDL::ExceptionOr> Window::open_impl(StringView u return target_browsing_context->window_proxy(); } -bool Window::confirm_impl(DeprecatedString const& message) -{ - if (auto* page = this->page()) - return page->did_request_confirm(message); - return false; -} - DeprecatedString Window::prompt_impl(DeprecatedString const& message, DeprecatedString const& default_) { if (auto* page = this->page()) @@ -1136,7 +1129,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badgedid_request_alert(message.to_deprecated_string()); } +// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm +bool Window::confirm(Optional const& message) +{ + // FIXME: Make this fully spec compliant. + // NOTE: `message` has an IDL-provided default value and is never empty. + if (auto* page = this->page()) + return page->did_request_confirm(message->to_deprecated_string()); + return false; +} + JS_DEFINE_NATIVE_FUNCTION(Window::open) { auto* impl = TRY(impl_from(vm)); @@ -1272,15 +1274,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::open) return TRY(Bindings::throw_dom_exception_if_needed(vm, [&] { return impl->open_impl(url, target, features); })); } -JS_DEFINE_NATIVE_FUNCTION(Window::confirm) -{ - auto* impl = TRY(impl_from(vm)); - DeprecatedString message = ""; - if (!vm.argument(0).is_undefined()) - message = TRY(vm.argument(0).to_deprecated_string(vm)); - return JS::Value(impl->confirm_impl(message)); -} - JS_DEFINE_NATIVE_FUNCTION(Window::prompt) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 40b5c498f6..d6266a962b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -66,7 +66,6 @@ public: void set_import_maps_allowed(bool import_maps_allowed) { m_import_maps_allowed = import_maps_allowed; } WebIDL::ExceptionOr> open_impl(StringView url, StringView target, StringView features); - bool confirm_impl(DeprecatedString const&); DeprecatedString prompt_impl(DeprecatedString const&, DeprecatedString const&); i32 request_animation_frame_impl(WebIDL::CallbackType& js_callback); void cancel_animation_frame_impl(i32); @@ -144,6 +143,7 @@ public: // JS API functions void alert(String const& message = {}); + bool confirm(Optional const& message); private: explicit Window(JS::Realm&); @@ -267,7 +267,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(is_secure_context_getter); JS_DECLARE_NATIVE_FUNCTION(open); - JS_DECLARE_NATIVE_FUNCTION(confirm); JS_DECLARE_NATIVE_FUNCTION(prompt); JS_DECLARE_NATIVE_FUNCTION(set_interval); JS_DECLARE_NATIVE_FUNCTION(set_timeout); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 67bc7da2f4..21cfe24f83 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -7,6 +7,7 @@ interface Window : EventTarget { // user prompts undefined alert(); undefined alert(DOMString message); + boolean confirm(optional DOMString message = ""); }; Window includes GlobalEventHandlers; Window includes WindowEventHandlers;