1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:17:34 +00:00

LibWeb: Make factory methods of UIEvents::KeyboardEvent fallible

This commit is contained in:
Kenneth Myhra 2023-02-19 10:25:32 +01:00 committed by Andreas Kling
parent b91d599177
commit a401cff4e2
4 changed files with 13 additions and 13 deletions

View file

@ -1296,7 +1296,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
} else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) { } else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) {
event = TRY(Event::create(realm, "")); event = TRY(Event::create(realm, ""));
} else if (Infra::is_ascii_case_insensitive_match(interface, "keyboardevent"sv)) { } else if (Infra::is_ascii_case_insensitive_match(interface, "keyboardevent"sv)) {
event = UIEvents::KeyboardEvent::create(realm, ""); event = TRY(UIEvents::KeyboardEvent::create(realm, ""));
} else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) { } else if (Infra::is_ascii_case_insensitive_match(interface, "messageevent"sv)) {
event = TRY(HTML::MessageEvent::create(realm, "")); event = TRY(HTML::MessageEvent::create(realm, ""));
} else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv) } else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv)

View file

@ -684,17 +684,17 @@ bool EventHandler::fire_keyboard_event(DeprecatedFlyString const& event_name, HT
return fire_keyboard_event(event_name, *browsing_context_container.nested_browsing_context(), key, modifiers, code_point); return fire_keyboard_event(event_name, *browsing_context_container.nested_browsing_context(), key, modifiers, code_point);
} }
auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), event_name, key, modifiers, code_point); auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), event_name, key, modifiers, code_point).release_value_but_fixme_should_propagate_errors();
return !focused_element->dispatch_event(*event); return !focused_element->dispatch_event(event);
} }
// FIXME: De-duplicate this. This is just to prevent wasting a KeyboardEvent allocation when recursing into an (i)frame. // FIXME: De-duplicate this. This is just to prevent wasting a KeyboardEvent allocation when recursing into an (i)frame.
auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), event_name, key, modifiers, code_point); auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), event_name, key, modifiers, code_point).release_value_but_fixme_should_propagate_errors();
if (JS::GCPtr<HTML::HTMLElement> body = document->body()) if (JS::GCPtr<HTML::HTMLElement> body = document->body())
return !body->dispatch_event(*event); return !body->dispatch_event(event);
return !document->root().dispatch_event(*event); return !document->root().dispatch_event(event);
} }
bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point) bool EventHandler::handle_keydown(KeyCode key, unsigned modifiers, u32 code_point)

View file

@ -66,7 +66,7 @@ static unsigned long determine_key_code(KeyCode platform_key, u32 code_point)
return platform_key; return platform_key;
} }
KeyboardEvent* KeyboardEvent::create_from_platform_event(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point) WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create_from_platform_event(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyCode platform_key, unsigned modifiers, u32 code_point)
{ {
// FIXME: Figure out what these should actually contain. // FIXME: Figure out what these should actually contain.
DeprecatedString event_key = key_code_to_string(platform_key); DeprecatedString event_key = key_code_to_string(platform_key);
@ -104,12 +104,12 @@ bool KeyboardEvent::get_modifier_state(DeprecatedString const& key_arg)
return false; return false;
} }
KeyboardEvent* KeyboardEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init) WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init)
{ {
return realm.heap().allocate<KeyboardEvent>(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors(); return MUST_OR_THROW_OOM(realm.heap().allocate<KeyboardEvent>(realm, realm, event_name, event_init));
} }
KeyboardEvent* KeyboardEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init) WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> KeyboardEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init)
{ {
return create(realm, event_name, event_init); return create(realm, event_name, event_init);
} }

View file

@ -28,9 +28,9 @@ class KeyboardEvent final : public UIEvent {
WEB_PLATFORM_OBJECT(KeyboardEvent, UIEvent); WEB_PLATFORM_OBJECT(KeyboardEvent, UIEvent);
public: public:
static KeyboardEvent* create(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init = {}); static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init = {});
static KeyboardEvent* construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init); static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, KeyboardEventInit const& event_init);
static KeyboardEvent* create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point); static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point);
virtual ~KeyboardEvent() override; virtual ~KeyboardEvent() override;