From 3fefe7b59fb7b4a2a391150737db17f6bced1726 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 2 Apr 2026 07:46:57 -0400 Subject: [PATCH] LibWeb: Add a convenience method to reject a promise with an exception --- Libraries/LibWeb/WebIDL/Promise.cpp | 6 ++++++ Libraries/LibWeb/WebIDL/Promise.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/WebIDL/Promise.cpp b/Libraries/LibWeb/WebIDL/Promise.cpp index c25a420ff5e..d2865b5644b 100644 --- a/Libraries/LibWeb/WebIDL/Promise.cpp +++ b/Libraries/LibWeb/WebIDL/Promise.cpp @@ -333,4 +333,10 @@ GC::Ref create_rejected_promise_from_exception(JS::Realm& realm, Except return WebIDL::create_rejected_promise(realm, throw_completion.value()); } +void reject_promise_with_exception(JS::Realm& realm, Promise const& promise, Exception exception) +{ + auto throw_completion = Bindings::exception_to_throw_completion(realm.vm(), move(exception)); + WebIDL::reject_promise(realm, promise, throw_completion.value()); +} + } diff --git a/Libraries/LibWeb/WebIDL/Promise.h b/Libraries/LibWeb/WebIDL/Promise.h index 8a6b1acbe71..9efce82c9bf 100644 --- a/Libraries/LibWeb/WebIDL/Promise.h +++ b/Libraries/LibWeb/WebIDL/Promise.h @@ -34,7 +34,8 @@ WEB_API bool is_promise_fulfilled(Promise const&); WEB_API void wait_for_all(JS::Realm&, ReadonlySpan> promises, Function const&)> success_steps, Function failure_steps); WEB_API GC::Ref get_promise_for_wait_for_all(JS::Realm&, ReadonlySpan> promises); -// Non-spec, convenience method. +// Non-spec, convenience methods. WEB_API GC::Ref create_rejected_promise_from_exception(JS::Realm&, Exception); +WEB_API void reject_promise_with_exception(JS::Realm&, Promise const&, Exception); }