From 3941e64fdedbd12079b2c8e60441b5adaaf50731 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Wed, 15 Feb 2023 19:30:27 +0100 Subject: [PATCH] LibWeb: Make factory method of HTML::PromiseRejectionEvent fallible --- Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp | 6 +++--- Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h | 4 ++-- Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index d6fd5a3e42..8f4b5b236c 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -138,8 +138,8 @@ JS::VM& main_thread_vm() /* .promise = */ promise, /* .reason = */ promise.result(), }; - auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init); - window.dispatch_event(*promise_rejection_event); + auto promise_rejection_event = HTML::PromiseRejectionEvent::create(HTML::relevant_realm(global), HTML::EventNames::rejectionhandled, event_init).release_value_but_fixme_should_propagate_errors(); + window.dispatch_event(promise_rejection_event); }); break; } diff --git a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp index fe9db95293..7ce8f15545 100644 --- a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp +++ b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.cpp @@ -9,12 +9,12 @@ namespace Web::HTML { -PromiseRejectionEvent* PromiseRejectionEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init) +WebIDL::ExceptionOr> PromiseRejectionEvent::create(JS::Realm& realm, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init) { - return realm.heap().allocate(realm, realm, event_name, event_init).release_allocated_value_but_fixme_should_propagate_errors(); + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, realm, event_name, event_init)); } -PromiseRejectionEvent* PromiseRejectionEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init) +WebIDL::ExceptionOr> PromiseRejectionEvent::construct_impl(JS::Realm& realm, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init) { return create(realm, event_name, event_init); } diff --git a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h index 3cd0ef2f1c..ec295b879c 100644 --- a/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h +++ b/Userland/Libraries/LibWeb/HTML/PromiseRejectionEvent.h @@ -23,8 +23,8 @@ class PromiseRejectionEvent final : public DOM::Event { WEB_PLATFORM_OBJECT(PromiseRejectionEvent, DOM::Event); public: - static PromiseRejectionEvent* create(JS::Realm&, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init = {}); - static PromiseRejectionEvent* construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init); + static WebIDL::ExceptionOr> create(JS::Realm&, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, DeprecatedFlyString const& event_name, PromiseRejectionEventInit const& event_init); virtual ~PromiseRejectionEvent() override; diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 40e6c46222..17c2b89079 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -251,7 +251,7 @@ void EnvironmentSettingsObject::notify_about_rejected_promises(Badge) // FIXME: This currently assumes that global is a WindowObject. auto& window = verify_cast(global); - auto promise_rejection_event = PromiseRejectionEvent::create(window.realm(), HTML::EventNames::unhandledrejection, event_init); + auto promise_rejection_event = PromiseRejectionEvent::create(window.realm(), HTML::EventNames::unhandledrejection, event_init).release_value_but_fixme_should_propagate_errors(); bool not_handled = window.dispatch_event(*promise_rejection_event);