mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:17:35 +00:00
LibWeb: Use a JS::Handle to keep the EventListener function alive
This commit is contained in:
parent
a119b61782
commit
41f3817b36
5 changed files with 18 additions and 14 deletions
|
@ -14,11 +14,5 @@ EventListenerWrapper::~EventListenerWrapper()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventListenerWrapper::visit_children(JS::Cell::Visitor& visitor)
|
|
||||||
{
|
|
||||||
Wrapper::visit_children(visitor);
|
|
||||||
visitor.visit(impl().function());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "EventListenerWrapper"; }
|
virtual const char* class_name() const override { return "EventListenerWrapper"; }
|
||||||
virtual void visit_children(JS::Cell::Visitor&) override;
|
|
||||||
|
|
||||||
NonnullRefPtr<EventListener> m_impl;
|
NonnullRefPtr<EventListener> m_impl;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,8 +18,8 @@ EventTargetWrapper::EventTargetWrapper(EventTarget& impl)
|
||||||
auto event_name = arguments[0].to_string();
|
auto event_name = arguments[0].to_string();
|
||||||
ASSERT(arguments[1].is_object());
|
ASSERT(arguments[1].is_object());
|
||||||
ASSERT(arguments[1].as_object()->is_function());
|
ASSERT(arguments[1].as_object()->is_function());
|
||||||
auto listener = adopt(*new EventListener(static_cast<JS::Function*>(const_cast<Object*>(arguments[1].as_object()))));
|
auto* function = static_cast<JS::Function*>(const_cast<Object*>(arguments[1].as_object()));
|
||||||
wrap(this_object->heap(), *listener);
|
auto listener = adopt(*new EventListener(JS::make_handle(function)));
|
||||||
static_cast<EventTargetWrapper*>(this_object)->impl().add_event_listener(event_name, move(listener));
|
static_cast<EventTargetWrapper*>(this_object)->impl().add_event_listener(event_name, move(listener));
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include <LibJS/Runtime/Function.h>
|
||||||
|
#include <LibWeb/DOM/EventListener.h>
|
||||||
|
|
||||||
|
namespace Web {
|
||||||
|
|
||||||
|
JS::Function* EventListener::function()
|
||||||
|
{
|
||||||
|
return m_function.cell();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Heap/Handle.h>
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
#include <LibWeb/Bindings/Wrappable.h>
|
||||||
|
|
||||||
namespace Web {
|
namespace Web {
|
||||||
|
@ -12,15 +12,15 @@ class EventListener
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::EventListenerWrapper;
|
using WrapperType = Bindings::EventListenerWrapper;
|
||||||
|
|
||||||
explicit EventListener(JS::Function* function)
|
explicit EventListener(JS::Handle<JS::Function> function)
|
||||||
: m_function(function)
|
: m_function(move(function))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
JS::Function* function() { return m_function; }
|
JS::Function* function();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JS::Function* m_function { nullptr };
|
JS::Handle<JS::Function> m_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue