LibWeb: Remove OOM propagation from Fetch::Request

This commit is contained in:
Timothy Flynn 2024-04-27 10:31:50 -04:00 committed by Andreas Kling
parent d12c560859
commit 790589ceb0
2 changed files with 13 additions and 18 deletions

View file

@ -182,7 +182,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// method
// requests method.
request->set_method(TRY_OR_THROW_OOM(vm, ByteBuffer::copy(input_request->method())));
request->set_method(MUST(ByteBuffer::copy(input_request->method())));
// header list
// A copy of requests header list.
@ -373,7 +373,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Method must not be one of CONNECT, TRACE, or TRACK"sv };
// 3. Normalize method.
method = TRY_OR_THROW_OOM(vm, String::from_utf8(Infrastructure::normalize_method(method.bytes())));
method = MUST(String::from_utf8(Infrastructure::normalize_method(method.bytes())));
// 4. Set requests method to method.
request->set_method(MUST(ByteBuffer::copy(method.bytes())));
@ -503,21 +503,17 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
}
// https://fetch.spec.whatwg.org/#dom-request-method
WebIDL::ExceptionOr<String> Request::method() const
String Request::method() const
{
auto& vm = this->vm();
// The method getter steps are to return thiss requests method.
return TRY_OR_THROW_OOM(vm, String::from_utf8(m_request->method()));
return MUST(String::from_utf8(m_request->method()));
}
// https://fetch.spec.whatwg.org/#dom-request-url
WebIDL::ExceptionOr<String> Request::url() const
String Request::url() const
{
auto& vm = this->vm();
// The url getter steps are to return thiss requests URL, serialized.
return TRY_OR_THROW_OOM(vm, String::from_byte_string(m_request->url().serialize()));
return MUST(String::from_byte_string(m_request->url().serialize()));
}
// https://fetch.spec.whatwg.org/#dom-request-headers
@ -535,11 +531,10 @@ Bindings::RequestDestination Request::destination() const
}
// https://fetch.spec.whatwg.org/#dom-request-referrer
WebIDL::ExceptionOr<String> Request::referrer() const
String Request::referrer() const
{
auto& vm = this->vm();
return m_request->referrer().visit(
[&](Infrastructure::Request::Referrer const& referrer) -> WebIDL::ExceptionOr<String> {
[&](Infrastructure::Request::Referrer const& referrer) {
switch (referrer) {
// 1. If thiss requests referrer is "no-referrer", then return the empty string.
case Infrastructure::Request::Referrer::NoReferrer:
@ -551,9 +546,9 @@ WebIDL::ExceptionOr<String> Request::referrer() const
VERIFY_NOT_REACHED();
}
},
[&](URL::URL const& url) -> WebIDL::ExceptionOr<String> {
[&](URL::URL const& url) {
// 3. Return thiss requests referrer, serialized.
return TRY_OR_THROW_OOM(vm, String::from_byte_string(url.serialize()));
return MUST(String::from_byte_string(url.serialize()));
});
}

View file

@ -82,11 +82,11 @@ public:
[[nodiscard]] JS::NonnullGCPtr<Infrastructure::Request> request() const { return m_request; }
// JS API functions
[[nodiscard]] WebIDL::ExceptionOr<String> method() const;
[[nodiscard]] WebIDL::ExceptionOr<String> url() const;
[[nodiscard]] String method() const;
[[nodiscard]] String url() const;
[[nodiscard]] JS::NonnullGCPtr<Headers> headers() const;
[[nodiscard]] Bindings::RequestDestination destination() const;
[[nodiscard]] WebIDL::ExceptionOr<String> referrer() const;
[[nodiscard]] String referrer() const;
[[nodiscard]] Bindings::ReferrerPolicy referrer_policy() const;
[[nodiscard]] Bindings::RequestMode mode() const;
[[nodiscard]] Bindings::RequestCredentials credentials() const;