mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-20 10:02:51 +00:00
AK: Make "foo"_string infallible
Stop worrying about tiny OOMs. Work towards #20405.
This commit is contained in:
parent
db2a8725c6
commit
34344120f2
Notes:
sideshowbarker
2024-07-16 20:31:50 +09:00
Author: https://github.com/awesomekling
Commit: 34344120f2
Pull-request: https://github.com/SerenityOS/serenity/pull/20408
181 changed files with 626 additions and 630 deletions
|
@ -466,7 +466,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
|
|||
// - should internalResponse to request be blocked due to nosniff
|
||||
|| TRY_OR_IGNORE(Infrastructure::should_response_to_request_be_blocked_due_to_nosniff(internal_response, request)) == Infrastructure::RequestOrResponseBlocking::Blocked)) {
|
||||
// then set response and internalResponse to a network error.
|
||||
response = internal_response = Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Response was blocked"_string));
|
||||
response = internal_response = Infrastructure::Response::network_error(vm, "Response was blocked"_string);
|
||||
}
|
||||
|
||||
// 20. If response’s type is "opaque", internalResponse’s status is 206, internalResponse’s range-requested
|
||||
|
@ -479,7 +479,7 @@ WebIDL::ExceptionOr<Optional<JS::NonnullGCPtr<PendingResponse>>> main_fetch(JS::
|
|||
&& internal_response->status() == 206
|
||||
&& internal_response->range_requested()
|
||||
&& !request->header_list()->contains("Range"sv.bytes())) {
|
||||
response = internal_response = Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Response has status 206 and 'range-requested' flag set, but request has no 'Range' header"_string));
|
||||
response = internal_response = Infrastructure::Response::network_error(vm, "Response has status 206 and 'range-requested' flag set, but request has no 'Range' header"_string);
|
||||
}
|
||||
|
||||
// 21. If response is not a network error and either request’s method is `HEAD` or `CONNECT`, or
|
||||
|
@ -834,8 +834,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> scheme_fetch(JS::Realm& r
|
|||
|
||||
// 4. Return a network error.
|
||||
auto message = request->current_url().scheme() == "about"sv
|
||||
? TRY_OR_THROW_OOM(vm, "Request has invalid 'about:' URL, only 'about:blank' can be fetched"_string)
|
||||
: TRY_OR_THROW_OOM(vm, "Request URL has invalid scheme, must be one of 'about', 'blob', 'data', 'file', 'http', or 'https'"_string);
|
||||
? "Request has invalid 'about:' URL, only 'about:blank' can be fetched"_string
|
||||
: "Request URL has invalid scheme, must be one of 'about', 'blob', 'data', 'file', 'http', or 'https'"_string;
|
||||
return PendingResponse::create(vm, request, Infrastructure::Response::network_error(vm, move(message)));
|
||||
}
|
||||
|
||||
|
@ -983,7 +983,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
|
|||
// a service worker for that matter, it is applied here.
|
||||
if (request->response_tainting() == Infrastructure::Request::ResponseTainting::CORS
|
||||
&& !TRY_OR_IGNORE(cors_check(request, *response))) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Request with 'cors' response tainting failed CORS check"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Request with 'cors' response tainting failed CORS check"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1001,7 +1001,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
|
|||
if ((request->response_tainting() == Infrastructure::Request::ResponseTainting::Opaque || response->type() == Infrastructure::Response::Type::Opaque)
|
||||
&& false // FIXME: "and the cross-origin resource policy check with request’s origin, request’s client, request’s destination, and actualResponse returns blocked"
|
||||
) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Response was blocked by cross-origin resource policy check"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Response was blocked by cross-origin resource policy check"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1018,7 +1018,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_fetch(JS::Realm& rea
|
|||
// -> "error"
|
||||
case Infrastructure::Request::RedirectMode::Error:
|
||||
// Set response to a network error.
|
||||
response = Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Request with 'error' redirect mode received redirect response"_string));
|
||||
response = Infrastructure::Response::network_error(vm, "Request with 'error' redirect mode received redirect response"_string);
|
||||
break;
|
||||
// -> "manual"
|
||||
case Infrastructure::Request::RedirectMode::Manual:
|
||||
|
@ -1583,7 +1583,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
|
|||
if (!request->body().has<Empty>()) {
|
||||
// 1. If request’s body’s source is null, then return a network error.
|
||||
if (request->body().get<Infrastructure::Body>().source().has<Empty>()) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Request has body but no body source"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Request has body but no body source"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1629,7 +1629,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> http_network_or_cache_fet
|
|||
// 1. If request’s window is "no-window", then return a network error.
|
||||
if (request->window().has<Infrastructure::Request::Window>()
|
||||
&& request->window().get<Infrastructure::Request::Window>() == Infrastructure::Request::Window::NoWindow) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("Request requires proxy authentication but has 'no-window' set"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "Request requires proxy authentication but has 'no-window' set"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1783,7 +1783,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
|
|||
auto response = Infrastructure::Response::create(vm);
|
||||
// FIXME: This is ugly, ResourceLoader should tell us.
|
||||
if (status_code.value_or(0) == 0) {
|
||||
response = Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("HTTP request failed"_string));
|
||||
response = Infrastructure::Response::network_error(vm, "HTTP request failed"_string);
|
||||
} else {
|
||||
response->set_type(Infrastructure::Response::Type::Error);
|
||||
response->set_status(status_code.value_or(400));
|
||||
|
@ -1874,12 +1874,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::
|
|||
|
||||
// 3. If either methods or headerNames is failure, return a network error.
|
||||
if (methods_or_failure.has<Infrastructure::ExtractHeaderParseFailure>()) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("The Access-Control-Allow-Methods in the CORS-preflight response is syntactically invalid"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "The Access-Control-Allow-Methods in the CORS-preflight response is syntactically invalid"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
if (header_names_or_failure.has<Infrastructure::ExtractHeaderParseFailure>()) {
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("The Access-Control-Allow-Headers in the CORS-preflight response is syntactically invalid"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "The Access-Control-Allow-Headers in the CORS-preflight response is syntactically invalid"_string));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1976,7 +1976,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::
|
|||
}
|
||||
|
||||
// 8. Otherwise, return a network error.
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, TRY_OR_IGNORE("CORS-preflight check failed"_string)));
|
||||
returned_pending_response->resolve(Infrastructure::Response::network_error(vm, "CORS-preflight check failed"_string));
|
||||
});
|
||||
|
||||
return returned_pending_response;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue