Skip to content

Commit

Permalink
LibWeb: Make EventListener::function() return a reference
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomekling committed Apr 29, 2020
1 parent a38658d commit 9738267
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Libraries/LibWeb/DOM/EventListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
2 changes: 1 addition & 1 deletion Libraries/LibWeb/DOM/EventListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EventListener
{
}

JS::Function* function();
JS::Function& function();

private:
JS::Handle<JS::Function> m_function;
Expand Down
11 changes: 6 additions & 5 deletions Libraries/LibWeb/DOM/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,19 @@ void Node::dispatch_event(NonnullRefPtr<Event> event)
{
for (auto& listener : listeners()) {
if (listener.event_name == event->name()) {
auto* function = const_cast<EventListener&>(*listener.listener).function();
auto& function = const_cast<EventListener&>(*listener.listener).function();
#ifdef EVENT_DEBUG
static_cast<const JS::ScriptFunction*>(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));
}
}

Expand Down
11 changes: 6 additions & 5 deletions Libraries/LibWeb/DOM/XMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ void XMLHttpRequest::dispatch_event(NonnullRefPtr<Event> event)
{
for (auto& listener : listeners()) {
if (listener.event_name == event->name()) {
auto* function = const_cast<EventListener&>(*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<EventListener&>(*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));
}
}
}
Expand Down

0 comments on commit 9738267

Please sign in to comment.