LibWeb: Implement BufferSource support for XHR::send()

This commit is contained in:
Kenneth Myhra 2022-07-22 18:50:30 +02:00 committed by Linus Groh
parent e55bdd434a
commit 9a1c27a163
Notes: sideshowbarker 2024-07-17 12:02:22 +09:00
3 changed files with 8 additions and 2 deletions

View File

@ -17,6 +17,7 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibTextCodec/Decoder.h>
#include <LibWeb/Bindings/EventWrapper.h>
#include <LibWeb/Bindings/IDLAbstractOperations.h>
#include <LibWeb/Bindings/XMLHttpRequestWrapper.h>
#include <LibWeb/DOM/DOMException.h>
#include <LibWeb/DOM/Document.h>
@ -283,6 +284,11 @@ static ErrorOr<Fetch::Infrastructure::BodyWithType> extract_body(XMLHttpRequestB
type = blob->type().to_byte_buffer();
return {};
},
[&](JS::Handle<JS::Object> const& buffer_source) -> ErrorOr<void> {
// Set source to a copy of the bytes held by object.
source = TRY(Bindings::IDL::get_buffer_source_copy(*buffer_source.cell()));
return {};
},
[&](NonnullRefPtr<URL::URLSearchParams> const& url_search_params) -> ErrorOr<void> {
// Set source to the result of running the application/x-www-form-urlencoded serializer with objects list.
source = url_search_params->to_string().to_byte_buffer();

View File

@ -24,7 +24,7 @@
namespace Web::XHR {
// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<FileAPI::Blob>, NonnullRefPtr<URL::URLSearchParams>, String>;
using XMLHttpRequestBodyInit = Variant<NonnullRefPtr<FileAPI::Blob>, JS::Handle<JS::Object>, NonnullRefPtr<URL::URLSearchParams>, String>;
class XMLHttpRequest final
: public RefCounted<XMLHttpRequest>

View File

@ -3,7 +3,7 @@
#import <FileAPI/Blob.idl>
#import <URL/URLSearchParams.idl>
typedef (Blob or URLSearchParams or USVString) XMLHttpRequestBodyInit;
typedef (Blob or BufferSource or URLSearchParams or USVString) XMLHttpRequestBodyInit;
enum XMLHttpRequestResponseType {
"",