LibCore: Remove macro-generated EventReceiver::try_create(...) factories

We can just use the infallible factory everywhere instead.
This commit is contained in:
Andreas Kling 2025-08-11 12:29:33 +02:00 committed by Andreas Kling
commit bd7599ccfc
Notes: github-actions[bot] 2025-08-11 14:56:51 +00:00
9 changed files with 18 additions and 23 deletions

View file

@ -19,21 +19,16 @@
namespace Core {
#define C_OBJECT(klass) \
public: \
virtual StringView class_name() const override \
{ \
return #klass##sv; \
} \
template<typename Klass = klass, class... Args> \
static NonnullRefPtr<klass> construct(Args&&... args) \
{ \
return adopt_ref(*new Klass(::forward<Args>(args)...)); \
} \
template<typename Klass = klass, class... Args> \
static ErrorOr<NonnullRefPtr<klass>> try_create(Args&&... args) \
{ \
return adopt_nonnull_ref_or_enomem(new (nothrow) Klass(::forward<Args>(args)...)); \
#define C_OBJECT(klass) \
public: \
virtual StringView class_name() const override \
{ \
return #klass##sv; \
} \
template<typename Klass = klass, class... Args> \
static NonnullRefPtr<klass> construct(Args&&... args) \
{ \
return adopt_ref(*new Klass(::forward<Args>(args)...)); \
}
#define C_OBJECT_ABSTRACT(klass) \

View file

@ -99,7 +99,7 @@ ErrorOr<NonnullRefPtr<FileWatcher>> FileWatcher::create(FileWatcherFlags flags)
if (watcher_fd < 0)
return Error::from_errno(errno);
auto notifier = TRY(Notifier::try_create(watcher_fd, Notifier::Type::Read));
auto notifier = Notifier::construct(watcher_fd, Notifier::Type::Read);
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcher(watcher_fd, move(notifier)));
}

View file

@ -65,7 +65,7 @@ public:
// NOTE: This isn't actually used on macOS, but is needed for FileWatcherBase.
// Creating it with an FD of -1 will effectively disable the notifier.
auto notifier = TRY(Notifier::try_create(-1, Notifier::Type::None));
auto notifier = Notifier::construct(-1, Notifier::Type::None);
return adopt_nonnull_ref_or_enomem(new (nothrow) FileWatcherMacOS(move(context), dispatch_queue, move(notifier)));
}

View file

@ -49,7 +49,7 @@ GC_DEFINE_ALLOCATOR(HTMLImageElement);
HTMLImageElement::HTMLImageElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: HTMLElement(document, move(qualified_name))
{
m_animation_timer = Core::Timer::try_create().release_value_but_fixme_should_propagate_errors();
m_animation_timer = Core::Timer::create();
m_animation_timer->on_timeout = [this] { animate(); };
document.register_viewport_client(*this);

View file

@ -17,7 +17,7 @@ GC::Ref<TimerSerenity> TimerSerenity::create(GC::Heap& heap)
}
TimerSerenity::TimerSerenity()
: m_timer(Core::Timer::try_create().release_value_but_fixme_should_propagate_errors())
: m_timer(Core::Timer::create())
{
m_timer->on_timeout = [this] {
if (on_timeout)

View file

@ -23,7 +23,7 @@ namespace Web::SVG {
SVGImageElement::SVGImageElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGGraphicsElement(document, move(qualified_name))
{
m_animation_timer = Core::Timer::try_create().release_value_but_fixme_should_propagate_errors();
m_animation_timer = Core::Timer::create();
m_animation_timer->on_timeout = [this] { animate(); };
}

View file

@ -67,7 +67,7 @@ ErrorOr<void> BrowserProcess::connect_as_server(ByteString const& socket_path)
// TODO: Mach IPC
auto socket_fd = TRY(Process::create_ipc_socket(socket_path));
m_socket_path = socket_path;
auto local_server = TRY(Core::LocalServer::try_create());
auto local_server = Core::LocalServer::construct();
TRY(local_server->take_over_fd(socket_fd));
m_server_connection = TRY(IPC::MultiServer<UIProcessConnectionFromClient>::try_create(move(local_server)));

View file

@ -220,7 +220,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
// TODO: Mach IPC
auto webcontent_socket = TRY(Core::take_over_socket_from_system_server("WebContent"sv));
auto webcontent_client = TRY(WebContent::ConnectionFromClient::try_create(make<IPC::Transport>(move(webcontent_socket))));
auto webcontent_client = WebContent::ConnectionFromClient::construct(make<IPC::Transport>(move(webcontent_socket)));
webcontent_client->on_request_server_connection = [&](auto const& socket_file) {
if (auto result = reinitialize_resource_loader(socket_file); result.is_error())

View file

@ -201,7 +201,7 @@ ErrorOr<NonnullRefPtr<Core::LocalServer>> Session::create_server(NonnullRefPtr<S
(void)Core::System::unlink(*m_web_content_socket_path);
auto server = TRY(Core::LocalServer::try_create());
auto server = Core::LocalServer::construct();
server->listen(*m_web_content_socket_path);
server->on_accept = [this, promise](auto client_socket) {