From 1ace80235b4f5df6fec8cf2199811617d5f45515 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 21 Sep 2022 23:14:40 +0100 Subject: [PATCH] LibWeb: Move XMLHttpRequestBodyInit into Fetch https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit --- Userland/Libraries/LibWeb/Fetch/BodyInit.h | 19 +++++++++++++++++++ Userland/Libraries/LibWeb/Fetch/BodyInit.idl | 5 +++++ .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 4 ++-- .../Libraries/LibWeb/XHR/XMLHttpRequest.h | 6 ++---- .../Libraries/LibWeb/XHR/XMLHttpRequest.idl | 7 ++----- 5 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 Userland/Libraries/LibWeb/Fetch/BodyInit.h create mode 100644 Userland/Libraries/LibWeb/Fetch/BodyInit.idl diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.h b/Userland/Libraries/LibWeb/Fetch/BodyInit.h new file mode 100644 index 0000000000..e8ce881f50 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::Fetch { + +// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit +using XMLHttpRequestBodyInit = Variant, JS::Handle, JS::Handle, String>; + +} diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.idl b/Userland/Libraries/LibWeb/Fetch/BodyInit.idl new file mode 100644 index 0000000000..15f001a8a8 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.idl @@ -0,0 +1,5 @@ +#import +#import + +// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit +typedef (Blob or BufferSource or URLSearchParams or USVString) XMLHttpRequestBodyInit; diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 0996a42101..80b5e025cd 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -270,7 +270,7 @@ Optional XMLHttpRequest::get_final_encoding() const // https://fetch.spec.whatwg.org/#concept-bodyinit-extract // FIXME: The parameter 'body_init' should be 'typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit'. For now we just let it be 'XMLHttpRequestBodyInit'. -static ErrorOr extract_body(XMLHttpRequestBodyInit const& body_init) +static ErrorOr extract_body(Fetch::XMLHttpRequestBodyInit const& body_init) { // FIXME: 1. Let stream be object if object is a ReadableStream object. Otherwise, let stream be a new ReadableStream, and set up stream. Fetch::Infrastructure::Body::ReadableStreamDummy stream {}; @@ -453,7 +453,7 @@ DOM::ExceptionOr XMLHttpRequest::open(String const& method_string, String } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send -DOM::ExceptionOr XMLHttpRequest::send(Optional body) +DOM::ExceptionOr XMLHttpRequest::send(Optional body) { if (m_ready_state != ReadyState::Opened) return DOM::InvalidStateError::create(global_object(), "XHR readyState is not OPENED"); diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index a7616ba888..75ae823853 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -22,9 +23,6 @@ namespace Web::XHR { -// https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit -using XMLHttpRequestBodyInit = Variant, JS::Handle, JS::Handle, String>; - class XMLHttpRequest final : public XMLHttpRequestEventTarget { WEB_PLATFORM_OBJECT(XMLHttpRequest, XMLHttpRequestEventTarget); @@ -49,7 +47,7 @@ public: DOM::ExceptionOr open(String const& method, String const& url); DOM::ExceptionOr open(String const& method, String const& url, bool async, String const& username = {}, String const& password = {}); - DOM::ExceptionOr send(Optional body); + DOM::ExceptionOr send(Optional body); DOM::ExceptionOr set_request_header(String const& header, String const& value); void set_response_type(Bindings::XMLHttpRequestResponseType type) { m_response_type = type; } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl index fa6b29a0c8..34c8726c7c 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.idl @@ -1,9 +1,6 @@ -#import #import -#import -#import - -typedef (Blob or BufferSource or URLSearchParams or USVString) XMLHttpRequestBodyInit; +#import +#import enum XMLHttpRequestResponseType { "",