mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibWeb: Add support for XHR response type Blob
This commit is contained in:
parent
df8c49f6bf
commit
5806eeec08
3 changed files with 13 additions and 2 deletions
|
@ -194,4 +194,9 @@ JS::Promise* Blob::array_buffer()
|
|||
return promise;
|
||||
}
|
||||
|
||||
JS::Object* Blob::create_wrapper(JS::GlobalObject& global_object)
|
||||
{
|
||||
return wrap(global_object, *this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
JS::Promise* text();
|
||||
JS::Promise* array_buffer();
|
||||
|
||||
virtual JS::Object* create_wrapper(JS::GlobalObject&);
|
||||
|
||||
private:
|
||||
Blob() = default;
|
||||
static DOM::ExceptionOr<ByteBuffer> process_blob_parts(Vector<BlobPart> const& blob_parts);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <LibWeb/Fetch/Infrastructure/HTTP.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Methods.h>
|
||||
#include <LibWeb/FileAPI/Blob.h>
|
||||
#include <LibWeb/HTML/EventHandler.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/HTML/Origin.h>
|
||||
|
@ -117,8 +118,11 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
|
|||
}
|
||||
// 6. Otherwise, if this’s response type is "blob", set this’s response object to a new Blob object representing this’s received bytes with type set to the result of get a final MIME type for this.
|
||||
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Blob) {
|
||||
// FIXME: Implement this once we have 'Blob'.
|
||||
return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, "XHR Blob type not implemented" };
|
||||
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() }));
|
||||
m_response_object = JS::make_handle(JS::Value(blob->create_wrapper(global_object)));
|
||||
}
|
||||
// 7. Otherwise, if this’s response type is "document", set a document response for this.
|
||||
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue