LibWeb: Make factory methods of UIEvents::UIEvent fallible

This affects calls to FocusEvent::create() since FocusEvent does not
implement its own create() method.
This commit is contained in:
Kenneth Myhra 2023-02-19 10:38:20 +01:00 committed by Andreas Kling
parent a401cff4e2
commit 587cf355ed
Notes: sideshowbarker 2024-07-17 07:38:17 +09:00
4 changed files with 12 additions and 12 deletions

View File

@ -1290,7 +1290,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
|| Infra::is_ascii_case_insensitive_match(interface, "events"sv)) {
event = TRY(Event::create(realm, ""));
} else if (Infra::is_ascii_case_insensitive_match(interface, "focusevent"sv)) {
event = UIEvents::FocusEvent::create(realm, "");
event = TRY(UIEvents::FocusEvent::create(realm, ""));
} else if (Infra::is_ascii_case_insensitive_match(interface, "hashchangeevent"sv)) {
event = TRY(Event::create(realm, "")); // FIXME: Create HashChangeEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "htmlevents"sv)) {
@ -1312,7 +1312,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
event = TRY(Event::create(realm, "")); // FIXME: Create TouchEvent
} else if (Infra::is_ascii_case_insensitive_match(interface, "uievent"sv)
|| Infra::is_ascii_case_insensitive_match(interface, "uievents"sv)) {
event = UIEvents::UIEvent::create(realm, "");
event = TRY(UIEvents::UIEvent::create(realm, ""));
}
// 3. If constructor is null, then throw a "NotSupportedError" DOMException.

View File

@ -65,9 +65,9 @@ static void run_focus_update_steps(Vector<JS::Handle<DOM::Node>> old_chain, Vect
// with related blur target as the related target.
if (blur_event_target) {
// FIXME: Implement the "fire a focus event" spec operation.
auto blur_event = UIEvents::FocusEvent::create(blur_event_target->realm(), HTML::EventNames::blur);
auto blur_event = UIEvents::FocusEvent::create(blur_event_target->realm(), HTML::EventNames::blur).release_value_but_fixme_should_propagate_errors();
blur_event->set_related_target(related_blur_target);
blur_event_target->dispatch_event(*blur_event);
blur_event_target->dispatch_event(blur_event);
}
}
@ -108,9 +108,9 @@ static void run_focus_update_steps(Vector<JS::Handle<DOM::Node>> old_chain, Vect
// with related focus target as the related target.
if (focus_event_target) {
// FIXME: Implement the "fire a focus event" spec operation.
auto focus_event = UIEvents::FocusEvent::create(focus_event_target->realm(), HTML::EventNames::focus);
auto focus_event = UIEvents::FocusEvent::create(focus_event_target->realm(), HTML::EventNames::focus).release_value_but_fixme_should_propagate_errors();
focus_event->set_related_target(related_focus_target);
focus_event_target->dispatch_event(*focus_event);
focus_event_target->dispatch_event(focus_event);
}
}
}

View File

@ -9,14 +9,14 @@
namespace Web::UIEvents {
UIEvent* UIEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name)
WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> UIEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name)
{
return realm.heap().allocate<UIEvent>(realm, realm, event_name).release_allocated_value_but_fixme_should_propagate_errors();
return MUST_OR_THROW_OOM(realm.heap().allocate<UIEvent>(realm, realm, event_name));
}
UIEvent* UIEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, UIEventInit const& event_init)
WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> UIEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, UIEventInit const& event_init)
{
return realm.heap().allocate<UIEvent>(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors();
return MUST_OR_THROW_OOM(realm.heap().allocate<UIEvent>(realm, realm, event_name, event_init));
}
UIEvent::UIEvent(JS::Realm& realm, DeprecatedFlyString const& event_name)

View File

@ -21,8 +21,8 @@ class UIEvent : public DOM::Event {
WEB_PLATFORM_OBJECT(UIEvent, DOM::Event);
public:
static UIEvent* create(JS::Realm&, DeprecatedFlyString const& type);
static UIEvent* construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, UIEventInit const& event_init);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> create(JS::Realm&, DeprecatedFlyString const& type);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<UIEvent>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, UIEventInit const& event_init);
virtual ~UIEvent() override;