From 97382677bd2cfb3fd5bd73942cc344ed425411a7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 29 Apr 2020 12:46:20 +0200 Subject: [PATCH] LibWeb: Make EventListener::function() return a reference --- Libraries/LibWeb/DOM/EventListener.cpp | 5 +++-- Libraries/LibWeb/DOM/EventListener.h | 2 +- Libraries/LibWeb/DOM/Node.cpp | 11 ++++++----- Libraries/LibWeb/DOM/XMLHttpRequest.cpp | 11 ++++++----- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/DOM/EventListener.cpp b/Libraries/LibWeb/DOM/EventListener.cpp index 407aa6d5adf..da0c545a6e2 100644 --- a/Libraries/LibWeb/DOM/EventListener.cpp +++ b/Libraries/LibWeb/DOM/EventListener.cpp @@ -29,9 +29,10 @@ namespace Web { -JS::Function* EventListener::function() +JS::Function& EventListener::function() { - return m_function.cell(); + ASSERT(m_function.cell()); + return *m_function.cell(); } } diff --git a/Libraries/LibWeb/DOM/EventListener.h b/Libraries/LibWeb/DOM/EventListener.h index a4a4ac8db54..83e8fd61551 100644 --- a/Libraries/LibWeb/DOM/EventListener.h +++ b/Libraries/LibWeb/DOM/EventListener.h @@ -43,7 +43,7 @@ public: { } - JS::Function* function(); + JS::Function& function(); private: JS::Handle m_function; diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index b8c1636380c..3f357134589 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -134,18 +134,19 @@ void Node::dispatch_event(NonnullRefPtr event) { for (auto& listener : listeners()) { if (listener.event_name == event->name()) { - auto* function = const_cast(*listener.listener).function(); + auto& function = const_cast(*listener.listener).function(); #ifdef EVENT_DEBUG static_cast(function)->body().dump(0); #endif - auto* this_value = wrap(function->heap(), *this); + auto& heap = function.heap(); + auto* this_value = wrap(heap, *this); #ifdef EVENT_DEBUG dbg() << "calling event listener with this=" << this_value; #endif - auto* event_wrapper = wrap(function->heap(), *event); - JS::MarkedValueList arguments(function->heap()); + auto* event_wrapper = wrap(heap, *event); + JS::MarkedValueList arguments(heap); arguments.append(event_wrapper); - document().interpreter().call(function, this_value, move(arguments)); + document().interpreter().call(&function, this_value, move(arguments)); } } diff --git a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp index 95e36e047d4..c19d0c892f2 100644 --- a/Libraries/LibWeb/DOM/XMLHttpRequest.cpp +++ b/Libraries/LibWeb/DOM/XMLHttpRequest.cpp @@ -92,11 +92,12 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr event) { for (auto& listener : listeners()) { if (listener.event_name == event->name()) { - auto* function = const_cast(*listener.listener).function(); - auto* this_value = wrap(function->heap(), *this); - JS::MarkedValueList arguments(function->heap()); - arguments.append(wrap(function->heap(), *event)); - function->interpreter().call(function, this_value, move(arguments)); + auto& function = const_cast(*listener.listener).function(); + auto& heap = function.heap(); + auto* this_value = wrap(heap, *this); + JS::MarkedValueList arguments(heap); + arguments.append(wrap(heap, *event)); + function.interpreter().call(&function, this_value, move(arguments)); } } }