Browse Source

LibWeb: Mark event listeners generated by event handler attributes

We have to mark the EventListener objects so that we can tell them apart
from listeners added via the addEventListener() API.

This makes element.onfoo getters actually return the handler function.
Andreas Kling 3 years ago
parent
commit
5ac82efbe1
1 changed files with 2 additions and 2 deletions
  1. 2 2
      Userland/Libraries/LibWeb/DOM/EventTarget.cpp

+ 2 - 2
Userland/Libraries/LibWeb/DOM/EventTarget.cpp

@@ -124,7 +124,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, HTML::Event
 
     RefPtr<DOM::EventListener> listener;
     if (!value.callback.is_null()) {
-        listener = adopt_ref(*new DOM::EventListener(move(value.callback)));
+        listener = adopt_ref(*new DOM::EventListener(move(value.callback), true));
     } else {
         StringBuilder builder;
         builder.appendff("function {}(event) {{\n{}\n}}", name, value.string);
@@ -136,7 +136,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, HTML::Event
         }
         auto* function = JS::ECMAScriptFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false);
         VERIFY(function);
-        listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function))));
+        listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)), true));
     }
     if (listener) {
         for (auto& registered_listener : target->listeners()) {