1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:37:36 +00:00

LibWeb: Move ExceptionOr from DOM/ to WebIDL/

This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
This commit is contained in:
Linus Groh 2022-09-25 17:03:42 +01:00
parent c0eda77928
commit ad04d7ac9b
107 changed files with 441 additions and 440 deletions

View file

@ -21,7 +21,6 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h>
#include <LibWeb/DOM/EventDispatcher.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/DOM/IDLEventListener.h>
#include <LibWeb/Fetch/BodyInit.h>
#include <LibWeb/Fetch/Infrastructure/HTTP.h>
@ -34,6 +33,7 @@
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
#include <LibWeb/XHR/EventNames.h>
#include <LibWeb/XHR/ProgressEvent.h>
#include <LibWeb/XHR/XMLHttpRequest.h>
@ -80,7 +80,7 @@ void XMLHttpRequest::fire_progress_event(String const& event_name, u64 transmitt
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-responsetext
DOM::ExceptionOr<String> XMLHttpRequest::response_text() const
WebIDL::ExceptionOr<String> XMLHttpRequest::response_text() const
{
// 1. If thiss response type is not the empty string or "text", then throw an "InvalidStateError" DOMException.
if (m_response_type != Bindings::XMLHttpRequestResponseType::Empty && m_response_type != Bindings::XMLHttpRequestResponseType::Text)
@ -94,7 +94,7 @@ DOM::ExceptionOr<String> XMLHttpRequest::response_text() const
}
// https://xhr.spec.whatwg.org/#response
DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
WebIDL::ExceptionOr<JS::Value> XMLHttpRequest::response()
{
// 1. If thiss response type is the empty string or "text", then:
if (m_response_type == Bindings::XMLHttpRequestResponseType::Empty || m_response_type == Bindings::XMLHttpRequestResponseType::Text) {
@ -139,7 +139,7 @@ DOM::ExceptionOr<JS::Value> XMLHttpRequest::response()
// 7. Otherwise, if thiss response type is "document", set a document response for this.
else if (m_response_type == Bindings::XMLHttpRequestResponseType::Document) {
// FIXME: Implement this.
return DOM::SimpleException { DOM::SimpleExceptionType::TypeError, "XHR Document type not implemented" };
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "XHR Document type not implemented" };
}
// 8. Otherwise:
else {
@ -269,7 +269,7 @@ Optional<StringView> XMLHttpRequest::get_final_encoding() const
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-setrequestheader
DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name_string, String const& value_string)
WebIDL::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name_string, String const& value_string)
{
auto name = name_string.to_byte_buffer();
auto value = value_string.to_byte_buffer();
@ -312,13 +312,13 @@ DOM::ExceptionOr<void> XMLHttpRequest::set_request_header(String const& name_str
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-open
DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String const& url)
WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String const& url)
{
// 8. If the async argument is omitted, set async to true, and set username and password to null.
return open(method_string, url, true, {}, {});
}
DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String const& url, bool async, String const& username, String const& password)
WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String const& url, bool async, String const& username, String const& password)
{
auto method = method_string.to_byte_buffer();
@ -395,7 +395,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, String
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-send
DOM::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyInit> body)
WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<Fetch::XMLHttpRequestBodyInit> body)
{
auto& vm = this->vm();
auto& realm = *vm.current_realm();
@ -548,7 +548,7 @@ String XMLHttpRequest::get_all_response_headers() const
}
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-overridemimetype
DOM::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
WebIDL::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
{
// 1. If thiss state is loading or done, then throw an "InvalidStateError" DOMException.
if (m_ready_state == ReadyState::Loading || m_ready_state == ReadyState::Done)
@ -565,7 +565,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::override_mime_type(String const& mime)
}
// https://xhr.spec.whatwg.org/#ref-for-dom-xmlhttprequest-timeout%E2%91%A2
DOM::ExceptionOr<void> XMLHttpRequest::set_timeout(u32 timeout)
WebIDL::ExceptionOr<void> XMLHttpRequest::set_timeout(u32 timeout)
{
// 1. If the current global object is a Window object and thiss synchronous flag is set,
// then throw an "InvalidAccessError" DOMException.

View file

@ -12,13 +12,13 @@
#include <AK/URL.h>
#include <AK/Weakable.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/ExceptionOr.h>
#include <LibWeb/Fetch/BodyInit.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Headers.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Statuses.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/MimeSniff/MimeType.h>
#include <LibWeb/URL/URLSearchParams.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
#include <LibWeb/XHR/XMLHttpRequestEventTarget.h>
namespace Web::XHR {
@ -41,15 +41,15 @@ public:
ReadyState ready_state() const { return m_ready_state; };
Fetch::Infrastructure::Status status() const { return m_status; };
DOM::ExceptionOr<String> response_text() const;
DOM::ExceptionOr<JS::Value> response();
WebIDL::ExceptionOr<String> response_text() const;
WebIDL::ExceptionOr<JS::Value> response();
Bindings::XMLHttpRequestResponseType response_type() const { return m_response_type; }
DOM::ExceptionOr<void> open(String const& method, String const& url);
DOM::ExceptionOr<void> open(String const& method, String const& url, bool async, String const& username = {}, String const& password = {});
DOM::ExceptionOr<void> send(Optional<Fetch::XMLHttpRequestBodyInit> body);
WebIDL::ExceptionOr<void> open(String const& method, String const& url);
WebIDL::ExceptionOr<void> open(String const& method, String const& url, bool async, String const& username = {}, String const& password = {});
WebIDL::ExceptionOr<void> send(Optional<Fetch::XMLHttpRequestBodyInit> body);
DOM::ExceptionOr<void> set_request_header(String const& header, String const& value);
WebIDL::ExceptionOr<void> set_request_header(String const& header, String const& value);
void set_response_type(Bindings::XMLHttpRequestResponseType type) { m_response_type = type; }
String get_response_header(String const& name) { return m_response_headers.get(name).value_or({}); }
@ -58,9 +58,9 @@ public:
WebIDL::CallbackType* onreadystatechange();
void set_onreadystatechange(WebIDL::CallbackType*);
DOM::ExceptionOr<void> override_mime_type(String const& mime);
WebIDL::ExceptionOr<void> override_mime_type(String const& mime);
DOM::ExceptionOr<void> set_timeout(u32 timeout);
WebIDL::ExceptionOr<void> set_timeout(u32 timeout);
u32 timeout() const;
private: