mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
33 lines
1 KiB
C++
33 lines
1 KiB
C++
#include <AK/Function.h>
|
|
#include <LibJS/Runtime/Function.h>
|
|
#include <LibWeb/Bindings/EventListenerWrapper.h>
|
|
#include <LibWeb/Bindings/EventTargetWrapper.h>
|
|
#include <LibWeb/DOM/EventListener.h>
|
|
#include <LibWeb/DOM/EventTarget.h>
|
|
|
|
namespace Web {
|
|
namespace Bindings {
|
|
|
|
EventTargetWrapper::EventTargetWrapper(EventTarget& impl)
|
|
: m_impl(impl)
|
|
{
|
|
put_native_function("addEventListener", [](Object* this_object, const Vector<JS::Value>& arguments) {
|
|
if (arguments.size() < 2)
|
|
return JS::js_undefined();
|
|
|
|
auto event_name = arguments[0].to_string();
|
|
ASSERT(arguments[1].is_object());
|
|
ASSERT(arguments[1].as_object()->is_function());
|
|
auto* function = static_cast<JS::Function*>(const_cast<Object*>(arguments[1].as_object()));
|
|
auto listener = adopt(*new EventListener(JS::make_handle(function)));
|
|
static_cast<EventTargetWrapper*>(this_object)->impl().add_event_listener(event_name, move(listener));
|
|
return JS::js_undefined();
|
|
});
|
|
}
|
|
|
|
EventTargetWrapper::~EventTargetWrapper()
|
|
{
|
|
}
|
|
|
|
}
|
|
}
|