mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:48:11 +00:00
LibWeb/HTML: Port Window.confirm() to IDL
This commit is contained in:
parent
a0b73eb5f7
commit
bbffda5f55
3 changed files with 12 additions and 19 deletions
|
@ -430,13 +430,6 @@ WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> 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<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
|||
define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
||||
define_native_function(realm, "open", open, 0, attr);
|
||||
define_native_function(realm, "confirm", confirm, 0, attr);
|
||||
define_native_function(realm, "prompt", prompt, 0, attr);
|
||||
define_native_function(realm, "setInterval", set_interval, 1, attr);
|
||||
define_native_function(realm, "setTimeout", set_timeout, 1, attr);
|
||||
|
@ -1250,6 +1242,16 @@ void Window::alert(String const& message)
|
|||
page->did_request_alert(message.to_deprecated_string());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm
|
||||
bool Window::confirm(Optional<String> 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));
|
||||
|
|
|
@ -66,7 +66,6 @@ public:
|
|||
void set_import_maps_allowed(bool import_maps_allowed) { m_import_maps_allowed = import_maps_allowed; }
|
||||
|
||||
WebIDL::ExceptionOr<JS::GCPtr<HTML::WindowProxy>> 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<String> 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue