1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:37:34 +00:00

LibJS: Add a helper for calling JS::Function's with arguments

The fact that a `MarkedValueList` had to be created was just annoying,
so here's an alternative.
This patchset also removes some (now) unneeded MarkedValueList.h includes.
This commit is contained in:
AnotherTest 2020-08-25 22:18:32 +04:30 committed by Andreas Kling
parent 521e730df1
commit 394e4c04cd
15 changed files with 72 additions and 113 deletions

View file

@ -28,7 +28,6 @@
#include <LibJS/AST.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibWeb/Bindings/EventWrapper.h>
#include <LibWeb/Bindings/EventWrapperFactory.h>
@ -38,8 +37,8 @@
#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventListener.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/HTML/HTMLAnchorElement.h>
#include <LibWeb/Layout/LayoutBlock.h>
#include <LibWeb/Layout/LayoutDocument.h>
#include <LibWeb/Layout/LayoutInline.h>
@ -132,10 +131,8 @@ void Node::dispatch_event(NonnullRefPtr<Event> event)
dbg() << "calling event listener with this=" << this_value;
#endif
auto* event_wrapper = wrap(global_object, *event);
JS::MarkedValueList arguments(global_object.heap());
arguments.append(event_wrapper);
auto& interpreter = document().interpreter();
(void)interpreter.call(function, this_value, move(arguments));
(void)interpreter.call(function, this_value, event_wrapper);
if (interpreter.exception())
interpreter.clear_exception();
}

View file

@ -28,12 +28,11 @@
#include <LibGUI/MessageBox.h>
#include <LibJS/Interpreter.h>
#include <LibJS/Runtime/Function.h>
#include <LibJS/Runtime/MarkedValueList.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Timer.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Page/Frame.h>
#include <LibWeb/InProcessWebView.h>
#include <LibWeb/Page/Frame.h>
namespace Web::DOM {
@ -122,10 +121,8 @@ i32 Window::request_animation_frame(JS::Function& callback)
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& interpreter = function.interpreter();
JS::MarkedValueList arguments(interpreter.heap());
arguments.append(JS::Value(fake_timestamp));
fake_timestamp += 10;
(void)interpreter.call(function, {}, move(arguments));
(void)interpreter.call(function, {}, JS::Value(fake_timestamp));
if (interpreter.exception())
interpreter.clear_exception();
GUI::DisplayLink::unregister_callback(link_id);

View file

@ -96,10 +96,8 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr<DOM::Event> event)
auto& function = const_cast<DOM::EventListener&>(*listener.listener).function();
auto& global_object = function.global_object();
auto* this_value = wrap(global_object, *this);
JS::MarkedValueList arguments(global_object.heap());
arguments.append(wrap(global_object, *event));
auto& interpreter = function.interpreter();
(void)interpreter.call(function, this_value, move(arguments));
(void)interpreter.call(function, this_value, wrap(global_object, *this));
if (interpreter.exception())
interpreter.clear_exception();
}