mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibWeb/HTML: Port Window.event to IDL
This commit is contained in:
parent
8c0f0726d1
commit
95ce5735ce
4 changed files with 17 additions and 22 deletions
|
@ -133,7 +133,7 @@ CppType idl_type_name_to_cpp_type(Type const& type, Interface const& interface)
|
|||
if (type.name() == "long" && !type.is_nullable())
|
||||
return { .name = "i32", .sequence_storage_type = SequenceStorageType::Vector };
|
||||
|
||||
if (type.name() == "any")
|
||||
if (type.name() == "any" || type.name() == "undefined")
|
||||
return { .name = "JS::Value", .sequence_storage_type = SequenceStorageType::MarkedVector };
|
||||
|
||||
if (type.name() == "BufferSource")
|
||||
|
@ -1600,10 +1600,10 @@ static void generate_wrap_statement(SourceGenerator& generator, DeprecatedString
|
|||
auto cpp_type = IDL::idl_type_name_to_cpp_type(current_union_type, interface);
|
||||
union_generator.set("current_type", cpp_type.name);
|
||||
union_generator.append(R"~~~(
|
||||
[&vm, &realm](@current_type@ const& visited_union_value@recursion_depth@) -> JS::Value {
|
||||
[&vm, &realm]([[maybe_unused]] @current_type@ const& visited_union_value@recursion_depth@) -> JS::Value {
|
||||
// These may be unused.
|
||||
(void)vm;
|
||||
(void) realm;
|
||||
(void)realm;
|
||||
)~~~");
|
||||
|
||||
// NOTE: While we are using const&, the underlying type for wrappable types in unions is (Nonnull)RefPtr, which are not references.
|
||||
|
|
|
@ -1101,9 +1101,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
|
|||
define_native_accessor(realm, "localStorage", local_storage_getter, {}, attr);
|
||||
define_native_accessor(realm, "sessionStorage", session_storage_getter, {}, attr);
|
||||
|
||||
// Legacy
|
||||
define_native_accessor(realm, "event", event_getter, event_setter, JS::Attribute::Enumerable);
|
||||
|
||||
// FIXME: Implement codegen for readonly properties with [PutForwards]
|
||||
auto& location_accessor = storage_get("location")->value.as_accessor();
|
||||
location_accessor.set_setter(JS::NativeFunction::create(realm, location_setter, 1, "location", &realm, {}, "set"sv));
|
||||
|
@ -1332,6 +1329,15 @@ void Window::post_message(JS::Value message, String const&)
|
|||
});
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-window-event
|
||||
Variant<JS::Handle<DOM::Event>, JS::Value> Window::event() const
|
||||
{
|
||||
// The event getter steps are to return this’s current event.
|
||||
if (auto* current_event = this->current_event())
|
||||
return make_handle(const_cast<DOM::Event&>(*current_event));
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
static JS::ThrowCompletionOr<TimerHandler> make_timer_handler(JS::VM& vm, JS::Value handler)
|
||||
{
|
||||
if (handler.is_function())
|
||||
|
@ -1539,19 +1545,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::screen_setter)
|
|||
REPLACEABLE_PROPERTY_SETTER(Window, screen);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::event_getter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
if (!impl->current_event())
|
||||
return JS::js_undefined();
|
||||
return impl->current_event();
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::event_setter)
|
||||
{
|
||||
REPLACEABLE_PROPERTY_SETTER(Window, event);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
|
||||
{
|
||||
auto* impl = TRY(impl_from(vm));
|
||||
|
|
|
@ -167,6 +167,8 @@ public:
|
|||
|
||||
void post_message(JS::Value message, String const&);
|
||||
|
||||
Variant<JS::Handle<DOM::Event>, JS::Value> event() const;
|
||||
|
||||
private:
|
||||
explicit Window(JS::Realm&);
|
||||
|
||||
|
@ -235,9 +237,6 @@ private:
|
|||
JS_DECLARE_NATIVE_FUNCTION(screen_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(screen_setter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(event_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(event_setter);
|
||||
|
||||
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
|
||||
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ interface Window : EventTarget {
|
|||
undefined postMessage(any message, USVString targetOrigin);
|
||||
// FIXME: undefined postMessage(any message, USVString targetOrigin, optional sequence<object> transfer = []);
|
||||
// FIXME: undefined postMessage(any message, optional WindowPostMessageOptions options = {});
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-window-extensions
|
||||
[Replaceable] readonly attribute (Event or undefined) event; // legacy
|
||||
};
|
||||
Window includes GlobalEventHandlers;
|
||||
Window includes WindowEventHandlers;
|
||||
|
|
Loading…
Add table
Reference in a new issue