From 62d5f7938849fcbd9bf841c7b8e5391244b44903 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 29 Mar 2020 00:45:53 +0100 Subject: [PATCH] LibJS+LibWeb: Function calls should always go through Interpreter This ensures that we set up a call frame with |this| and arguments. --- Libraries/LibJS/Interpreter.h | 2 +- Libraries/LibWeb/DOM/Document.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Libraries/LibJS/Interpreter.h b/Libraries/LibJS/Interpreter.h index e72c466d3a1..2485a83ea2e 100644 --- a/Libraries/LibJS/Interpreter.h +++ b/Libraries/LibJS/Interpreter.h @@ -88,7 +88,7 @@ public: void enter_scope(const ScopeNode&, Vector, ScopeType); void exit_scope(const ScopeNode&); - Value call(Function*, Value this_value, const Vector& arguments); + Value call(Function*, Value this_value = {}, const Vector& arguments = {}); CallFrame& push_call_frame() { diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 26bcc9f127a..e3520c2ad2b 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -357,8 +357,8 @@ JS::Interpreter& Document::interpreter() // FIXME: This timer should not be leaked! It should also be removable with clearInterval()! (void)Core::Timer::construct( arguments[1].to_i32(), [this, callback] { - // FIXME: Perform the call through Interpreter so it can set up a call frame! - const_cast(static_cast(callback.cell()))->call(*m_interpreter); + auto* function = const_cast(static_cast(callback.cell())); + m_interpreter->call(function); }) .leak_ref(); @@ -374,8 +374,8 @@ JS::Interpreter& Document::interpreter() auto callback = make_handle(const_cast(arguments[0].as_object())); // FIXME: Don't hand out raw DisplayLink ID's to JavaScript! i32 link_id = GUI::DisplayLink::register_callback([this, callback](i32 link_id) { - // FIXME: Perform the call through Interpreter so it can set up a call frame! - const_cast(static_cast(callback.cell()))->call(*m_interpreter); + auto* function = const_cast(static_cast(callback.cell())); + m_interpreter->call(function); GUI::DisplayLink::unregister_callback(link_id); }); return JS::Value(link_id);