1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 20:34:59 +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

@ -340,10 +340,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> HTMLMediaElement::play()
// 2. If the media element's error attribute is not null and its code is MEDIA_ERR_SRC_NOT_SUPPORTED, then return a promise
// rejected with a "NotSupportedError" DOMException.
if (m_error && m_error->code() == MediaError::Code::SrcNotSupported) {
auto error = WebIDL::NotSupportedError::create(realm, m_error->message());
auto promise = WebIDL::create_rejected_promise(realm, error);
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise->promise()) };
auto exception = WebIDL::NotSupportedError::create(realm, m_error->message());
return WebIDL::create_rejected_promise_from_exception(realm, move(exception));
}
// 3. Let promise be a new promise and append promise to the list of pending play promises.