1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-17 11:47:37 +00:00

LibWeb: Make factory method of FileAPI::Blob fallible

This commit is contained in:
Kenneth Myhra 2023-02-14 19:55:21 +01:00 committed by Linus Groh
parent bc02686ae9
commit 15917146d3
4 changed files with 5 additions and 5 deletions

View file

@ -109,7 +109,7 @@ WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm& realm, ByteBuffer bytes,
// Return a Blob whose contents are bytes and type attribute is mimeType.
// NOTE: If extracting the mime type returns failure, other browsers set it to an empty string - not sure if that's spec'd.
auto mime_type_string = mime_type.has_value() ? mime_type->serialized() : DeprecatedString::empty();
return FileAPI::Blob::create(realm, move(bytes), move(mime_type_string));
return TRY(FileAPI::Blob::create(realm, move(bytes), move(mime_type_string)));
}
case PackageDataType::FormData:
// If mimeTypes essence is "multipart/form-data", then:

View file

@ -15,9 +15,9 @@
namespace Web::FileAPI {
JS::NonnullGCPtr<Blob> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::create(JS::Realm& realm, ByteBuffer byte_buffer, DeprecatedString type)
{
return realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type)).release_allocated_value_but_fixme_should_propagate_errors();
return MUST_OR_THROW_OOM(realm.heap().allocate<Blob>(realm, realm, move(byte_buffer), move(type)));
}
// https://w3c.github.io/FileAPI/#convert-line-endings-to-native

View file

@ -33,7 +33,7 @@ class Blob : public Bindings::PlatformObject {
public:
virtual ~Blob() override;
static JS::NonnullGCPtr<Blob> create(JS::Realm&, ByteBuffer, DeprecatedString type);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, ByteBuffer, DeprecatedString type);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> create(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> construct_impl(JS::Realm&, Optional<Vector<BlobPart>> const& blob_parts = {}, Optional<BlobPropertyBag> const& options = {});

View file

@ -161,7 +161,7 @@ WebIDL::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 = FileAPI::Blob::create(realm(), m_received_bytes, get_final_mime_type().type());
auto blob_part = TRY(FileAPI::Blob::create(realm(), m_received_bytes, get_final_mime_type().type()));
auto blob = TRY(FileAPI::Blob::create(realm(), Vector<FileAPI::BlobPart> { JS::make_handle(*blob_part) }));
m_response_object = JS::Value(blob.ptr());
}