mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibWeb: Implement JS confirm()
This commit is contained in:
parent
0a483cf677
commit
1f6578ee0a
4 changed files with 20 additions and 0 deletions
|
@ -46,6 +46,7 @@ WindowObject::WindowObject(Window& impl)
|
||||||
put("window", this);
|
put("window", this);
|
||||||
put_native_property("document", document_getter, document_setter);
|
put_native_property("document", document_getter, document_setter);
|
||||||
put_native_function("alert", alert);
|
put_native_function("alert", alert);
|
||||||
|
put_native_function("confirm", confirm);
|
||||||
put_native_function("setInterval", set_interval, 1);
|
put_native_function("setInterval", set_interval, 1);
|
||||||
put_native_function("setTimeout", set_timeout, 1);
|
put_native_function("setTimeout", set_timeout, 1);
|
||||||
put_native_function("requestAnimationFrame", request_animation_frame, 1);
|
put_native_function("requestAnimationFrame", request_animation_frame, 1);
|
||||||
|
@ -96,6 +97,17 @@ JS::Value WindowObject::alert(JS::Interpreter& interpreter)
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS::Value WindowObject::confirm(JS::Interpreter& interpreter)
|
||||||
|
{
|
||||||
|
auto* impl = impl_from(interpreter);
|
||||||
|
if (!impl)
|
||||||
|
return {};
|
||||||
|
auto& arguments = interpreter.call_frame().arguments;
|
||||||
|
if (arguments.size() < 1)
|
||||||
|
return {};
|
||||||
|
return JS::Value(impl->confirm(arguments[0].to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
JS::Value WindowObject::set_interval(JS::Interpreter& interpreter)
|
JS::Value WindowObject::set_interval(JS::Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(interpreter);
|
auto* impl = impl_from(interpreter);
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
static void document_setter(JS::Interpreter&, JS::Value);
|
static void document_setter(JS::Interpreter&, JS::Value);
|
||||||
|
|
||||||
static JS::Value alert(JS::Interpreter&);
|
static JS::Value alert(JS::Interpreter&);
|
||||||
|
static JS::Value confirm(JS::Interpreter&);
|
||||||
static JS::Value set_interval(JS::Interpreter&);
|
static JS::Value set_interval(JS::Interpreter&);
|
||||||
static JS::Value set_timeout(JS::Interpreter&);
|
static JS::Value set_timeout(JS::Interpreter&);
|
||||||
static JS::Value request_animation_frame(JS::Interpreter&);
|
static JS::Value request_animation_frame(JS::Interpreter&);
|
||||||
|
|
|
@ -52,6 +52,12 @@ void Window::alert(const String& message)
|
||||||
GUI::MessageBox::show(message, "Alert", GUI::MessageBox::Type::Information);
|
GUI::MessageBox::show(message, "Alert", GUI::MessageBox::Type::Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Window::confirm(const String& message)
|
||||||
|
{
|
||||||
|
auto confirm_result = GUI::MessageBox::show(message, "Confirm", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::OKCancel);
|
||||||
|
return confirm_result == GUI::Dialog::ExecResult::ExecOK;
|
||||||
|
}
|
||||||
|
|
||||||
void Window::set_interval(JS::Function& callback, i32 interval)
|
void Window::set_interval(JS::Function& callback, i32 interval)
|
||||||
{
|
{
|
||||||
// FIXME: This leaks the interval timer and makes it unstoppable.
|
// FIXME: This leaks the interval timer and makes it unstoppable.
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
Document& document() { return m_document; }
|
Document& document() { return m_document; }
|
||||||
|
|
||||||
void alert(const String&);
|
void alert(const String&);
|
||||||
|
bool confirm(const String&);
|
||||||
i32 request_animation_frame(JS::Function&);
|
i32 request_animation_frame(JS::Function&);
|
||||||
void cancel_animation_frame(i32);
|
void cancel_animation_frame(i32);
|
||||||
void set_interval(JS::Function&, i32);
|
void set_interval(JS::Function&, i32);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue