mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 00:45:08 +00:00
LibWeb: Give the DOM Window object a (weak) pointer to its JS wrapper
This commit is contained in:
parent
8194dfb9f4
commit
cc5cba90db
4 changed files with 20 additions and 7 deletions
|
@ -51,6 +51,11 @@ Window::~Window()
|
|||
{
|
||||
}
|
||||
|
||||
void Window::set_wrapper(Badge<Bindings::WindowObject>, Bindings::WindowObject& wrapper)
|
||||
{
|
||||
m_wrapper = wrapper.make_weak_ptr();
|
||||
}
|
||||
|
||||
void Window::alert(const String& message)
|
||||
{
|
||||
GUI::MessageBox::show(message, "Alert", GUI::MessageBox::Type::Information);
|
||||
|
@ -65,22 +70,20 @@ bool Window::confirm(const String& message)
|
|||
void Window::set_interval(JS::Function& callback, i32 interval)
|
||||
{
|
||||
// FIXME: This leaks the interval timer and makes it unstoppable.
|
||||
(void)Core::Timer::construct(interval, [handle = make_handle(&callback)] {
|
||||
(void)Core::Timer::construct(interval, [this, handle = make_handle(&callback)] {
|
||||
auto& function = const_cast<JS::Function&>(static_cast<const JS::Function&>(*handle.cell()));
|
||||
auto& interpreter = function.interpreter();
|
||||
auto& window = static_cast<Bindings::WindowObject&>(interpreter.global_object());
|
||||
interpreter.call(function, &window);
|
||||
interpreter.call(function, wrapper());
|
||||
}).leak_ref();
|
||||
}
|
||||
|
||||
void Window::set_timeout(JS::Function& callback, i32 interval)
|
||||
{
|
||||
// FIXME: This leaks the interval timer and makes it unstoppable.
|
||||
auto& timer = Core::Timer::construct(interval, [handle = make_handle(&callback)] {
|
||||
auto& timer = Core::Timer::construct(interval, [this, handle = make_handle(&callback)] {
|
||||
auto& function = const_cast<JS::Function&>(static_cast<const JS::Function&>(*handle.cell()));
|
||||
auto& interpreter = function.interpreter();
|
||||
auto& window = static_cast<Bindings::WindowObject&>(interpreter.global_object());
|
||||
interpreter.call(function, &window);
|
||||
interpreter.call(function, wrapper());
|
||||
}).leak_ref();
|
||||
timer.set_single_shot(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue