mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb: Make the Window object "inherit" from EventTarget :^)
Since Web::Bindings::WindowObject inherits from JS::GlobalObject, it cannot also inherit from Web::Bindings::EventTargetWrapper. However, that's not actually necessary. Instead, we simply set the Window object's prototype to the EventTargetPrototype, and add a little extra branch in the impl_from() function that turns the JS "this" value into a DOM::EventTarget*. With this, you can now call window.addEventListener()! Very cool :^) Fixes #4758.
This commit is contained in:
parent
fd83918476
commit
0639e77898
Notes:
sideshowbarker
2024-07-18 23:07:27 +09:00
Author: https://github.com/awesomekling
Commit: 0639e77898
13 changed files with 26 additions and 14 deletions
|
@ -840,6 +840,7 @@ void generate_prototype_implementation(const IDL::Interface& interface)
|
|||
#include <LibWeb/Bindings/WindowObject.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/DOM/EventListener.h>
|
||||
#include <LibWeb/DOM/Window.h>
|
||||
#include <LibWeb/HTML/HTMLElement.h>
|
||||
#include <LibWeb/Origin.h>
|
||||
|
||||
|
@ -927,9 +928,18 @@ static @fully_qualified_name@* impl_from(JS::VM& vm, JS::GlobalObject& global_ob
|
|||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return {};
|
||||
)~~~");
|
||||
|
||||
if (interface.name == "EventTarget") {
|
||||
generator.append(R"~~~(
|
||||
if (is<WindowObject>(this_object)) {
|
||||
return &static_cast<WindowObject*>(this_object)->impl();
|
||||
}
|
||||
)~~~");
|
||||
}
|
||||
|
||||
generator.append(R"~~~(
|
||||
if (!is<@wrapper_class@>(this_object)) {
|
||||
dbgln("expected @wrapper_class@ but got {}", this_object->class_name());
|
||||
ASSERT_NOT_REACHED();
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "@fully_qualified_name@");
|
||||
return nullptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue