1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

LibWeb: Make Blob and File GC-allocated

This commit is contained in:
Andreas Kling 2022-09-04 11:44:38 +02:00
parent 018d236439
commit 647ac1bdba
10 changed files with 77 additions and 61 deletions

View file

@ -16,7 +16,6 @@
#include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/GlobalObject.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/BlobWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/XMLHttpRequestPrototype.h>
#include <LibWeb/DOM/DOMException.h>
@ -133,9 +132,9 @@ 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 = 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::Value(wrap(realm(), *blob));
auto blob_part = TRY(FileAPI::Blob::create(global_object(), m_received_bytes, get_final_mime_type().type()));
auto blob = TRY(FileAPI::Blob::create(global_object(), Vector<FileAPI::BlobPart> { JS::make_handle(*blob_part) }));
m_response_object = JS::Value(blob.ptr());
}
// 7. Otherwise, if thiss response type is "document", set a document response for this.
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
@ -286,7 +285,7 @@ static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(XMLHttpRequestB
// 6. Switch on object.
// FIXME: Still need to support BufferSource and FormData
TRY(body_init.visit(
[&](NonnullRefPtr<FileAPI::Blob> const& blob) -> ErrorOr<void> {
[&](JS::Handle<FileAPI::Blob> const& blob) -> ErrorOr<void> {
// FIXME: Set action to this step: read object.
// Set source to object.
source = blob;
@ -493,7 +492,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<XMLHttpRequestBodyInit> bod
request.set_body(buffer);
return {};
},
[&](NonnullRefPtr<FileAPI::Blob> const& blob) -> ErrorOr<void> {
[&](JS::Handle<FileAPI::Blob> const& blob) -> ErrorOr<void> {
auto byte_buffer = TRY(ByteBuffer::copy(blob->bytes()));
request.set_body(byte_buffer);
return {};