LibWeb/HTML: Define Window's {Global,Window}EventHandlers via IDL

This commit is contained in:
Linus Groh 2023-03-05 16:01:53 +00:00
parent c130fd6993
commit a6f8b18649
Notes: sideshowbarker 2024-07-17 18:49:10 +09:00
3 changed files with 3 additions and 39 deletions

View file

@ -1207,13 +1207,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
// WebAssembly "namespace"
define_direct_property("WebAssembly", MUST_OR_THROW_OOM(heap().allocate<Bindings::WebAssemblyObject>(realm, realm)), JS::Attribute::Enumerable | JS::Attribute::Configurable);
// HTML::GlobalEventHandlers and HTML::WindowEventHandlers
#define __ENUMERATE(attribute, event_name) \
define_native_accessor(realm, #attribute, attribute##_getter, attribute##_setter, attr);
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE);
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE);
#undef __ENUMERATE
return {};
}
@ -1963,29 +1956,4 @@ JS_DEFINE_NATIVE_FUNCTION(Window::navigator_getter)
return impl->m_navigator;
}
#define __ENUMERATE(attribute, event_name) \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_getter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto retval = impl->attribute(); \
if (!retval) \
return JS::js_null(); \
return &retval->callback; \
} \
JS_DEFINE_NATIVE_FUNCTION(Window::attribute##_setter) \
{ \
auto* impl = TRY(impl_from(vm)); \
auto value = vm.argument(0); \
WebIDL::CallbackType* cpp_value = nullptr; \
if (value.is_object()) { \
cpp_value = vm.heap().allocate_without_realm<WebIDL::CallbackType>( \
value.as_object(), HTML::incumbent_settings_object()); \
} \
impl->set_##attribute(cpp_value); \
return JS::js_undefined(); \
}
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE)
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE)
#undef __ENUMERATE
}

View file

@ -291,13 +291,6 @@ private:
JS_DECLARE_NATIVE_FUNCTION(navigator_getter);
#define __ENUMERATE(attribute, event_name) \
JS_DECLARE_NATIVE_FUNCTION(attribute##_getter); \
JS_DECLARE_NATIVE_FUNCTION(attribute##_setter);
ENUMERATE_GLOBAL_EVENT_HANDLERS(__ENUMERATE);
ENUMERATE_WINDOW_EVENT_HANDLERS(__ENUMERATE);
#undef __ENUMERATE
HTML::Location* m_location { nullptr };
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap

View file

@ -1,6 +1,9 @@
#import <DOM/EventHandler.idl>
#import <DOM/EventTarget.idl>
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window
[Global=Window, Exposed=Window, LegacyUnenumerableNamedProperties]
interface Window : EventTarget {
};
Window includes GlobalEventHandlers;
Window includes WindowEventHandlers;