1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 05:27:35 +00:00

LibWeb: Add and use a helper to reject a promise with an exception

This commit is contained in:
Sam Atkins 2024-03-08 15:37:28 +00:00 committed by Tim Flynn
parent 24951a039e
commit 4bdb7dba8c
10 changed files with 42 additions and 52 deletions

View file

@ -13,7 +13,6 @@
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/Bindings/HostDefined.h>
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::WebIDL {
@ -295,4 +294,11 @@ void wait_for_all(JS::Realm& realm, Vector<JS::NonnullGCPtr<Promise>> const& pro
}
}
JS::NonnullGCPtr<JS::Promise> create_rejected_promise_from_exception(JS::Realm& realm, Exception exception)
{
auto throw_completion = Bindings::dom_exception_to_throw_completion(realm.vm(), move(exception));
auto promise_capability = WebIDL::create_rejected_promise(realm, *throw_completion.value());
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise().ptr()) };
}
}