mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 09:52:54 +00:00
LibWeb: Remove exception handling from safely extracting response bodies
The entire purpose of this AO is to avoid handling exceptions, which we can do now that the underlying AOs do not throw exceptions on OOM.
This commit is contained in:
parent
49ff5eb4d8
commit
953fe75271
Notes:
github-actions[bot]
2024-12-10 03:04:18 +00:00
Author: https://github.com/gmta
Commit: 953fe75271
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2162
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/shannonbooth
8 changed files with 33 additions and 34 deletions
|
@ -122,7 +122,7 @@ WebIDL::ExceptionOr<GC::Ref<Infrastructure::FetchController>> fetch(JS::Realm& r
|
|||
|
||||
// 8. If request’s body is a byte sequence, then set request’s body to request’s body as a body.
|
||||
if (auto const* buffer = request.body().get_pointer<ByteBuffer>())
|
||||
request.set_body(TRY(Infrastructure::byte_sequence_as_body(realm, buffer->bytes())));
|
||||
request.set_body(Infrastructure::byte_sequence_as_body(realm, buffer->bytes()));
|
||||
|
||||
// 9. If request’s window is "client", then set request’s window to request’s client, if request’s client’s global
|
||||
// object is a Window object; otherwise "no-window".
|
||||
|
@ -576,7 +576,7 @@ WebIDL::ExceptionOr<GC::Ptr<PendingResponse>> main_fetch(JS::Realm& realm, Infra
|
|||
}
|
||||
|
||||
// 2. Set response’s body to bytes as a body.
|
||||
response->set_body(TRY_OR_IGNORE(Infrastructure::byte_sequence_as_body(realm, bytes)));
|
||||
response->set_body(Infrastructure::byte_sequence_as_body(realm, bytes));
|
||||
|
||||
// 3. Run fetch response handover given fetchParams and response.
|
||||
fetch_response_handover(realm, fetch_params, *response);
|
||||
|
@ -807,7 +807,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> scheme_fetch(JS::Realm& realm, Inf
|
|||
auto header = Infrastructure::Header::from_string_pair("Content-Type"sv, "text/html;charset=utf-8"sv);
|
||||
response->header_list()->append(move(header));
|
||||
|
||||
response->set_body(MUST(Infrastructure::byte_sequence_as_body(realm, ""sv.bytes())));
|
||||
response->set_body(Infrastructure::byte_sequence_as_body(realm, ""sv.bytes()));
|
||||
return PendingResponse::create(vm, request, response);
|
||||
}
|
||||
|
||||
|
@ -845,13 +845,13 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> scheme_fetch(JS::Realm& realm, Inf
|
|||
// 8. If request’s header list does not contain `Range`:
|
||||
if (!request->header_list()->contains("Range"sv.bytes())) {
|
||||
// 1. Let bodyWithType be the result of safely extracting blob.
|
||||
auto body_with_type = TRY(safely_extract_body(realm, blob->raw_bytes()));
|
||||
auto body_with_type = safely_extract_body(realm, blob->raw_bytes());
|
||||
|
||||
// 2. Set response’s status message to `OK`.
|
||||
response->set_status_message(MUST(ByteBuffer::copy("OK"sv.bytes())));
|
||||
|
||||
// 3. Set response’s body to bodyWithType’s body.
|
||||
response->set_body(move(body_with_type.body));
|
||||
response->set_body(body_with_type.body);
|
||||
|
||||
// 4. Set response’s header list to « (`Content-Length`, serializedFullLength), (`Content-Type`, type) ».
|
||||
auto content_length_header = Infrastructure::Header::from_string_pair("Content-Length"sv, serialized_full_length);
|
||||
|
@ -903,7 +903,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> scheme_fetch(JS::Realm& realm, Inf
|
|||
auto sliced_blob = TRY(blob->slice(*range_start, *range_end + 1, type));
|
||||
|
||||
// 9. Let slicedBodyWithType be the result of safely extracting slicedBlob.
|
||||
auto sliced_body_with_type = TRY(safely_extract_body(realm, sliced_blob->raw_bytes()));
|
||||
auto sliced_body_with_type = safely_extract_body(realm, sliced_blob->raw_bytes());
|
||||
|
||||
// 10. Set response’s body to slicedBodyWithType’s body.
|
||||
response->set_body(sliced_body_with_type.body);
|
||||
|
@ -958,7 +958,7 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> scheme_fetch(JS::Realm& realm, Inf
|
|||
auto header = Infrastructure::Header::from_string_pair("Content-Type"sv, mime_type);
|
||||
response->header_list()->append(move(header));
|
||||
|
||||
response->set_body(TRY(Infrastructure::byte_sequence_as_body(realm, data_url_struct.value().body)));
|
||||
response->set_body(Infrastructure::byte_sequence_as_body(realm, data_url_struct.value().body));
|
||||
return PendingResponse::create(vm, request, response);
|
||||
}
|
||||
// -> "file"
|
||||
|
@ -1308,8 +1308,8 @@ WebIDL::ExceptionOr<GC::Ptr<PendingResponse>> http_redirect_fetch(JS::Realm& rea
|
|||
auto converted_source = source.has<ByteBuffer>()
|
||||
? BodyInitOrReadableBytes { source.get<ByteBuffer>() }
|
||||
: BodyInitOrReadableBytes { source.get<GC::Root<FileAPI::Blob>>() };
|
||||
auto [body, _] = TRY(safely_extract_body(realm, converted_source));
|
||||
request->set_body(move(body));
|
||||
auto [body, _] = safely_extract_body(realm, converted_source);
|
||||
request->set_body(body);
|
||||
}
|
||||
|
||||
// 15. Let timingInfo be fetchParams’s timing info.
|
||||
|
@ -2107,8 +2107,8 @@ WebIDL::ExceptionOr<GC::Ref<PendingResponse>> http_network_or_cache_fetch(JS::Re
|
|||
auto converted_source = source.has<ByteBuffer>()
|
||||
? BodyInitOrReadableBytes { source.get<ByteBuffer>() }
|
||||
: BodyInitOrReadableBytes { source.get<GC::Root<FileAPI::Blob>>() };
|
||||
auto [body, _] = TRY_OR_IGNORE(safely_extract_body(realm, converted_source));
|
||||
request->set_body(move(body));
|
||||
auto [body, _] = safely_extract_body(realm, converted_source);
|
||||
request->set_body(body);
|
||||
}
|
||||
|
||||
// 3. If request’s use-URL-credentials flag is unset or isAuthenticationFetch is true, then:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue