LibWeb: Remove OOM propagation from Fetch::Infrastructure::Responses

This commit is contained in:
Timothy Flynn 2024-04-26 13:42:39 -04:00 committed by Andreas Kling
commit 5f51a11618
Notes: sideshowbarker 2024-07-17 04:49:48 +09:00
4 changed files with 14 additions and 14 deletions

View file

@ -417,16 +417,16 @@ WebIDL::ExceptionOr<JS::GCPtr<PendingResponse>> main_fetch(JS::Realm& realm, Inf
// 2. Set response to the following filtered response with response as its internal response, depending
// on requests response tainting:
response = TRY_OR_IGNORE([&]() -> WebIDL::ExceptionOr<JS::NonnullGCPtr<Infrastructure::Response>> {
response = [&]() -> JS::NonnullGCPtr<Infrastructure::Response> {
switch (request->response_tainting()) {
// -> "basic"
case Infrastructure::Request::ResponseTainting::Basic:
// basic filtered response
return TRY_OR_THROW_OOM(vm, Infrastructure::BasicFilteredResponse::create(vm, *response));
return Infrastructure::BasicFilteredResponse::create(vm, *response);
// -> "cors"
case Infrastructure::Request::ResponseTainting::CORS:
// CORS filtered response
return TRY_OR_THROW_OOM(vm, Infrastructure::CORSFilteredResponse::create(vm, *response));
return Infrastructure::CORSFilteredResponse::create(vm, *response);
// -> "opaque"
case Infrastructure::Request::ResponseTainting::Opaque:
// opaque filtered response
@ -434,7 +434,7 @@ WebIDL::ExceptionOr<JS::GCPtr<PendingResponse>> main_fetch(JS::Realm& realm, Inf
default:
VERIFY_NOT_REACHED();
}
}());
}();
}
// 15. Let internalResponse be response, if response is a network error, and responses internal response

View file

@ -146,18 +146,18 @@ ErrorOr<Optional<URL::URL>> Response::location_url(Optional<String> const& reque
}
// https://fetch.spec.whatwg.org/#concept-response-clone
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::clone(JS::Realm& realm) const
JS::NonnullGCPtr<Response> Response::clone(JS::Realm& realm) const
{
// To clone a response response, run these steps:
auto& vm = realm.vm();
// 1. If response is a filtered response, then return a new identical filtered response whose internal response is a clone of responses internal response.
if (is<FilteredResponse>(*this)) {
auto internal_response = TRY(static_cast<FilteredResponse const&>(*this).internal_response()->clone(realm));
auto internal_response = static_cast<FilteredResponse const&>(*this).internal_response()->clone(realm);
if (is<BasicFilteredResponse>(*this))
return TRY_OR_THROW_OOM(vm, BasicFilteredResponse::create(vm, internal_response));
return BasicFilteredResponse::create(vm, internal_response);
if (is<CORSFilteredResponse>(*this))
return TRY_OR_THROW_OOM(vm, CORSFilteredResponse::create(vm, internal_response));
return CORSFilteredResponse::create(vm, internal_response);
if (is<OpaqueFilteredResponse>(*this))
return OpaqueFilteredResponse::create(vm, internal_response);
if (is<OpaqueRedirectFilteredResponse>(*this))
@ -231,7 +231,7 @@ void FilteredResponse::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_internal_response);
}
ErrorOr<JS::NonnullGCPtr<BasicFilteredResponse>> BasicFilteredResponse::create(JS::VM& vm, JS::NonnullGCPtr<Response> internal_response)
JS::NonnullGCPtr<BasicFilteredResponse> BasicFilteredResponse::create(JS::VM& vm, JS::NonnullGCPtr<Response> internal_response)
{
// A basic filtered response is a filtered response whose type is "basic" and header list excludes
// any headers in internal responses header list whose name is a forbidden response-header name.
@ -256,7 +256,7 @@ void BasicFilteredResponse::visit_edges(JS::Cell::Visitor& visitor)
visitor.visit(m_header_list);
}
ErrorOr<JS::NonnullGCPtr<CORSFilteredResponse>> CORSFilteredResponse::create(JS::VM& vm, JS::NonnullGCPtr<Response> internal_response)
JS::NonnullGCPtr<CORSFilteredResponse> CORSFilteredResponse::create(JS::VM& vm, JS::NonnullGCPtr<Response> internal_response)
{
// A CORS filtered response is a filtered response whose type is "cors" and header list excludes
// any headers in internal responses header list whose name is not a CORS-safelisted response-header

View file

@ -109,7 +109,7 @@ public:
[[nodiscard]] Optional<URL::URL const&> url() const;
[[nodiscard]] ErrorOr<Optional<URL::URL>> location_url(Optional<String> const& request_fragment) const;
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> clone(JS::Realm&) const;
[[nodiscard]] JS::NonnullGCPtr<Response> clone(JS::Realm&) const;
[[nodiscard]] JS::NonnullGCPtr<Response> unsafe_response();
@ -227,7 +227,7 @@ class BasicFilteredResponse final : public FilteredResponse {
JS_DECLARE_ALLOCATOR(BasicFilteredResponse);
public:
[[nodiscard]] static ErrorOr<JS::NonnullGCPtr<BasicFilteredResponse>> create(JS::VM&, JS::NonnullGCPtr<Response>);
[[nodiscard]] static JS::NonnullGCPtr<BasicFilteredResponse> create(JS::VM&, JS::NonnullGCPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::Basic; }
[[nodiscard]] virtual JS::NonnullGCPtr<HeaderList> header_list() const override { return m_header_list; }
@ -246,7 +246,7 @@ class CORSFilteredResponse final : public FilteredResponse {
JS_DECLARE_ALLOCATOR(CORSFilteredResponse);
public:
[[nodiscard]] static ErrorOr<JS::NonnullGCPtr<CORSFilteredResponse>> create(JS::VM&, JS::NonnullGCPtr<Response>);
[[nodiscard]] static JS::NonnullGCPtr<CORSFilteredResponse> create(JS::VM&, JS::NonnullGCPtr<Response>);
[[nodiscard]] virtual Type type() const override { return Type::CORS; }
[[nodiscard]] virtual JS::NonnullGCPtr<HeaderList> header_list() const override { return m_header_list; }

View file

@ -289,7 +289,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::clone() const
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Response is unusable"sv };
// 2. Let clonedResponse be the result of cloning thiss response.
auto cloned_response = TRY(m_response->clone(realm));
auto cloned_response = m_response->clone(realm);
// 3. Return the result of creating a Response object, given clonedResponse, thiss headerss guard, and thiss relevant Realm.
return Response::create(HTML::relevant_realm(*this), cloned_response, m_headers->guard());