mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibWeb: Make factory methods of UIEvents::KeyboardEvent fallible
This commit is contained in:
parent
b91d599177
commit
a401cff4e2
Notes:
sideshowbarker
2024-07-17 10:31:19 +09:00
Author: https://github.com/kennethmyhra Commit: https://github.com/SerenityOS/serenity/commit/a401cff4e2 Pull-request: https://github.com/SerenityOS/serenity/pull/17542
@ -1296,7 +1296,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
|
||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) {
|
||||
event = TRY(Event::create(realm, ""));
|
||||
} 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)) {
|
||||
event = TRY(HTML::MessageEvent::create(realm, ""));
|
||||
} else if (Infra::is_ascii_case_insensitive_match(interface, "mouseevent"sv)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
auto event = UIEvents::KeyboardEvent::create_from_platform_event(document->realm(), event_name, key, modifiers, code_point);
|
||||
return !focused_element->dispatch_event(*event);
|
||||
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);
|
||||
}
|
||||
|
||||
// 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())
|
||||
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)
|
||||
|
@ -66,7 +66,7 @@ static unsigned long determine_key_code(KeyCode platform_key, u32 code_point)
|
||||
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.
|
||||
DeprecatedString event_key = key_code_to_string(platform_key);
|
||||
@ -104,12 +104,12 @@ bool KeyboardEvent::get_modifier_state(DeprecatedString const& key_arg)
|
||||
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);
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ class KeyboardEvent final : public UIEvent {
|
||||
WEB_PLATFORM_OBJECT(KeyboardEvent, UIEvent);
|
||||
|
||||
public:
|
||||
static 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 KeyboardEvent* create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point);
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create(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 WebIDL::ExceptionOr<JS::NonnullGCPtr<KeyboardEvent>> create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, KeyCode, unsigned modifiers, u32 code_point);
|
||||
|
||||
virtual ~KeyboardEvent() override;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user