From bf048da8cbdd2fffe94402d842b5130b4276d6b2 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sun, 9 Apr 2023 10:57:50 +0200 Subject: [PATCH] LibWeb: Port fire_progress_event() + request_error_steps() to new String This ports XHR's fire_progress_event() and request_error_steps() to new FlyString. Signature of fire_progress_event() parameter event_name was changed from 'String const&' to 'FlyString const&'. --- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 42 +++++++++---------- .../Libraries/LibWeb/XHR/XMLHttpRequest.h | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 0e69cd32df..b94a22363c 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -92,7 +92,7 @@ void XMLHttpRequest::visit_edges(Cell::Visitor& visitor) } // https://xhr.spec.whatwg.org/#concept-event-fire-progress -static void fire_progress_event(XMLHttpRequestEventTarget& target, DeprecatedString const& event_name, u64 transmitted, u64 length) +static void fire_progress_event(XMLHttpRequestEventTarget& target, FlyString const& event_name, u64 transmitted, u64 length) { // To fire a progress event named e at target, given transmitted and length, means to fire an event named e at target, using ProgressEvent, // with the loaded attribute initialized to transmitted, and if length is not 0, with the lengthComputable attribute initialized to true @@ -102,7 +102,7 @@ static void fire_progress_event(XMLHttpRequestEventTarget& target, DeprecatedStr event_init.loaded = transmitted; event_init.total = length; // FIXME: If we're in an async context, this will propagate to a callback context which can't propagate it anywhere else and does not expect this to fail. - target.dispatch_event(*ProgressEvent::create(target.realm(), String::from_deprecated_string(event_name).release_value_but_fixme_should_propagate_errors(), event_init).release_value_but_fixme_should_propagate_errors()); + target.dispatch_event(*ProgressEvent::create(target.realm(), event_name, event_init).release_value_but_fixme_should_propagate_errors()); } // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-responsetext @@ -277,7 +277,7 @@ ErrorOr XMLHttpRequest::get_response_mime_type() const ErrorOr> XMLHttpRequest::get_final_encoding() const { // 1. Let label be null. - Optional label; + Optional label; // 2. Let responseMIME be the result of get a response MIME type for xhr. auto response_mime = TRY(get_response_mime_type()); @@ -285,13 +285,13 @@ ErrorOr> XMLHttpRequest::get_final_encoding() const // 3. If responseMIME’s parameters["charset"] exists, then set label to it. auto response_mime_charset_it = response_mime.parameters().find("charset"sv); if (response_mime_charset_it != response_mime.parameters().end()) - label = response_mime_charset_it->value.to_deprecated_string(); + label = response_mime_charset_it->value; // 4. If xhr’s override MIME type’s parameters["charset"] exists, then set label to it. if (m_override_mime_type.has_value()) { auto override_mime_charset_it = m_override_mime_type->parameters().find("charset"sv); if (override_mime_charset_it != m_override_mime_type->parameters().end()) - label = override_mime_charset_it->value.to_deprecated_string(); + label = override_mime_charset_it->value; } // 5. If label is null, then return null. @@ -607,7 +607,7 @@ WebIDL::ExceptionOr XMLHttpRequest::send(Optional XMLHttpRequest::send(Optional XMLHttpRequest::send(Optional XMLHttpRequest::send(Optional XMLHttpRequest::handle_response_end_of_body() // 6. If xhr’s synchronous flag is unset, then fire a progress event named progress at xhr with transmitted and length. if (!m_synchronous) - fire_progress_event(*this, EventNames::progress.to_deprecated_fly_string(), transmitted, length); + fire_progress_event(*this, EventNames::progress, transmitted, length); // 7. Set xhr’s state to done. m_state = State::Done; @@ -1091,10 +1091,10 @@ WebIDL::ExceptionOr XMLHttpRequest::handle_response_end_of_body() dispatch_event(*DOM::Event::create(realm, EventNames::readystatechange).release_value_but_fixme_should_propagate_errors()); // 10. Fire a progress event named load at xhr with transmitted and length. - fire_progress_event(*this, EventNames::load.to_deprecated_fly_string(), transmitted, length); + fire_progress_event(*this, EventNames::load, transmitted, length); // 11. Fire a progress event named loadend at xhr with transmitted and length. - fire_progress_event(*this, EventNames::loadend.to_deprecated_fly_string(), transmitted, length); + fire_progress_event(*this, EventNames::loadend, transmitted, length); return {}; } @@ -1108,20 +1108,20 @@ WebIDL::ExceptionOr XMLHttpRequest::handle_errors() // 2. If xhr’s timed out flag is set, then run the request error steps for xhr, timeout, and "TimeoutError" DOMException. if (m_timed_out) - return TRY(request_error_steps(EventNames::timeout.to_deprecated_fly_string(), WebIDL::TimeoutError::create(realm(), "Timed out"sv))); + return TRY(request_error_steps(EventNames::timeout, WebIDL::TimeoutError::create(realm(), "Timed out"sv))); // 3. Otherwise, if xhr’s response’s aborted flag is set, run the request error steps for xhr, abort, and "AbortError" DOMException. if (m_response->aborted()) - return TRY(request_error_steps(EventNames::abort.to_deprecated_fly_string(), WebIDL::AbortError::create(realm(), "Aborted"sv))); + return TRY(request_error_steps(EventNames::abort, WebIDL::AbortError::create(realm(), "Aborted"sv))); // 4. Otherwise, if xhr’s response is a network error, then run the request error steps for xhr, error, and "NetworkError" DOMException. if (m_response->is_network_error()) - return TRY(request_error_steps(EventNames::error.to_deprecated_fly_string(), WebIDL::NetworkError::create(realm(), "Network error"sv))); + return TRY(request_error_steps(EventNames::error, WebIDL::NetworkError::create(realm(), "Network error"sv))); return {}; } -JS::ThrowCompletionOr XMLHttpRequest::request_error_steps(DeprecatedFlyString const& event_name, JS::GCPtr exception) +JS::ThrowCompletionOr XMLHttpRequest::request_error_steps(FlyString const& event_name, JS::GCPtr exception) { // 1. Set xhr’s state to done. m_state = State::Done; @@ -1153,7 +1153,7 @@ JS::ThrowCompletionOr XMLHttpRequest::request_error_steps(DeprecatedFlyStr fire_progress_event(m_upload_object, event_name, 0, 0); // 2. Fire a progress event named loadend at xhr’s upload object with 0 and 0. - fire_progress_event(m_upload_object, EventNames::loadend.to_deprecated_fly_string(), 0, 0); + fire_progress_event(m_upload_object, EventNames::loadend, 0, 0); } } @@ -1161,7 +1161,7 @@ JS::ThrowCompletionOr XMLHttpRequest::request_error_steps(DeprecatedFlyStr fire_progress_event(*this, event_name, 0, 0); // 8. Fire a progress event named loadend at xhr with 0 and 0. - fire_progress_event(*this, EventNames::loadend.to_deprecated_fly_string(), 0, 0); + fire_progress_event(*this, EventNames::loadend, 0, 0); return {}; } diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h index d37701e6ec..e8ab6cf56b 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h @@ -89,7 +89,7 @@ private: WebIDL::ExceptionOr handle_response_end_of_body(); WebIDL::ExceptionOr handle_errors(); - JS::ThrowCompletionOr request_error_steps(DeprecatedFlyString const& event_name, JS::GCPtr exception = nullptr); + JS::ThrowCompletionOr request_error_steps(FlyString const& event_name, JS::GCPtr exception = nullptr); XMLHttpRequest(JS::Realm&, XMLHttpRequestUpload&, Fetch::Infrastructure::HeaderList&, Fetch::Infrastructure::Response&, Fetch::Infrastructure::FetchController&);