1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibWeb: Make factory methods of DOM::Event fallible

Because of interdependencies between DOM::Event and UIEvents::MouseEvent
to template function fire_an_event() in WebDriverConnection.cpp, the
commit: 'LibWeb: Make factory methods of UIEvents::MouseEvent fallible'
have been squashed into this commit.
This commit is contained in:
Kenneth Myhra 2023-02-14 22:43:17 +01:00 committed by Linus Groh
parent 0d9076c9f5
commit c120c46acc
20 changed files with 85 additions and 85 deletions

View file

@ -62,7 +62,7 @@ void AbortSignal::signal_abort(JS::Value reason)
m_abort_algorithms.clear(); m_abort_algorithms.clear();
// 5. Fire an event named abort at signal. // 5. Fire an event named abort at signal.
dispatch_event(*Event::create(realm(), HTML::EventNames::abort)); dispatch_event(Event::create(realm(), HTML::EventNames::abort).release_value_but_fixme_should_propagate_errors());
} }
void AbortSignal::set_onabort(WebIDL::CallbackType* event_handler) void AbortSignal::set_onabort(WebIDL::CallbackType* event_handler)

View file

@ -1006,7 +1006,7 @@ void Document::set_hovered_node(Node* node)
// FIXME: Check if we need to dispatch these events in a specific order. // FIXME: Check if we need to dispatch these events in a specific order.
for (auto target = old_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) { for (auto target = old_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) {
// FIXME: Populate the event with mouse coordinates, etc. // FIXME: Populate the event with mouse coordinates, etc.
target->dispatch_event(*UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseleave)); target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseleave).release_value_but_fixme_should_propagate_errors());
} }
} }
@ -1015,7 +1015,7 @@ void Document::set_hovered_node(Node* node)
// FIXME: Check if we need to dispatch these events in a specific order. // FIXME: Check if we need to dispatch these events in a specific order.
for (auto target = m_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) { for (auto target = m_hovered_node; target && target.ptr() != common_ancestor; target = target->parent()) {
// FIXME: Populate the event with mouse coordinates, etc. // FIXME: Populate the event with mouse coordinates, etc.
target->dispatch_event(*UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter)); target->dispatch_event(UIEvents::MouseEvent::create(realm(), UIEvents::EventNames::mouseenter).release_value_but_fixme_should_propagate_errors());
} }
} }
} }
@ -1272,39 +1272,39 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Document::create_event(DeprecatedSt
// then set constructor to the interface in the second column on the same row as the matching string: // then set constructor to the interface in the second column on the same row as the matching string:
auto interface_lowercase = interface.to_lowercase(); auto interface_lowercase = interface.to_lowercase();
if (interface_lowercase == "beforeunloadevent") { if (interface_lowercase == "beforeunloadevent") {
event = Event::create(realm, ""); // FIXME: Create BeforeUnloadEvent event = TRY(Event::create(realm, "")); // FIXME: Create BeforeUnloadEvent
} else if (interface_lowercase == "compositionevent") { } else if (interface_lowercase == "compositionevent") {
event = Event::create(realm, ""); // FIXME: Create CompositionEvent event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
} else if (interface_lowercase == "customevent") { } else if (interface_lowercase == "customevent") {
event = TRY(CustomEvent::create(realm, "")); event = TRY(CustomEvent::create(realm, ""));
} else if (interface_lowercase == "devicemotionevent") { } else if (interface_lowercase == "devicemotionevent") {
event = Event::create(realm, ""); // FIXME: Create DeviceMotionEvent event = TRY(Event::create(realm, "")); // FIXME: Create DeviceMotionEvent
} else if (interface_lowercase == "deviceorientationevent") { } else if (interface_lowercase == "deviceorientationevent") {
event = Event::create(realm, ""); // FIXME: Create DeviceOrientationEvent event = TRY(Event::create(realm, "")); // FIXME: Create DeviceOrientationEvent
} else if (interface_lowercase == "dragevent") { } else if (interface_lowercase == "dragevent") {
event = Event::create(realm, ""); // FIXME: Create DragEvent event = TRY(Event::create(realm, "")); // FIXME: Create DragEvent
} else if (interface_lowercase.is_one_of("event", "events")) { } else if (interface_lowercase.is_one_of("event", "events")) {
event = Event::create(realm, ""); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "focusevent") { } else if (interface_lowercase == "focusevent") {
event = UIEvents::FocusEvent::create(realm, ""); event = UIEvents::FocusEvent::create(realm, "");
} else if (interface_lowercase == "hashchangeevent") { } else if (interface_lowercase == "hashchangeevent") {
event = Event::create(realm, ""); // FIXME: Create HashChangeEvent event = TRY(Event::create(realm, "")); // FIXME: Create HashChangeEvent
} else if (interface_lowercase == "htmlevents") { } else if (interface_lowercase == "htmlevents") {
event = Event::create(realm, ""); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "keyboardevent") { } else if (interface_lowercase == "keyboardevent") {
event = UIEvents::KeyboardEvent::create(realm, ""); event = UIEvents::KeyboardEvent::create(realm, "");
} else if (interface_lowercase == "messageevent") { } else if (interface_lowercase == "messageevent") {
event = TRY(HTML::MessageEvent::create(realm, "")); event = TRY(HTML::MessageEvent::create(realm, ""));
} else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) { } else if (interface_lowercase.is_one_of("mouseevent", "mouseevents")) {
event = UIEvents::MouseEvent::create(realm, ""); event = TRY(UIEvents::MouseEvent::create(realm, ""));
} else if (interface_lowercase == "storageevent") { } else if (interface_lowercase == "storageevent") {
event = Event::create(realm, ""); // FIXME: Create StorageEvent event = TRY(Event::create(realm, "")); // FIXME: Create StorageEvent
} else if (interface_lowercase == "svgevents") { } else if (interface_lowercase == "svgevents") {
event = Event::create(realm, ""); event = TRY(Event::create(realm, ""));
} else if (interface_lowercase == "textevent") { } else if (interface_lowercase == "textevent") {
event = Event::create(realm, ""); // FIXME: Create CompositionEvent event = TRY(Event::create(realm, "")); // FIXME: Create CompositionEvent
} else if (interface_lowercase == "touchevent") { } else if (interface_lowercase == "touchevent") {
event = Event::create(realm, ""); // FIXME: Create TouchEvent event = TRY(Event::create(realm, "")); // FIXME: Create TouchEvent
} else if (interface_lowercase.is_one_of("uievent", "uievents")) { } else if (interface_lowercase.is_one_of("uievent", "uievents")) {
event = UIEvents::UIEvent::create(realm, ""); event = UIEvents::UIEvent::create(realm, "");
} }
@ -1539,7 +1539,7 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
} }
// 4. Fire an event named readystatechange at document. // 4. Fire an event named readystatechange at document.
dispatch_event(*Event::create(realm(), HTML::EventNames::readystatechange)); dispatch_event(Event::create(realm(), HTML::EventNames::readystatechange).release_value_but_fixme_should_propagate_errors());
} }
Page* Document::page() Page* Document::page()
@ -1587,7 +1587,7 @@ void Document::completely_finish_loading()
// 5. Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source given container to fire an event named load at container. // 5. Otherwise, if container is non-null, then queue an element task on the DOM manipulation task source given container to fire an event named load at container.
else if (container) { else if (container) {
container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container] { container->queue_an_element_task(HTML::Task::Source::DOMManipulation, [container] {
container->dispatch_event(*DOM::Event::create(container->realm(), HTML::EventNames::load)); container->dispatch_event(DOM::Event::create(container->realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
}); });
} }
} }
@ -1717,7 +1717,7 @@ void Document::update_the_visibility_state(HTML::VisibilityState visibility_stat
// FIXME: 3. Run any page visibility change steps which may be defined in other specifications, with visibility state and document. // FIXME: 3. Run any page visibility change steps which may be defined in other specifications, with visibility state and document.
// 4. Fire an event named visibilitychange at document, with its bubbles attribute initialized to true. // 4. Fire an event named visibilitychange at document, with its bubbles attribute initialized to true.
auto event = DOM::Event::create(realm(), HTML::EventNames::visibilitychange); auto event = DOM::Event::create(realm(), HTML::EventNames::visibilitychange).release_value_but_fixme_should_propagate_errors();
event->set_bubbles(true); event->set_bubbles(true);
dispatch_event(event); dispatch_event(event);
} }
@ -1738,7 +1738,7 @@ void Document::run_the_resize_steps()
return; return;
m_last_viewport_size = viewport_size; m_last_viewport_size = viewport_size;
window().dispatch_event(*DOM::Event::create(realm(), UIEvents::EventNames::resize)); window().dispatch_event(DOM::Event::create(realm(), UIEvents::EventNames::resize).release_value_but_fixme_should_propagate_errors());
schedule_layout_update(); schedule_layout_update();
} }
@ -1750,15 +1750,15 @@ void Document::run_the_scroll_steps()
for (auto& target : m_pending_scroll_event_targets) { for (auto& target : m_pending_scroll_event_targets) {
// 1. If target is a Document, fire an event named scroll that bubbles at target and fire an event named scroll at the VisualViewport that is associated with target. // 1. If target is a Document, fire an event named scroll that bubbles at target and fire an event named scroll at the VisualViewport that is associated with target.
if (is<Document>(*target)) { if (is<Document>(*target)) {
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll); auto event = DOM::Event::create(realm(), HTML::EventNames::scroll).release_value_but_fixme_should_propagate_errors();
event->set_bubbles(true); event->set_bubbles(true);
target->dispatch_event(*event); target->dispatch_event(event);
// FIXME: Fire at the associated VisualViewport // FIXME: Fire at the associated VisualViewport
} }
// 2. Otherwise, fire an event named scroll at target. // 2. Otherwise, fire an event named scroll at target.
else { else {
auto event = DOM::Event::create(realm(), HTML::EventNames::scroll); auto event = DOM::Event::create(realm(), HTML::EventNames::scroll).release_value_but_fixme_should_propagate_errors();
target->dispatch_event(*event); target->dispatch_event(event);
} }
} }
@ -1797,7 +1797,7 @@ void Document::evaluate_media_queries_and_report_changes()
CSS::MediaQueryListEventInit init; CSS::MediaQueryListEventInit init;
init.media = media_query_list->media(); init.media = media_query_list->media();
init.matches = now_matches; init.matches = now_matches;
auto event = CSS::MediaQueryListEvent::create(realm(), HTML::EventNames::change, init); auto event = CSS::MediaQueryListEvent::create(realm(), HTML::EventNames::change, init).release_value_but_fixme_should_propagate_errors();
event->set_is_trusted(true); event->set_is_trusted(true);
media_query_list->dispatch_event(*event); media_query_list->dispatch_event(*event);
} }
@ -2259,7 +2259,7 @@ void Document::unload(bool recursive_flag, Optional<DocumentUnloadTimingInfo> un
// then fire an event named unload at document's relevant global object, with legacy target override flag set. // then fire an event named unload at document's relevant global object, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event() // FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
// We should reorganize this so that the flag appears explicitly here instead. // We should reorganize this so that the flag appears explicitly here instead.
auto event = DOM::Event::create(realm(), HTML::EventNames::unload); auto event = DOM::Event::create(realm(), HTML::EventNames::unload).release_value_but_fixme_should_propagate_errors();
global_object().dispatch_event(event); global_object().dispatch_event(event);
} }

View file

@ -14,12 +14,12 @@
namespace Web::DOM { namespace Web::DOM {
JS::NonnullGCPtr<Event> Event::create(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init) WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::create(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init)
{ {
return realm.heap().allocate<Event>(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors(); return MUST_OR_THROW_OOM(realm.heap().allocate<Event>(realm, realm, event_name, event_init));
} }
JS::NonnullGCPtr<Event> Event::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init) WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> Event::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, EventInit const& event_init)
{ {
return create(realm, event_name, event_init); return create(realm, event_name, event_init);
} }

View file

@ -45,8 +45,8 @@ public:
using Path = Vector<PathEntry>; using Path = Vector<PathEntry>;
static JS::NonnullGCPtr<Event> create(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init = {}); static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> create(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init = {});
static JS::NonnullGCPtr<Event> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init); static WebIDL::ExceptionOr<JS::NonnullGCPtr<Event>> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, EventInit const& event_init);
Event(JS::Realm&, DeprecatedFlyString const& type); Event(JS::Realm&, DeprecatedFlyString const& type);
Event(JS::Realm&, DeprecatedFlyString const& type, EventInit const& event_init); Event(JS::Realm&, DeprecatedFlyString const& type, EventInit const& event_init);

View file

@ -1177,7 +1177,7 @@ WebIDL::ExceptionOr<void> BrowsingContext::traverse_the_history(size_t entry_ind
// and the newURL attribute initialized to newURL. // and the newURL attribute initialized to newURL.
// FIXME: Implement a proper HashChangeEvent class. // FIXME: Implement a proper HashChangeEvent class.
auto event = DOM::Event::create(verify_cast<HTML::Window>(relevant_global_object(*new_document)).realm(), HTML::EventNames::hashchange); auto event = DOM::Event::create(verify_cast<HTML::Window>(relevant_global_object(*new_document)).realm(), HTML::EventNames::hashchange).release_value_but_fixme_should_propagate_errors();
new_document->dispatch_event(event); new_document->dispatch_event(event);
}); });
} }

View file

@ -278,7 +278,7 @@ bool HTMLElement::fire_a_synthetic_pointer_event(DeprecatedFlyString const& type
// 1. Let event be the result of creating an event using PointerEvent. // 1. Let event be the result of creating an event using PointerEvent.
// 2. Initialize event's type attribute to e. // 2. Initialize event's type attribute to e.
// FIXME: Actually create a PointerEvent! // FIXME: Actually create a PointerEvent!
auto event = UIEvents::MouseEvent::create(realm(), type); auto event = UIEvents::MouseEvent::create(realm(), type).release_value_but_fixme_should_propagate_errors();
// 3. Initialize event's bubbles and cancelable attributes to true. // 3. Initialize event's bubbles and cancelable attributes to true.
event->set_bubbles(true); event->set_bubbles(true);
@ -300,7 +300,7 @@ bool HTMLElement::fire_a_synthetic_pointer_event(DeprecatedFlyString const& type
// FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device. // FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device.
// 9. Return the result of dispatching event at target. // 9. Return the result of dispatching event at target.
return target.dispatch_event(*event); return target.dispatch_event(event);
} }
// https://html.spec.whatwg.org/multipage/interaction.html#dom-click // https://html.spec.whatwg.org/multipage/interaction.html#dom-click

View file

@ -149,11 +149,11 @@ void HTMLFormElement::submit_form(JS::GCPtr<HTMLElement> submitter, bool from_su
void HTMLFormElement::reset_form() void HTMLFormElement::reset_form()
{ {
// 1. Let reset be the result of firing an event named reset at form, with the bubbles and cancelable attributes initialized to true. // 1. Let reset be the result of firing an event named reset at form, with the bubbles and cancelable attributes initialized to true.
auto reset_event = DOM::Event::create(realm(), HTML::EventNames::reset); auto reset_event = DOM::Event::create(realm(), HTML::EventNames::reset).release_value_but_fixme_should_propagate_errors();
reset_event->set_bubbles(true); reset_event->set_bubbles(true);
reset_event->set_cancelable(true); reset_event->set_cancelable(true);
bool reset = dispatch_event(*reset_event); bool reset = dispatch_event(reset_event);
// 2. If reset is true, then invoke the reset algorithm of each resettable element whose form owner is form. // 2. If reset is true, then invoke the reset algorithm of each resettable element whose form owner is form.
if (reset) { if (reset) {

View file

@ -165,7 +165,7 @@ void run_iframe_load_event_steps(HTML::HTMLIFrameElement& element)
// FIXME: 4. Set childDocument's iframe load in progress flag. // FIXME: 4. Set childDocument's iframe load in progress flag.
// 5. Fire an event named load at element. // 5. Fire an event named load at element.
element.dispatch_event(*DOM::Event::create(element.realm(), HTML::EventNames::load)); element.dispatch_event(DOM::Event::create(element.realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
// FIXME: 6. Unset childDocument's iframe load in progress flag. // FIXME: 6. Unset childDocument's iframe load in progress flag.
} }

View file

@ -27,7 +27,7 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q
set_needs_style_update(true); set_needs_style_update(true);
this->document().set_needs_layout(); this->document().set_needs_layout();
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(this->realm(), EventNames::load)); dispatch_event(DOM::Event::create(this->realm(), EventNames::load).release_value_but_fixme_should_propagate_errors());
}); });
}; };
@ -36,7 +36,7 @@ HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName q
set_needs_style_update(true); set_needs_style_update(true);
this->document().set_needs_layout(); this->document().set_needs_layout();
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(this->realm(), EventNames::error)); dispatch_event(DOM::Event::create(this->realm(), EventNames::error).release_value_but_fixme_should_propagate_errors());
}); });
}; };

View file

@ -134,12 +134,12 @@ void HTMLInputElement::update_the_file_selection(JS::NonnullGCPtr<FileAPI::FileL
this->set_files(files.ptr()); this->set_files(files.ptr());
// 2. Fire an event named input at the input element, with the bubbles and composed attributes initialized to true. // 2. Fire an event named input at the input element, with the bubbles and composed attributes initialized to true.
auto input_event = DOM::Event::create(this->realm(), EventNames::input, { .bubbles = true, .composed = true }); auto input_event = DOM::Event::create(this->realm(), EventNames::input, { .bubbles = true, .composed = true }).release_value_but_fixme_should_propagate_errors();
this->dispatch_event(*input_event); this->dispatch_event(input_event);
// 3. Fire an event named change at the input element, with the bubbles attribute initialized to true. // 3. Fire an event named change at the input element, with the bubbles attribute initialized to true.
auto change_event = DOM::Event::create(this->realm(), EventNames::change, { .bubbles = true }); auto change_event = DOM::Event::create(this->realm(), EventNames::change, { .bubbles = true }).release_value_but_fixme_should_propagate_errors();
this->dispatch_event(*change_event); this->dispatch_event(change_event);
}); });
} }
@ -225,13 +225,13 @@ void HTMLInputElement::run_input_activation_behavior()
return; return;
// 2. Fire an event named input at the element with the bubbles and composed attributes initialized to true. // 2. Fire an event named input at the element with the bubbles and composed attributes initialized to true.
auto input_event = DOM::Event::create(realm(), HTML::EventNames::input); auto input_event = DOM::Event::create(realm(), HTML::EventNames::input).release_value_but_fixme_should_propagate_errors();
input_event->set_bubbles(true); input_event->set_bubbles(true);
input_event->set_composed(true); input_event->set_composed(true);
dispatch_event(*input_event); dispatch_event(input_event);
// 3. Fire an event named change at the element with the bubbles attribute initialized to true. // 3. Fire an event named change at the element with the bubbles attribute initialized to true.
auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); auto change_event = DOM::Event::create(realm(), HTML::EventNames::change).release_value_but_fixme_should_propagate_errors();
change_event->set_bubbles(true); change_event->set_bubbles(true);
dispatch_event(*change_event); dispatch_event(*change_event);
} else if (type_state() == TypeAttributeState::SubmitButton) { } else if (type_state() == TypeAttributeState::SubmitButton) {
@ -249,7 +249,7 @@ void HTMLInputElement::run_input_activation_behavior()
} else if (type_state() == TypeAttributeState::FileUpload) { } else if (type_state() == TypeAttributeState::FileUpload) {
show_the_picker_if_applicable(*this); show_the_picker_if_applicable(*this);
} else { } else {
dispatch_event(*DOM::Event::create(realm(), EventNames::change)); dispatch_event(DOM::Event::create(realm(), EventNames::change).release_value_but_fixme_should_propagate_errors());
} }
} }
@ -262,15 +262,15 @@ void HTMLInputElement::did_edit_text_node(Badge<BrowsingContext>)
// NOTE: This is a bit ad-hoc, but basically implements part of "4.10.5.5 Common event behaviors" // NOTE: This is a bit ad-hoc, but basically implements part of "4.10.5.5 Common event behaviors"
// https://html.spec.whatwg.org/multipage/input.html#common-input-element-events // https://html.spec.whatwg.org/multipage/input.html#common-input-element-events
queue_an_element_task(HTML::Task::Source::UserInteraction, [this] { queue_an_element_task(HTML::Task::Source::UserInteraction, [this] {
auto input_event = DOM::Event::create(realm(), HTML::EventNames::input); auto input_event = DOM::Event::create(realm(), HTML::EventNames::input).release_value_but_fixme_should_propagate_errors();
input_event->set_bubbles(true); input_event->set_bubbles(true);
input_event->set_composed(true); input_event->set_composed(true);
dispatch_event(*input_event); dispatch_event(*input_event);
// FIXME: This should only fire when the input is "committed", whatever that means. // FIXME: This should only fire when the input is "committed", whatever that means.
auto change_event = DOM::Event::create(realm(), HTML::EventNames::change); auto change_event = DOM::Event::create(realm(), HTML::EventNames::change).release_value_but_fixme_should_propagate_errors();
change_event->set_bubbles(true); change_event->set_bubbles(true);
dispatch_event(*change_event); dispatch_event(change_event);
}); });
} }

View file

@ -124,7 +124,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
// 3. If that failed, fire an event named error at the element, then jump to the step below labeled fallback. // 3. If that failed, fire an event named error at the element, then jump to the step below labeled fallback.
if (!url.is_valid()) { if (!url.is_valid()) {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
return run_object_representation_fallback_steps(); return run_object_representation_fallback_steps();
} }
@ -151,7 +151,7 @@ void HTMLObjectElement::queue_element_task_to_run_object_representation_steps()
void HTMLObjectElement::resource_did_fail() void HTMLObjectElement::resource_did_fail()
{ {
// 4.7. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire an event named error at the element, then jump to the step below labeled fallback. // 4.7. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire an event named error at the element, then jump to the step below labeled fallback.
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
run_object_representation_fallback_steps(); run_object_representation_fallback_steps();
} }
@ -289,7 +289,7 @@ void HTMLObjectElement::run_object_representation_completed_steps(Representation
// 4.11. If the object element does not represent its nested browsing context, then once the resource is completely loaded, queue an element task on the DOM manipulation task source given the object element to fire an event named load at the element. // 4.11. If the object element does not represent its nested browsing context, then once the resource is completely loaded, queue an element task on the DOM manipulation task source given the object element to fire an event named load at the element.
if (representation != Representation::NestedBrowsingContext) { if (representation != Representation::NestedBrowsingContext) {
queue_an_element_task(HTML::Task::Source::DOMManipulation, [&]() { queue_an_element_task(HTML::Task::Source::DOMManipulation, [&]() {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
}); });
} }

View file

@ -71,7 +71,7 @@ void HTMLScriptElement::execute_script()
// 3. If el's result is null, then fire an event named error at el, and return. // 3. If el's result is null, then fire an event named error at el, and return.
if (m_result.has<ResultState::Null>()) { if (m_result.has<ResultState::Null>()) {
dbgln("HTMLScriptElement: Refusing to run script because the element's result is null."); dbgln("HTMLScriptElement: Refusing to run script because the element's result is null.");
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
return; return;
} }
@ -122,7 +122,7 @@ void HTMLScriptElement::execute_script()
// 8. If el's from an external file is true, then fire an event named load at el. // 8. If el's from an external file is true, then fire an event named load at el.
if (m_from_an_external_file) if (m_from_an_external_file)
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
} }
// https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script // https://html.spec.whatwg.org/multipage/scripting.html#prepare-a-script
@ -292,7 +292,7 @@ void HTMLScriptElement::prepare_script()
if (m_script_type == ScriptType::ImportMap) { if (m_script_type == ScriptType::ImportMap) {
// then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return. // then queue an element task on the DOM manipulation task source given el to fire an event named error at el, and return.
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
}); });
return; return;
} }
@ -304,7 +304,7 @@ void HTMLScriptElement::prepare_script()
if (src.is_empty()) { if (src.is_empty()) {
dbgln("HTMLScriptElement: Refusing to run script because the src attribute is empty."); dbgln("HTMLScriptElement: Refusing to run script because the src attribute is empty.");
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
}); });
return; return;
} }
@ -319,7 +319,7 @@ void HTMLScriptElement::prepare_script()
if (!url.is_valid()) { if (!url.is_valid()) {
dbgln("HTMLScriptElement: Refusing to run script because the src URL '{}' is invalid.", url); dbgln("HTMLScriptElement: Refusing to run script because the src URL '{}' is invalid.", url);
queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] { queue_an_element_task(HTML::Task::Source::DOMManipulation, [this] {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
}); });
return; return;
} }

View file

@ -253,9 +253,9 @@ void HTMLParser::the_end()
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time(); document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true. // 2. Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded); auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded).release_value_but_fixme_should_propagate_errors();
content_loaded_event->set_bubbles(true); content_loaded_event->set_bubbles(true);
document->dispatch_event(*content_loaded_event); document->dispatch_event(content_loaded_event);
// 3. Set the Document's load timing info's DOM content loaded event end time to the current high resolution time given the Document's relevant global object. // 3. Set the Document's load timing info's DOM content loaded event end time to the current high resolution time given the Document's relevant global object.
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time(); document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
@ -294,7 +294,7 @@ void HTMLParser::the_end()
// 5. Fire an event named load at window, with legacy target override flag set. // 5. Fire an event named load at window, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event() // FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
// We should reorganize this so that the flag appears explicitly here instead. // We should reorganize this so that the flag appears explicitly here instead.
window->dispatch_event(*DOM::Event::create(document->realm(), HTML::EventNames::load)); window->dispatch_event(DOM::Event::create(document->realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
// FIXME: 6. Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL. // FIXME: 6. Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL.

View file

@ -249,12 +249,12 @@ bool EventHandler::handle_mouseup(CSSPixelPoint position, unsigned button, unsig
auto offset = compute_mouse_event_offset(position, *layout_node); auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position); auto client_offset = compute_mouse_event_client_offset(position);
auto page_offset = compute_mouse_event_page_offset(client_offset); auto page_offset = compute_mouse_event_page_offset(client_offset);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mouseup, offset, client_offset, page_offset, buttons, button)); node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mouseup, offset, client_offset, page_offset, buttons, button).release_value_but_fixme_should_propagate_errors());
handled_event = true; handled_event = true;
bool run_activation_behavior = true; bool run_activation_behavior = true;
if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) { if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) {
run_activation_behavior = node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset, client_offset, page_offset, button)); run_activation_behavior = node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::click, offset, client_offset, page_offset, button).release_value_but_fixme_should_propagate_errors());
} }
if (run_activation_behavior) { if (run_activation_behavior) {
@ -372,7 +372,7 @@ bool EventHandler::handle_mousedown(CSSPixelPoint position, unsigned button, uns
auto offset = compute_mouse_event_offset(position, *layout_node); auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position); auto client_offset = compute_mouse_event_client_offset(position);
auto page_offset = compute_mouse_event_page_offset(client_offset); auto page_offset = compute_mouse_event_page_offset(client_offset);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousedown, offset, client_offset, page_offset, buttons, button)); node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousedown, offset, client_offset, page_offset, buttons, button).release_value_but_fixme_should_propagate_errors());
} }
// NOTE: Dispatching an event may have disturbed the world. // NOTE: Dispatching an event may have disturbed the world.
@ -488,7 +488,7 @@ bool EventHandler::handle_mousemove(CSSPixelPoint position, unsigned buttons, un
auto offset = compute_mouse_event_offset(position, *layout_node); auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position); auto client_offset = compute_mouse_event_client_offset(position);
auto page_offset = compute_mouse_event_page_offset(client_offset); auto page_offset = compute_mouse_event_page_offset(client_offset);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset, client_offset, page_offset, buttons)); node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::mousemove, offset, client_offset, page_offset, buttons).release_value_but_fixme_should_propagate_errors());
// NOTE: Dispatching an event may have disturbed the world. // NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box()) if (!paint_root() || paint_root() != node->document().paint_box())
return true; return true;
@ -577,7 +577,7 @@ bool EventHandler::handle_doubleclick(CSSPixelPoint position, unsigned button, u
auto offset = compute_mouse_event_offset(position, *layout_node); auto offset = compute_mouse_event_offset(position, *layout_node);
auto client_offset = compute_mouse_event_client_offset(position); auto client_offset = compute_mouse_event_client_offset(position);
auto page_offset = compute_mouse_event_page_offset(client_offset); auto page_offset = compute_mouse_event_page_offset(client_offset);
node->dispatch_event(*UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::dblclick, offset, client_offset, page_offset, buttons, button)); node->dispatch_event(UIEvents::MouseEvent::create_from_platform_event(node->realm(), UIEvents::EventNames::dblclick, offset, client_offset, page_offset, buttons, button).release_value_but_fixme_should_propagate_errors());
// NOTE: Dispatching an event may have disturbed the world. // NOTE: Dispatching an event may have disturbed the world.
if (!paint_root() || paint_root() != node->document().paint_box()) if (!paint_root() || paint_root() != node->document().paint_box())

View file

@ -56,12 +56,12 @@ static i16 determine_button(unsigned mouse_button)
} }
} }
MouseEvent* MouseEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, MouseEventInit const& event_init) WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, MouseEventInit const& event_init)
{ {
return realm.heap().allocate<MouseEvent>(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors(); return MUST_OR_THROW_OOM(realm.heap().allocate<MouseEvent>(realm, realm, event_name, event_init));
} }
MouseEvent* MouseEvent::create_from_platform_event(JS::Realm& realm, DeprecatedFlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button) WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> MouseEvent::create_from_platform_event(JS::Realm& realm, DeprecatedFlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button)
{ {
MouseEventInit event_init {}; MouseEventInit event_init {};
event_init.offset_x = static_cast<double>(offset.x().value()); event_init.offset_x = static_cast<double>(offset.x().value());

View file

@ -29,8 +29,8 @@ class MouseEvent : public UIEvent {
WEB_PLATFORM_OBJECT(MouseEvent, UIEvent); WEB_PLATFORM_OBJECT(MouseEvent, UIEvent);
public: public:
static MouseEvent* create(JS::Realm&, DeprecatedFlyString const& event_name, MouseEventInit const& event_init = {}); static WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> create(JS::Realm&, DeprecatedFlyString const& event_name, MouseEventInit const& event_init = {});
static MouseEvent* create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button = 1); static WebIDL::ExceptionOr<JS::NonnullGCPtr<MouseEvent>> create_from_platform_event(JS::Realm&, DeprecatedFlyString const& event_name, CSSPixelPoint offset, CSSPixelPoint client_offset, CSSPixelPoint page_offset, unsigned buttons, unsigned mouse_button = 1);
virtual ~MouseEvent() override; virtual ~MouseEvent() override;

View file

@ -204,13 +204,13 @@ void WebSocket::on_open()
// 1. Change the readyState attribute's value to OPEN (1). // 1. Change the readyState attribute's value to OPEN (1).
// 2. Change the extensions attribute's value to the extensions in use, if it is not the null value. [WSP] // 2. Change the extensions attribute's value to the extensions in use, if it is not the null value. [WSP]
// 3. Change the protocol attribute's value to the subprotocol in use, if it is not the null value. [WSP] // 3. Change the protocol attribute's value to the subprotocol in use, if it is not the null value. [WSP]
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::open)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::open).release_value_but_fixme_should_propagate_errors());
} }
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol // https://websockets.spec.whatwg.org/#feedback-from-the-protocol
void WebSocket::on_error() void WebSocket::on_error()
{ {
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
} }
// https://websockets.spec.whatwg.org/#feedback-from-the-protocol // https://websockets.spec.whatwg.org/#feedback-from-the-protocol

View file

@ -419,7 +419,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(DeprecatedString const& method_st
m_state = State::Opened; m_state = State::Opened;
// 2. Fire an event named readystatechange at this. // 2. Fire an event named readystatechange at this.
dispatch_event(*DOM::Event::create(realm(), EventNames::readystatechange)); dispatch_event(TRY(DOM::Event::create(realm(), EventNames::readystatechange)));
} }
return {}; return {};
@ -463,8 +463,8 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
if (should_enforce_same_origin_policy && !m_window->associated_document().origin().is_same_origin(request_url_origin)) { if (should_enforce_same_origin_policy && !m_window->associated_document().origin().is_same_origin(request_url_origin)) {
dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->associated_document().url(), request_url); dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->associated_document().url(), request_url);
m_state = State::Done; m_state = State::Done;
dispatch_event(*DOM::Event::create(realm, EventNames::readystatechange)); dispatch_event(TRY(DOM::Event::create(realm, EventNames::readystatechange)));
dispatch_event(*DOM::Event::create(realm, HTML::EventNames::error)); dispatch_event(TRY(DOM::Event::create(realm, HTML::EventNames::error)));
return {}; return {};
} }
@ -544,7 +544,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
xhr.m_status = status_code.value_or(0); xhr.m_status = status_code.value_or(0);
xhr.m_response_headers = move(response_headers); xhr.m_response_headers = move(response_headers);
xhr.m_send = false; xhr.m_send = false;
xhr.dispatch_event(*DOM::Event::create(xhr.realm(), EventNames::readystatechange)); xhr.dispatch_event(DOM::Event::create(xhr.realm(), EventNames::readystatechange).release_value_but_fixme_should_propagate_errors());
xhr.fire_progress_event(EventNames::load, transmitted, length); xhr.fire_progress_event(EventNames::load, transmitted, length);
xhr.fire_progress_event(EventNames::loadend, transmitted, length); xhr.fire_progress_event(EventNames::loadend, transmitted, length);
}, },
@ -556,8 +556,8 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
auto& xhr = const_cast<XMLHttpRequest&>(*strong_this); auto& xhr = const_cast<XMLHttpRequest&>(*strong_this);
xhr.m_state = State::Done; xhr.m_state = State::Done;
xhr.set_status(status_code.value_or(0)); xhr.set_status(status_code.value_or(0));
xhr.dispatch_event(*DOM::Event::create(xhr.realm(), EventNames::readystatechange)); xhr.dispatch_event(DOM::Event::create(xhr.realm(), EventNames::readystatechange).release_value_but_fixme_should_propagate_errors());
xhr.dispatch_event(*DOM::Event::create(xhr.realm(), HTML::EventNames::error)); xhr.dispatch_event(DOM::Event::create(xhr.realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
}, },
m_timeout, m_timeout,
[weak_this = make_weak_ptr<XMLHttpRequest>()] { [weak_this = make_weak_ptr<XMLHttpRequest>()] {
@ -565,7 +565,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
if (!strong_this) if (!strong_this)
return; return;
auto& xhr = const_cast<XMLHttpRequest&>(*strong_this); auto& xhr = const_cast<XMLHttpRequest&>(*strong_this);
xhr.dispatch_event(*DOM::Event::create(xhr.realm(), EventNames::timeout)); xhr.dispatch_event(DOM::Event::create(xhr.realm(), EventNames::timeout).release_value_but_fixme_should_propagate_errors());
}); });
} else { } else {
TODO(); TODO();

View file

@ -189,9 +189,9 @@ void XMLDocumentBuilder::document_end()
document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time(); document->load_timing_info().dom_content_loaded_event_start_time = HighResolutionTime::unsafe_shared_current_time();
// Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true. // Fire an event named DOMContentLoaded at the Document object, with its bubbles attribute initialized to true.
auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded); auto content_loaded_event = DOM::Event::create(document->realm(), HTML::EventNames::DOMContentLoaded).release_value_but_fixme_should_propagate_errors();
content_loaded_event->set_bubbles(true); content_loaded_event->set_bubbles(true);
document->dispatch_event(*content_loaded_event); document->dispatch_event(content_loaded_event);
// Set the Document's load timing info's DOM content loaded event end time to the current high resolution time given the Document's relevant global object. // Set the Document's load timing info's DOM content loaded event end time to the current high resolution time given the Document's relevant global object.
document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time(); document->load_timing_info().dom_content_loaded_event_end_time = HighResolutionTime::unsafe_shared_current_time();
@ -229,7 +229,7 @@ void XMLDocumentBuilder::document_end()
// Fire an event named load at window, with legacy target override flag set. // Fire an event named load at window, with legacy target override flag set.
// FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event() // FIXME: The legacy target override flag is currently set by a virtual override of dispatch_event()
// We should reorganize this so that the flag appears explicitly here instead. // We should reorganize this so that the flag appears explicitly here instead.
window->dispatch_event(*DOM::Event::create(document->realm(), HTML::EventNames::load)); window->dispatch_event(DOM::Event::create(document->realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
// FIXME: Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL. // FIXME: Invoke WebDriver BiDi load complete with the Document's browsing context, and a new WebDriver BiDi navigation status whose id is the Document object's navigation id, status is "complete", and url is the Document object's URL.

View file

@ -314,8 +314,8 @@ static bool fire_an_event(DeprecatedString name, Optional<Web::DOM::Element&> ta
if (!target.has_value()) if (!target.has_value())
return false; return false;
auto event = T::create(target->realm(), name); auto event = T::create(target->realm(), name).release_value_but_fixme_should_propagate_errors();
return target->dispatch_event(*event); return target->dispatch_event(event);
} }
ErrorOr<NonnullRefPtr<WebDriverConnection>> WebDriverConnection::connect(Web::PageClient& page_client, DeprecatedString const& webdriver_ipc_path) ErrorOr<NonnullRefPtr<WebDriverConnection>> WebDriverConnection::connect(Web::PageClient& page_client, DeprecatedString const& webdriver_ipc_path)