Skip to content

Commit bf048da

Browse files
kennethmyhralinusg
authored andcommitted
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&'.
1 parent fdd33d8 commit bf048da

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void XMLHttpRequest::visit_edges(Cell::Visitor& visitor)
9292
}
9393

9494
// https://xhr.spec.whatwg.org/#concept-event-fire-progress
95-
static void fire_progress_event(XMLHttpRequestEventTarget& target, DeprecatedString const& event_name, u64 transmitted, u64 length)
95+
static void fire_progress_event(XMLHttpRequestEventTarget& target, FlyString const& event_name, u64 transmitted, u64 length)
9696
{
9797
// To fire a progress event named e at target, given transmitted and length, means to fire an event named e at target, using ProgressEvent,
9898
// 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
102102
event_init.loaded = transmitted;
103103
event_init.total = length;
104104
// 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.
105-
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());
105+
target.dispatch_event(*ProgressEvent::create(target.realm(), event_name, event_init).release_value_but_fixme_should_propagate_errors());
106106
}
107107

108108
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-responsetext
@@ -277,21 +277,21 @@ ErrorOr<MimeSniff::MimeType> XMLHttpRequest::get_response_mime_type() const
277277
ErrorOr<Optional<StringView>> XMLHttpRequest::get_final_encoding() const
278278
{
279279
// 1. Let label be null.
280-
Optional<DeprecatedString> label;
280+
Optional<String> label;
281281

282282
// 2. Let responseMIME be the result of get a response MIME type for xhr.
283283
auto response_mime = TRY(get_response_mime_type());
284284

285285
// 3. If responseMIME’s parameters["charset"] exists, then set label to it.
286286
auto response_mime_charset_it = response_mime.parameters().find("charset"sv);
287287
if (response_mime_charset_it != response_mime.parameters().end())
288-
label = response_mime_charset_it->value.to_deprecated_string();
288+
label = response_mime_charset_it->value;
289289

290290
// 4. If xhr’s override MIME type’s parameters["charset"] exists, then set label to it.
291291
if (m_override_mime_type.has_value()) {
292292
auto override_mime_charset_it = m_override_mime_type->parameters().find("charset"sv);
293293
if (override_mime_charset_it != m_override_mime_type->parameters().end())
294-
label = override_mime_charset_it->value.to_deprecated_string();
294+
label = override_mime_charset_it->value;
295295
}
296296

297297
// 5. If label is null, then return null.
@@ -607,7 +607,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
607607
// 11. If this’s synchronous flag is unset, then:
608608
if (!m_synchronous) {
609609
// 1. Fire a progress event named loadstart at this with 0 and 0.
610-
fire_progress_event(*this, EventNames::loadstart.to_deprecated_fly_string(), 0, 0);
610+
fire_progress_event(*this, EventNames::loadstart, 0, 0);
611611

612612
// 2. Let requestBodyTransmitted be 0.
613613
// NOTE: This is kept on the XHR object itself instead of the stack, as we cannot capture references to stack variables in an async context.
@@ -625,7 +625,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
625625

626626
// 5. If this’s upload complete flag is unset and this’s upload listener flag is set, then fire a progress event named loadstart at this’s upload object with requestBodyTransmitted and requestBodyLength.
627627
if (!m_upload_complete && m_upload_listener)
628-
fire_progress_event(m_upload_object, EventNames::loadstart.to_deprecated_fly_string(), m_request_body_transmitted, request_body_length);
628+
fire_progress_event(m_upload_object, EventNames::loadstart, m_request_body_transmitted, request_body_length);
629629

630630
// 6. If this’s state is not opened or this’s send() flag is unset, then return.
631631
if (m_state != State::Opened || !m_send)
@@ -642,7 +642,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
642642

643643
// 3. If this’s upload listener flag is set, then fire a progress event named progress at this’s upload object with requestBodyTransmitted and requestBodyLength.
644644
if (m_upload_listener)
645-
fire_progress_event(m_upload_object, EventNames::progress.to_deprecated_fly_string(), m_request_body_transmitted, request_body_length);
645+
fire_progress_event(m_upload_object, EventNames::progress, m_request_body_transmitted, request_body_length);
646646
};
647647

648648
// 8. Let processRequestEndOfBody be these steps:
@@ -657,13 +657,13 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::send(Optional<DocumentOrXMLHttpRequest
657657
return;
658658

659659
// 3. Fire a progress event named progress at this’s upload object with requestBodyTransmitted and requestBodyLength.
660-
fire_progress_event(m_upload_object, EventNames::progress.to_deprecated_fly_string(), m_request_body_transmitted, request_body_length);
660+
fire_progress_event(m_upload_object, EventNames::progress, m_request_body_transmitted, request_body_length);
661661

662662
// 4. Fire a progress event named load at this’s upload object with requestBodyTransmitted and requestBodyLength.
663-
fire_progress_event(m_upload_object, EventNames::load.to_deprecated_fly_string(), m_request_body_transmitted, request_body_length);
663+
fire_progress_event(m_upload_object, EventNames::load, m_request_body_transmitted, request_body_length);
664664

665665
// 5. Fire a progress event named loadend at this’s upload object with requestBodyTransmitted and requestBodyLength.
666-
fire_progress_event(m_upload_object, EventNames::loadend.to_deprecated_fly_string(), m_request_body_transmitted, request_body_length);
666+
fire_progress_event(m_upload_object, EventNames::loadend, m_request_body_transmitted, request_body_length);
667667
};
668668

669669
// 9. Let processResponse, given a response, be these steps:
@@ -1017,7 +1017,7 @@ void XMLHttpRequest::abort()
10171017
// NOTE: This cannot throw as we don't pass in an exception. XHR::abort cannot be reached in a synchronous context where the state matches above.
10181018
// This is because it pauses inside XHR::send until the request is done or times out and then immediately calls `handle_response_end_of_body`
10191019
// which will always set `m_state` to `Done`.
1020-
MUST(request_error_steps(EventNames::abort.to_deprecated_fly_string()));
1020+
MUST(request_error_steps(EventNames::abort));
10211021
}
10221022

10231023
// 3. If this’s state is done, then set this’s state to unsent and this’s response to a network error.
@@ -1078,7 +1078,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::handle_response_end_of_body()
10781078

10791079
// 6. If xhr’s synchronous flag is unset, then fire a progress event named progress at xhr with transmitted and length.
10801080
if (!m_synchronous)
1081-
fire_progress_event(*this, EventNames::progress.to_deprecated_fly_string(), transmitted, length);
1081+
fire_progress_event(*this, EventNames::progress, transmitted, length);
10821082

10831083
// 7. Set xhr’s state to done.
10841084
m_state = State::Done;
@@ -1091,10 +1091,10 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::handle_response_end_of_body()
10911091
dispatch_event(*DOM::Event::create(realm, EventNames::readystatechange).release_value_but_fixme_should_propagate_errors());
10921092

10931093
// 10. Fire a progress event named load at xhr with transmitted and length.
1094-
fire_progress_event(*this, EventNames::load.to_deprecated_fly_string(), transmitted, length);
1094+
fire_progress_event(*this, EventNames::load, transmitted, length);
10951095

10961096
// 11. Fire a progress event named loadend at xhr with transmitted and length.
1097-
fire_progress_event(*this, EventNames::loadend.to_deprecated_fly_string(), transmitted, length);
1097+
fire_progress_event(*this, EventNames::loadend, transmitted, length);
10981098

10991099
return {};
11001100
}
@@ -1108,20 +1108,20 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::handle_errors()
11081108

11091109
// 2. If xhr’s timed out flag is set, then run the request error steps for xhr, timeout, and "TimeoutError" DOMException.
11101110
if (m_timed_out)
1111-
return TRY(request_error_steps(EventNames::timeout.to_deprecated_fly_string(), WebIDL::TimeoutError::create(realm(), "Timed out"sv)));
1111+
return TRY(request_error_steps(EventNames::timeout, WebIDL::TimeoutError::create(realm(), "Timed out"sv)));
11121112

11131113
// 3. Otherwise, if xhr’s response’s aborted flag is set, run the request error steps for xhr, abort, and "AbortError" DOMException.
11141114
if (m_response->aborted())
1115-
return TRY(request_error_steps(EventNames::abort.to_deprecated_fly_string(), WebIDL::AbortError::create(realm(), "Aborted"sv)));
1115+
return TRY(request_error_steps(EventNames::abort, WebIDL::AbortError::create(realm(), "Aborted"sv)));
11161116

11171117
// 4. Otherwise, if xhr’s response is a network error, then run the request error steps for xhr, error, and "NetworkError" DOMException.
11181118
if (m_response->is_network_error())
1119-
return TRY(request_error_steps(EventNames::error.to_deprecated_fly_string(), WebIDL::NetworkError::create(realm(), "Network error"sv)));
1119+
return TRY(request_error_steps(EventNames::error, WebIDL::NetworkError::create(realm(), "Network error"sv)));
11201120

11211121
return {};
11221122
}
11231123

1124-
JS::ThrowCompletionOr<void> XMLHttpRequest::request_error_steps(DeprecatedFlyString const& event_name, JS::GCPtr<WebIDL::DOMException> exception)
1124+
JS::ThrowCompletionOr<void> XMLHttpRequest::request_error_steps(FlyString const& event_name, JS::GCPtr<WebIDL::DOMException> exception)
11251125
{
11261126
// 1. Set xhr’s state to done.
11271127
m_state = State::Done;
@@ -1153,15 +1153,15 @@ JS::ThrowCompletionOr<void> XMLHttpRequest::request_error_steps(DeprecatedFlyStr
11531153
fire_progress_event(m_upload_object, event_name, 0, 0);
11541154

11551155
// 2. Fire a progress event named loadend at xhr’s upload object with 0 and 0.
1156-
fire_progress_event(m_upload_object, EventNames::loadend.to_deprecated_fly_string(), 0, 0);
1156+
fire_progress_event(m_upload_object, EventNames::loadend, 0, 0);
11571157
}
11581158
}
11591159

11601160
// 7. Fire a progress event named event at xhr with 0 and 0.
11611161
fire_progress_event(*this, event_name, 0, 0);
11621162

11631163
// 8. Fire a progress event named loadend at xhr with 0 and 0.
1164-
fire_progress_event(*this, EventNames::loadend.to_deprecated_fly_string(), 0, 0);
1164+
fire_progress_event(*this, EventNames::loadend, 0, 0);
11651165

11661166
return {};
11671167
}

Userland/Libraries/LibWeb/XHR/XMLHttpRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class XMLHttpRequest final : public XMLHttpRequestEventTarget {
8989

9090
WebIDL::ExceptionOr<void> handle_response_end_of_body();
9191
WebIDL::ExceptionOr<void> handle_errors();
92-
JS::ThrowCompletionOr<void> request_error_steps(DeprecatedFlyString const& event_name, JS::GCPtr<WebIDL::DOMException> exception = nullptr);
92+
JS::ThrowCompletionOr<void> request_error_steps(FlyString const& event_name, JS::GCPtr<WebIDL::DOMException> exception = nullptr);
9393

9494
XMLHttpRequest(JS::Realm&, XMLHttpRequestUpload&, Fetch::Infrastructure::HeaderList&, Fetch::Infrastructure::Response&, Fetch::Infrastructure::FetchController&);
9595

0 commit comments

Comments
 (0)