1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:27:44 +00:00

LibWeb: Add & use TRY_OR_RETURN_OOM macro

This is a convenient way to return a DOM exception for operations that
return ErrorOr and only have an OOM failure path.
This commit is contained in:
Linus Groh 2022-07-17 18:23:27 +01:00
parent 452dc544bc
commit bc68539e26
4 changed files with 19 additions and 15 deletions

View file

@ -118,10 +118,8 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
}
// 6. Otherwise, if thiss response type is "blob", set thiss response object to a new Blob object representing thiss received bytes with type set to the result of get a final MIME type for this.
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Blob) {
auto blob_part_or_error = try_make_ref_counted<FileAPI::Blob>(m_received_bytes, get_final_mime_type().type());
if (blob_part_or_error.is_error())
return DOM::UnknownError::create("Out of memory."sv);
auto blob = TRY(FileAPI::Blob::create(Vector<FileAPI::BlobPart> { blob_part_or_error.release_value() }));
auto blob_part = TRY_OR_RETURN_OOM(try_make_ref_counted<FileAPI::Blob>(m_received_bytes, get_final_mime_type().type()));
auto blob = TRY(FileAPI::Blob::create(Vector<FileAPI::BlobPart> { move(blob_part) }));
m_response_object = JS::make_handle(JS::Value(blob->create_wrapper(global_object)));
}
// 7. Otherwise, if thiss response type is "document", set a document response for this.