diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp
index fb5efb24c7..0142ae02d1 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Window.cpp
@@ -430,12 +430,6 @@ WebIDL::ExceptionOr> Window::open_impl(StringView u
return target_browsing_context->window_proxy();
}
-void Window::alert_impl(DeprecatedString const& message)
-{
- if (auto* page = this->page())
- page->did_request_alert(message);
-}
-
bool Window::confirm_impl(DeprecatedString const& message)
{
if (auto* page = this->page())
@@ -1142,7 +1136,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge impl_from(JS::VM& vm)
return vm.throw_completion(JS::ErrorType::NotAnObjectOfType, "Window");
}
+// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-alert
+void Window::alert(String const& message)
+{
+ // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
+ // Note: This method is defined using two overloads, instead of using an optional argument,
+ // for historical reasons. The practical impact of this is that alert(undefined) is
+ // treated as alert("undefined"), but alert() is treated as alert("").
+ // FIXME: Make this fully spec compliant.
+ if (auto* page = this->page())
+ page->did_request_alert(message.to_deprecated_string());
+}
+
JS_DEFINE_NATIVE_FUNCTION(Window::open)
{
auto* impl = TRY(impl_from(vm));
@@ -1267,20 +1272,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::alert)
-{
- // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#simple-dialogs
- // Note: This method is defined using two overloads, instead of using an optional argument,
- // for historical reasons. The practical impact of this is that alert(undefined) is
- // treated as alert("undefined"), but alert() is treated as alert("").
- auto* impl = TRY(impl_from(vm));
- DeprecatedString message = "";
- if (vm.argument_count())
- message = TRY(vm.argument(0).to_deprecated_string(vm));
- impl->alert_impl(message);
- return JS::js_undefined();
-}
-
JS_DEFINE_NATIVE_FUNCTION(Window::confirm)
{
auto* impl = TRY(impl_from(vm));
diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h
index 75df91f6c8..40b5c498f6 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);
- void alert_impl(DeprecatedString const&);
bool confirm_impl(DeprecatedString const&);
DeprecatedString prompt_impl(DeprecatedString const&, DeprecatedString const&);
i32 request_animation_frame_impl(WebIDL::CallbackType& js_callback);
@@ -143,6 +142,9 @@ public:
Vector> pdf_viewer_plugin_objects();
Vector> pdf_viewer_mime_type_objects();
+ // JS API functions
+ void alert(String const& message = {});
+
private:
explicit Window(JS::Realm&);
@@ -265,7 +267,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(is_secure_context_getter);
JS_DECLARE_NATIVE_FUNCTION(open);
- JS_DECLARE_NATIVE_FUNCTION(alert);
JS_DECLARE_NATIVE_FUNCTION(confirm);
JS_DECLARE_NATIVE_FUNCTION(prompt);
JS_DECLARE_NATIVE_FUNCTION(set_interval);
diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl
index 19e5f269f7..67bc7da2f4 100644
--- a/Userland/Libraries/LibWeb/HTML/Window.idl
+++ b/Userland/Libraries/LibWeb/HTML/Window.idl
@@ -2,8 +2,11 @@
#import
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window
-[Global=Window, Exposed=Window, LegacyUnenumerableNamedProperties]
+[Global=Window, Exposed=Window, LegacyUnenumerableNamedProperties, UseNewAKString]
interface Window : EventTarget {
+ // user prompts
+ undefined alert();
+ undefined alert(DOMString message);
};
Window includes GlobalEventHandlers;
Window includes WindowEventHandlers;