LibWeb: Use JS::VM::call() in timer and RAF callback invocation

This removes assumptions about having an Interpreter, and also unbreaks
requestAnimationFrame which was asserting.
This commit is contained in:
Andreas Kling 2020-09-27 20:31:13 +02:00
parent 340d6b0ef7
commit 700cbc02ec

View file

@ -26,7 +26,6 @@
#include <LibGUI/DisplayLink.h> #include <LibGUI/DisplayLink.h>
#include <LibGUI/MessageBox.h> #include <LibGUI/MessageBox.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Function.h> #include <LibJS/Runtime/Function.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Timer.h> #include <LibWeb/DOM/Timer.h>
@ -86,6 +85,7 @@ void Window::timer_did_fire(Badge<Timer>, Timer& timer)
{ {
// We should not be here if there's no JS wrapper for the Window object. // We should not be here if there's no JS wrapper for the Window object.
ASSERT(wrapper()); ASSERT(wrapper());
auto& vm = wrapper()->vm();
// NOTE: This protector pointer keeps the timer alive until the end of this function no matter what. // NOTE: This protector pointer keeps the timer alive until the end of this function no matter what.
NonnullRefPtr protector(timer); NonnullRefPtr protector(timer);
@ -94,10 +94,9 @@ void Window::timer_did_fire(Badge<Timer>, Timer& timer)
m_timers.remove(timer.id()); m_timers.remove(timer.id());
} }
auto& interpreter = document().interpreter(); (void)vm.call(timer.callback(), wrapper());
(void)interpreter.call(timer.callback(), wrapper()); if (vm.exception())
if (interpreter.exception()) vm.clear_exception();
interpreter.vm().clear_exception();
} }
i32 Window::allocate_timer_id(Badge<Timer>) i32 Window::allocate_timer_id(Badge<Timer>)
@ -122,11 +121,11 @@ i32 Window::request_animation_frame(JS::Function& callback)
i32 link_id = GUI::DisplayLink::register_callback([handle = make_handle(&callback)](i32 link_id) { i32 link_id = GUI::DisplayLink::register_callback([handle = make_handle(&callback)](i32 link_id) {
auto& function = const_cast<JS::Function&>(static_cast<const JS::Function&>(*handle.cell())); auto& function = const_cast<JS::Function&>(static_cast<const JS::Function&>(*handle.cell()));
auto& interpreter = function.interpreter(); auto& vm = function.vm();
fake_timestamp += 10; fake_timestamp += 10;
(void)interpreter.call(function, {}, JS::Value(fake_timestamp)); (void)vm.call(function, {}, JS::Value(fake_timestamp));
if (interpreter.exception()) if (vm.exception())
interpreter.vm().clear_exception(); vm.clear_exception();
GUI::DisplayLink::unregister_callback(link_id); GUI::DisplayLink::unregister_callback(link_id);
}); });