1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:27:35 +00:00

LibWeb/Fetch: Port JS interfaces to new String

Since BodyInit and Headers are tightly coupled to both Request and
Response, I chose to do all of them at once instead of introducing a
bunch of temporary conversion glue code.
This commit is contained in:
Linus Groh 2023-03-02 22:26:12 +00:00
parent f561940e54
commit 7f9ddcf420
13 changed files with 130 additions and 129 deletions

View file

@ -24,7 +24,7 @@
// ```idl // ```idl
// #import <Fetch/Request.idl> // #import <Fetch/Request.idl>
// #import <Fetch/Response.idl> // #import <Fetch/Response.idl>
// [Exposed=Window] // [Exposed=Window, UseNewAKString]
// interface Dummy { // interface Dummy {
// static Promise<Response> fetch(RequestInfo input, optional RequestInit init = {}); // static Promise<Response> fetch(RequestInfo input, optional RequestInit init = {});
// }; // };
@ -55,7 +55,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (vm.argument_count() < 1) if (vm.argument_count() < 1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "fetch"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::BadArgCountOne, "fetch");
auto arg0 = vm.argument(0); auto arg0 = vm.argument(0);
auto arg0_to_variant = [&vm, &realm](JS::Value arg0) -> JS::ThrowCompletionOr<Variant<JS::Handle<Request>, DeprecatedString>> { auto arg0_to_variant = [&vm, &realm](JS::Value arg0) -> JS::ThrowCompletionOr<Variant<JS::Handle<Request>, String>> {
// These might be unused. // These might be unused.
(void)vm; (void)vm;
(void)realm; (void)realm;
@ -66,9 +66,9 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
return JS::make_handle(static_cast<Request&>(arg0_object)); return JS::make_handle(static_cast<Request&>(arg0_object));
} }
} }
return TRY(arg0.to_deprecated_string(vm)); return TRY(arg0.to_string(vm));
}; };
Variant<JS::Handle<Request>, DeprecatedString> input = TRY(arg0_to_variant(arg0)); Variant<JS::Handle<Request>, String> input = TRY(arg0_to_variant(arg0));
auto arg1 = vm.argument(1); auto arg1 = vm.argument(1);
if (!arg1.is_nullish() && !arg1.is_object()) if (!arg1.is_nullish() && !arg1.is_object())
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "RequestInit"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "RequestInit");
@ -77,7 +77,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object()) if (arg1.is_object())
body_property_value = TRY(arg1.as_object().get("body")); body_property_value = TRY(arg1.as_object().get("body"));
if (!body_property_value.is_undefined()) { if (!body_property_value.is_undefined()) {
auto body_property_value_to_variant = [&vm, &realm](JS::Value body_property_value) -> JS::ThrowCompletionOr<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, DeprecatedString>> { auto body_property_value_to_variant = [&vm, &realm](JS::Value body_property_value) -> JS::ThrowCompletionOr<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, String>> {
// These might be unused. // These might be unused.
(void)vm; (void)vm;
(void)realm; (void)realm;
@ -94,9 +94,9 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (is<JS::ArrayBuffer>(body_property_value_object)) if (is<JS::ArrayBuffer>(body_property_value_object))
return JS::make_handle(body_property_value_object); return JS::make_handle(body_property_value_object);
} }
return TRY(body_property_value.to_deprecated_string(vm)); return TRY(body_property_value.to_string(vm));
}; };
Optional<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, DeprecatedString>> body_value; Optional<Variant<JS::Handle<ReadableStream>, JS::Handle<Blob>, JS::Handle<JS::Object>, JS::Handle<URLSearchParams>, String>> body_value;
if (!body_property_value.is_nullish()) if (!body_property_value.is_nullish())
body_value = TRY(body_property_value_to_variant(body_property_value)); body_value = TRY(body_property_value_to_variant(body_property_value));
init.body = body_value; init.body = body_value;
@ -161,7 +161,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object()) if (arg1.is_object())
headers_property_value = TRY(arg1.as_object().get("headers")); headers_property_value = TRY(arg1.as_object().get("headers"));
if (!headers_property_value.is_undefined()) { if (!headers_property_value.is_undefined()) {
auto headers_property_value_to_variant = [&vm, &realm](JS::Value headers_property_value) -> JS::ThrowCompletionOr<Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>>> { auto headers_property_value_to_variant = [&vm, &realm](JS::Value headers_property_value) -> JS::ThrowCompletionOr<Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>> {
// These might be unused. // These might be unused.
(void)vm; (void)vm;
(void)realm; (void)realm;
@ -170,7 +170,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
auto* method = TRY(headers_property_value.get_method(vm, *vm.well_known_symbol_iterator())); auto* method = TRY(headers_property_value.get_method(vm, *vm.well_known_symbol_iterator()));
if (method) { if (method) {
auto iterator1 = TRY(JS::get_iterator(vm, headers_property_value, JS::IteratorHint::Sync, method)); auto iterator1 = TRY(JS::get_iterator(vm, headers_property_value, JS::IteratorHint::Sync, method));
Vector<Vector<DeprecatedString>> headers_value; Vector<Vector<String>> headers_value;
for (;;) { for (;;) {
auto* next1 = TRY(JS::iterator_step(vm, iterator1)); auto* next1 = TRY(JS::iterator_step(vm, iterator1));
if (!next1) if (!next1)
@ -182,17 +182,15 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (!iterator_method1) if (!iterator_method1)
return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, next_item1.to_string_without_side_effects())); return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotIterable, TRY_OR_THROW_OOM(vm, next_item1.to_string_without_side_effects()));
auto iterator2 = TRY(JS::get_iterator(vm, next_item1, JS::IteratorHint::Sync, iterator_method1)); auto iterator2 = TRY(JS::get_iterator(vm, next_item1, JS::IteratorHint::Sync, iterator_method1));
Vector<DeprecatedString> sequence_item1; Vector<String> sequence_item1;
for (;;) { for (;;) {
auto* next2 = TRY(JS::iterator_step(vm, iterator2)); auto* next2 = TRY(JS::iterator_step(vm, iterator2));
if (!next2) if (!next2)
break; break;
auto next_item2 = TRY(JS::iterator_value(vm, *next2)); auto next_item2 = TRY(JS::iterator_value(vm, *next2));
DeprecatedString sequence_item2; String sequence_item2;
if (next_item2.is_null() && false) { if (!false || !next_item2.is_null()) {
sequence_item2 = DeprecatedString::empty(); sequence_item2 = TRY(next_item2.to_string(vm));
} else {
sequence_item2 = TRY(next_item2.to_deprecated_string(vm));
} }
sequence_item1.append(sequence_item2); sequence_item1.append(sequence_item2);
} }
@ -200,25 +198,21 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
} }
return headers_value; return headers_value;
} }
OrderedHashMap<DeprecatedString, DeprecatedString> record_union_type; OrderedHashMap<String, String> record_union_type;
auto record_keys1 = TRY(headers_property_value_object.internal_own_property_keys()); auto record_keys1 = TRY(headers_property_value_object.internal_own_property_keys());
for (auto& key1 : record_keys1) { for (auto& key1 : record_keys1) {
auto property_key1 = MUST(JS::PropertyKey::from_value(vm, key1)); auto property_key1 = MUST(JS::PropertyKey::from_value(vm, key1));
auto descriptor1 = TRY(headers_property_value_object.internal_get_own_property(property_key1)); auto descriptor1 = TRY(headers_property_value_object.internal_get_own_property(property_key1));
if (!descriptor1.has_value() || !descriptor1->enumerable.has_value() || !descriptor1->enumerable.value()) if (!descriptor1.has_value() || !descriptor1->enumerable.has_value() || !descriptor1->enumerable.value())
continue; continue;
DeprecatedString typed_key1; String typed_key1;
if (key1.is_null() && false) { if (!false || !key1.is_null()) {
typed_key1 = DeprecatedString::empty(); typed_key1 = TRY(key1.to_string(vm));
} else {
typed_key1 = TRY(key1.to_deprecated_string(vm));
} }
auto value1 = TRY(headers_property_value_object.get(property_key1)); auto value1 = TRY(headers_property_value_object.get(property_key1));
DeprecatedString typed_value1; String typed_value1;
if (value1.is_null() && false) { if (!false || !value1.is_null()) {
typed_value1 = DeprecatedString::empty(); typed_value1 = TRY(value1.to_string(vm));
} else {
typed_value1 = TRY(value1.to_deprecated_string(vm));
} }
record_union_type.set(typed_key1, typed_value1); record_union_type.set(typed_key1, typed_value1);
} }
@ -226,7 +220,7 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
} }
return vm.throw_completion<JS::TypeError>("No union types matched"sv); return vm.throw_completion<JS::TypeError>("No union types matched"sv);
}; };
Optional<Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>>> headers_value; Optional<Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>> headers_value;
if (!headers_property_value.is_nullish()) if (!headers_property_value.is_nullish())
headers_value = TRY(headers_property_value_to_variant(headers_property_value)); headers_value = TRY(headers_property_value_to_variant(headers_property_value));
init.headers = headers_value; init.headers = headers_value;
@ -235,14 +229,13 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object()) if (arg1.is_object())
integrity_property_value = TRY(arg1.as_object().get("integrity")); integrity_property_value = TRY(arg1.as_object().get("integrity"));
if (!integrity_property_value.is_undefined()) { if (!integrity_property_value.is_undefined()) {
DeprecatedString integrity_value; Optional<String> integrity_value;
if (!integrity_property_value.is_undefined()) { if (!integrity_property_value.is_undefined()) {
if (integrity_property_value.is_null() && false) if (!false || !integrity_property_value.is_null())
integrity_value = DeprecatedString::empty(); integrity_value = TRY(integrity_property_value.to_string(vm));
else
integrity_value = TRY(integrity_property_value.to_deprecated_string(vm));
} }
init.integrity = integrity_value; if (integrity_value.has_value())
init.integrity = integrity_value.release_value();
} }
auto keepalive_property_value = JS::js_undefined(); auto keepalive_property_value = JS::js_undefined();
if (arg1.is_object()) if (arg1.is_object())
@ -257,14 +250,13 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object()) if (arg1.is_object())
method_property_value = TRY(arg1.as_object().get("method")); method_property_value = TRY(arg1.as_object().get("method"));
if (!method_property_value.is_undefined()) { if (!method_property_value.is_undefined()) {
DeprecatedString method_value; Optional<String> method_value;
if (!method_property_value.is_undefined()) { if (!method_property_value.is_undefined()) {
if (method_property_value.is_null() && false) if (!false || !method_property_value.is_null())
method_value = DeprecatedString::empty(); method_value = TRY(method_property_value.to_string(vm));
else
method_value = TRY(method_property_value.to_deprecated_string(vm));
} }
init.method = method_value; if (method_value.has_value())
init.method = method_value.release_value();
} }
auto mode_property_value = JS::js_undefined(); auto mode_property_value = JS::js_undefined();
if (arg1.is_object()) if (arg1.is_object())
@ -308,14 +300,13 @@ JS::ThrowCompletionOr<JS::Value> fetch(JS::VM& vm)
if (arg1.is_object()) if (arg1.is_object())
referrer_property_value = TRY(arg1.as_object().get("referrer")); referrer_property_value = TRY(arg1.as_object().get("referrer"));
if (!referrer_property_value.is_undefined()) { if (!referrer_property_value.is_undefined()) {
DeprecatedString referrer_value; Optional<String> referrer_value;
if (!referrer_property_value.is_undefined()) { if (!referrer_property_value.is_undefined()) {
if (referrer_property_value.is_null() && false) if (!false || !referrer_property_value.is_null())
referrer_value = DeprecatedString::empty(); referrer_value = TRY(referrer_property_value.to_string(vm));
else
referrer_value = TRY(referrer_property_value.to_deprecated_string(vm));
} }
init.referrer = referrer_value; if (referrer_value.has_value())
init.referrer = referrer_value.release_value();
} }
auto referrer_policy_property_value = JS::js_undefined(); auto referrer_policy_property_value = JS::js_undefined();
if (arg1.is_object()) if (arg1.is_object())

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -135,7 +135,7 @@ WebIDL::ExceptionOr<JS::Value> package_data(JS::Realm& realm, ByteBuffer bytes,
return Infra::parse_json_bytes_to_javascript_value(vm, bytes); return Infra::parse_json_bytes_to_javascript_value(vm, bytes);
case PackageDataType::Text: case PackageDataType::Text:
// Return the result of running UTF-8 decode on bytes. // Return the result of running UTF-8 decode on bytes.
return JS::PrimitiveString::create(vm, DeprecatedString::copy(bytes)); return JS::PrimitiveString::create(vm, TRY_OR_THROW_OOM(vm, String::from_utf8(bytes)));
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Kenneth Myhra <kennethmyhra@serenityos.org> * Copyright (c) 2022, Kenneth Myhra <kennethmyhra@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
@ -96,10 +96,10 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
type = TRY_OR_THROW_OOM(vm, ByteBuffer::copy("application/x-www-form-urlencoded;charset=UTF-8"sv.bytes())); type = TRY_OR_THROW_OOM(vm, ByteBuffer::copy("application/x-www-form-urlencoded;charset=UTF-8"sv.bytes()));
return {}; return {};
}, },
[&](DeprecatedString const& scalar_value_string) -> WebIDL::ExceptionOr<void> { [&](String const& scalar_value_string) -> WebIDL::ExceptionOr<void> {
// NOTE: AK::DeprecatedString is always UTF-8. // NOTE: AK::String is always UTF-8.
// Set source to the UTF-8 encoding of object. // Set source to the UTF-8 encoding of object.
source = scalar_value_string.to_byte_buffer(); source = TRY_OR_THROW_OOM(vm, ByteBuffer::copy(scalar_value_string.bytes()));
// Set type to `text/plain;charset=UTF-8`. // Set type to `text/plain;charset=UTF-8`.
type = TRY_OR_THROW_OOM(vm, ByteBuffer::copy("text/plain;charset=UTF-8"sv.bytes())); type = TRY_OR_THROW_OOM(vm, ByteBuffer::copy("text/plain;charset=UTF-8"sv.bytes()));
return {}; return {};

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -14,9 +14,9 @@
namespace Web::Fetch { namespace Web::Fetch {
// https://fetch.spec.whatwg.org/#bodyinit // https://fetch.spec.whatwg.org/#bodyinit
using BodyInit = Variant<JS::Handle<Streams::ReadableStream>, JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, DeprecatedString>; using BodyInit = Variant<JS::Handle<Streams::ReadableStream>, JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, String>;
using BodyInitOrReadableBytes = Variant<JS::Handle<Streams::ReadableStream>, JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, DeprecatedString, ReadonlyBytes>; using BodyInitOrReadableBytes = Variant<JS::Handle<Streams::ReadableStream>, JS::Handle<FileAPI::Blob>, JS::Handle<JS::Object>, JS::Handle<URL::URLSearchParams>, String, ReadonlyBytes>;
WebIDL::ExceptionOr<Infrastructure::BodyWithType> safely_extract_body(JS::Realm&, BodyInitOrReadableBytes const&); WebIDL::ExceptionOr<Infrastructure::BodyWithType> safely_extract_body(JS::Realm&, BodyInitOrReadableBytes const&);
WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm&, BodyInitOrReadableBytes const&, bool keepalive = false); WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm&, BodyInitOrReadableBytes const&, bool keepalive = false);

View file

@ -52,7 +52,7 @@ void Headers::visit_edges(JS::Cell::Visitor& visitor)
} }
// https://fetch.spec.whatwg.org/#dom-headers-append // https://fetch.spec.whatwg.org/#dom-headers-append
WebIDL::ExceptionOr<void> Headers::append(DeprecatedString const& name_string, DeprecatedString const& value_string) WebIDL::ExceptionOr<void> Headers::append(String const& name_string, String const& value_string)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
@ -66,15 +66,15 @@ WebIDL::ExceptionOr<void> Headers::append(DeprecatedString const& name_string, D
} }
// https://fetch.spec.whatwg.org/#dom-headers-delete // https://fetch.spec.whatwg.org/#dom-headers-delete
WebIDL::ExceptionOr<void> Headers::delete_(DeprecatedString const& name_string) WebIDL::ExceptionOr<void> Headers::delete_(String const& name_string)
{ {
// The delete(name) method steps are: // The delete(name) method steps are:
auto& realm = this->realm(); auto& vm = this->vm();
auto name = name_string.bytes(); auto name = name_string.bytes();
// 1. If validating (name, ``) for headers returns false, then return. // 1. If validating (name, ``) for headers returns false, then return.
// NOTE: Passing a dummy header value ought not to have any negative repercussions. // NOTE: Passing a dummy header value ought not to have any negative repercussions.
auto header = TRY_OR_THROW_OOM(realm.vm(), Infrastructure::Header::from_string_pair(name, ""sv)); auto header = TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(name, ""sv));
if (!TRY(validate(header))) if (!TRY(validate(header)))
return {}; return {};
@ -97,9 +97,10 @@ WebIDL::ExceptionOr<void> Headers::delete_(DeprecatedString const& name_string)
} }
// https://fetch.spec.whatwg.org/#dom-headers-get // https://fetch.spec.whatwg.org/#dom-headers-get
WebIDL::ExceptionOr<DeprecatedString> Headers::get(DeprecatedString const& name_string) WebIDL::ExceptionOr<Optional<String>> Headers::get(String const& name_string)
{ {
// The get(name) method steps are: // The get(name) method steps are:
auto& vm = this->vm();
auto name = name_string.bytes(); auto name = name_string.bytes();
// 1. If name is not a header name, then throw a TypeError. // 1. If name is not a header name, then throw a TypeError.
@ -107,17 +108,16 @@ WebIDL::ExceptionOr<DeprecatedString> Headers::get(DeprecatedString const& name_
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv }; return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Invalid header name"sv };
// 2. Return the result of getting name from thiss header list. // 2. Return the result of getting name from thiss header list.
auto byte_buffer = TRY_OR_THROW_OOM(vm(), m_header_list->get(name)); auto byte_buffer = TRY_OR_THROW_OOM(vm, m_header_list->get(name));
// FIXME: Teach BindingsGenerator about Optional<DeprecatedString> return byte_buffer.has_value() ? TRY_OR_THROW_OOM(vm, String::from_utf8(*byte_buffer)) : Optional<String> {};
return byte_buffer.has_value() ? DeprecatedString { byte_buffer->span() } : DeprecatedString {};
} }
// https://fetch.spec.whatwg.org/#dom-headers-getsetcookie // https://fetch.spec.whatwg.org/#dom-headers-getsetcookie
WebIDL::ExceptionOr<Vector<DeprecatedString>> Headers::get_set_cookie() WebIDL::ExceptionOr<Vector<String>> Headers::get_set_cookie()
{ {
// The getSetCookie() method steps are: // The getSetCookie() method steps are:
auto& vm = this->vm(); auto& vm = this->vm();
auto values = Vector<DeprecatedString> {}; auto values = Vector<String> {};
// 1. If thiss header list does not contain `Set-Cookie`, then return « ». // 1. If thiss header list does not contain `Set-Cookie`, then return « ».
if (!m_header_list->contains("Set-Cookie"sv.bytes())) if (!m_header_list->contains("Set-Cookie"sv.bytes()))
@ -127,13 +127,13 @@ WebIDL::ExceptionOr<Vector<DeprecatedString>> Headers::get_set_cookie()
// `Set-Cookie`, in order. // `Set-Cookie`, in order.
for (auto const& header : *m_header_list) { for (auto const& header : *m_header_list) {
if (StringView { header.name }.equals_ignoring_case("Set-Cookie"sv)) if (StringView { header.name }.equals_ignoring_case("Set-Cookie"sv))
TRY_OR_THROW_OOM(vm, values.try_append(DeprecatedString { header.value.bytes() })); TRY_OR_THROW_OOM(vm, values.try_append(TRY_OR_THROW_OOM(vm, String::from_utf8(header.value))));
} }
return values; return values;
} }
// https://fetch.spec.whatwg.org/#dom-headers-has // https://fetch.spec.whatwg.org/#dom-headers-has
WebIDL::ExceptionOr<bool> Headers::has(DeprecatedString const& name_string) WebIDL::ExceptionOr<bool> Headers::has(String const& name_string)
{ {
// The has(name) method steps are: // The has(name) method steps are:
auto name = name_string.bytes(); auto name = name_string.bytes();
@ -147,7 +147,7 @@ WebIDL::ExceptionOr<bool> Headers::has(DeprecatedString const& name_string)
} }
// https://fetch.spec.whatwg.org/#dom-headers-set // https://fetch.spec.whatwg.org/#dom-headers-set
WebIDL::ExceptionOr<void> Headers::set(DeprecatedString const& name_string, DeprecatedString const& value_string) WebIDL::ExceptionOr<void> Headers::set(String const& name_string, String const& value_string)
{ {
auto& realm = this->realm(); auto& realm = this->realm();
auto& vm = realm.vm(); auto& vm = realm.vm();
@ -185,12 +185,11 @@ WebIDL::ExceptionOr<void> Headers::set(DeprecatedString const& name_string, Depr
// https://webidl.spec.whatwg.org/#es-iterable, Step 4 // https://webidl.spec.whatwg.org/#es-iterable, Step 4
JS::ThrowCompletionOr<void> Headers::for_each(ForEachCallback callback) JS::ThrowCompletionOr<void> Headers::for_each(ForEachCallback callback)
{ {
auto& vm = this->vm();
// The value pairs to iterate over are the return value of running sort and combine with thiss header list. // The value pairs to iterate over are the return value of running sort and combine with thiss header list.
auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr<Vector<Fetch::Infrastructure::Header>> { auto value_pairs_to_iterate_over = [&]() -> JS::ThrowCompletionOr<Vector<Fetch::Infrastructure::Header>> {
auto headers_or_error = m_header_list->sort_and_combine(); return TRY_OR_THROW_OOM(vm, m_header_list->sort_and_combine());
if (headers_or_error.is_error())
return vm().throw_completion<JS::InternalError>(JS::ErrorType::NotEnoughMemoryToAllocate);
return headers_or_error.release_value();
}; };
// 1-5. Are done in the generated wrapper code. // 1-5. Are done in the generated wrapper code.
@ -207,7 +206,7 @@ JS::ThrowCompletionOr<void> Headers::for_each(ForEachCallback callback)
auto const& pair = pairs[i]; auto const& pair = pairs[i];
// 2. Invoke idlCallback with « pairs value, pairs key, idlObject » and with thisArg as the callback this value. // 2. Invoke idlCallback with « pairs value, pairs key, idlObject » and with thisArg as the callback this value.
TRY(callback(StringView { pair.name }, StringView { pair.value })); TRY(callback(TRY_OR_THROW_OOM(vm, String::from_utf8(pair.name)), TRY_OR_THROW_OOM(vm, String::from_utf8(pair.value))));
// 3. Set pairs to idlObjects current list of value pairs to iterate over. (It might have changed.) // 3. Set pairs to idlObjects current list of value pairs to iterate over. (It might have changed.)
pairs = TRY(value_pairs_to_iterate_over()); pairs = TRY(value_pairs_to_iterate_over());
@ -309,20 +308,20 @@ WebIDL::ExceptionOr<void> Headers::fill(HeadersInit const& object)
// To fill a Headers object headers with a given object object, run these steps: // To fill a Headers object headers with a given object object, run these steps:
return object.visit( return object.visit(
// 1. If object is a sequence, then for each header of object: // 1. If object is a sequence, then for each header of object:
[&](Vector<Vector<DeprecatedString>> const& object) -> WebIDL::ExceptionOr<void> { [&](Vector<Vector<String>> const& object) -> WebIDL::ExceptionOr<void> {
for (auto const& entry : object) { for (auto const& entry : object) {
// 1. If header's size is not 2, then throw a TypeError. // 1. If header's size is not 2, then throw a TypeError.
if (entry.size() != 2) if (entry.size() != 2)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Array must contain header key/value pair"sv }; return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Array must contain header key/value pair"sv };
// 2. Append (header[0], header[1]) to headers. // 2. Append (header[0], header[1]) to headers.
auto header = TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(entry[0], entry[1].bytes())); auto header = TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(entry[0], entry[1]));
TRY(append(move(header))); TRY(append(move(header)));
} }
return {}; return {};
}, },
// 2. Otherwise, object is a record, then for each key → value of object, append (key, value) to headers. // 2. Otherwise, object is a record, then for each key → value of object, append (key, value) to headers.
[&](OrderedHashMap<DeprecatedString, DeprecatedString> const& object) -> WebIDL::ExceptionOr<void> { [&](OrderedHashMap<String, String> const& object) -> WebIDL::ExceptionOr<void> {
for (auto const& entry : object) { for (auto const& entry : object) {
auto header = TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(entry.key, entry.value)); auto header = TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(entry.key, entry.value));
TRY(append(move(header))); TRY(append(move(header)));

View file

@ -6,8 +6,8 @@
#pragma once #pragma once
#include <AK/DeprecatedString.h>
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/Variant.h> #include <AK/Variant.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
@ -18,7 +18,7 @@
namespace Web::Fetch { namespace Web::Fetch {
using HeadersInit = Variant<Vector<Vector<DeprecatedString>>, OrderedHashMap<DeprecatedString, DeprecatedString>>; using HeadersInit = Variant<Vector<Vector<String>>, OrderedHashMap<String, String>>;
// https://fetch.spec.whatwg.org/#headers-class // https://fetch.spec.whatwg.org/#headers-class
class Headers final : public Bindings::PlatformObject { class Headers final : public Bindings::PlatformObject {
@ -44,17 +44,17 @@ public:
void set_guard(Guard guard) { m_guard = guard; } void set_guard(Guard guard) { m_guard = guard; }
WebIDL::ExceptionOr<void> fill(HeadersInit const&); WebIDL::ExceptionOr<void> fill(HeadersInit const&);
WebIDL::ExceptionOr<void> append(Infrastructure::Header);
// JS API functions // JS API functions
WebIDL::ExceptionOr<void> append(Infrastructure::Header); WebIDL::ExceptionOr<void> append(String const& name, String const& value);
WebIDL::ExceptionOr<void> append(DeprecatedString const& name, DeprecatedString const& value); WebIDL::ExceptionOr<void> delete_(String const& name);
WebIDL::ExceptionOr<void> delete_(DeprecatedString const& name); WebIDL::ExceptionOr<Optional<String>> get(String const& name);
WebIDL::ExceptionOr<DeprecatedString> get(DeprecatedString const& name); WebIDL::ExceptionOr<Vector<String>> get_set_cookie();
WebIDL::ExceptionOr<Vector<DeprecatedString>> get_set_cookie(); WebIDL::ExceptionOr<bool> has(String const& name);
WebIDL::ExceptionOr<bool> has(DeprecatedString const& name); WebIDL::ExceptionOr<void> set(String const& name, String const& value);
WebIDL::ExceptionOr<void> set(DeprecatedString const& name, DeprecatedString const& value);
using ForEachCallback = Function<JS::ThrowCompletionOr<void>(DeprecatedString const&, DeprecatedString const&)>; using ForEachCallback = Function<JS::ThrowCompletionOr<void>(String const&, String const&)>;
JS::ThrowCompletionOr<void> for_each(ForEachCallback); JS::ThrowCompletionOr<void> for_each(ForEachCallback);
private: private:

View file

@ -1,6 +1,6 @@
typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit; typedef (sequence<sequence<ByteString>> or record<ByteString, ByteString>) HeadersInit;
[Exposed=(Window,Worker)] [Exposed=(Window,Worker), UseNewAKString]
interface Headers { interface Headers {
constructor(optional HeadersInit init); constructor(optional HeadersInit init);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -119,9 +119,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
DOM::AbortSignal const* input_signal = nullptr; DOM::AbortSignal const* input_signal = nullptr;
// 5. If input is a string, then: // 5. If input is a string, then:
if (input.has<DeprecatedString>()) { if (input.has<String>()) {
// 1. Let parsedURL be the result of parsing input with baseURL. // 1. Let parsedURL be the result of parsing input with baseURL.
auto parsed_url = URLParser::parse(input.get<DeprecatedString>(), &base_url); auto parsed_url = URLParser::parse(input.get<String>(), &base_url);
// 2. If parsedURL is failure, then throw a TypeError. // 2. If parsedURL is failure, then throw a TypeError.
if (!parsed_url.is_valid()) if (!parsed_url.is_valid())
@ -355,7 +355,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// 23. If init["integrity"] exists, then set requests integrity metadata to it. // 23. If init["integrity"] exists, then set requests integrity metadata to it.
if (init.integrity.has_value()) if (init.integrity.has_value())
request->set_integrity_metadata(*init.integrity); request->set_integrity_metadata(init.integrity->to_deprecated_string());
// 24. If init["keepalive"] exists, then set requests keepalive to it. // 24. If init["keepalive"] exists, then set requests keepalive to it.
if (init.keepalive.has_value()) if (init.keepalive.has_value())
@ -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 }; return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Method must not be one of CONNECT, TRACE, or TRACK"sv };
// 3. Normalize method. // 3. Normalize method.
method = TRY_OR_THROW_OOM(vm, Infrastructure::normalize_method(method.bytes())); method = TRY_OR_THROW_OOM(vm, String::from_utf8(TRY_OR_THROW_OOM(vm, Infrastructure::normalize_method(method.bytes()))));
// 4. Set requests method to method. // 4. Set requests method to method.
request->set_method(MUST(ByteBuffer::copy(method.bytes()))); request->set_method(MUST(ByteBuffer::copy(method.bytes())));
@ -424,7 +424,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// 4. If headers is a Headers object, then for each header of its header list, append header to thiss headers. // 4. If headers is a Headers object, then for each header of its header list, append header to thiss headers.
if (auto* header_list = headers.get_pointer<JS::NonnullGCPtr<Infrastructure::HeaderList>>()) { if (auto* header_list = headers.get_pointer<JS::NonnullGCPtr<Infrastructure::HeaderList>>()) {
for (auto& header : *header_list->ptr()) for (auto& header : *header_list->ptr())
TRY(request_object->headers()->append(DeprecatedString::copy(header.name), DeprecatedString::copy(header.value))); TRY(request_object->headers()->append(TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair(header.name, header.value))));
} }
// 5. Otherwise, fill thiss headers with headers. // 5. Otherwise, fill thiss headers with headers.
else { else {
@ -457,7 +457,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
// 4. If type is non-null and thiss headerss header list does not contain `Content-Type`, then append (`Content-Type`, type) to thiss headers. // 4. If type is non-null and thiss headerss header list does not contain `Content-Type`, then append (`Content-Type`, type) to thiss headers.
if (type.has_value() && !request_object->headers()->header_list()->contains("Content-Type"sv.bytes())) if (type.has_value() && !request_object->headers()->header_list()->contains("Content-Type"sv.bytes()))
TRY(request_object->headers()->append("Content-Type"sv, DeprecatedString::copy(type->span()))); TRY(request_object->headers()->append(TRY_OR_THROW_OOM(vm, Infrastructure::Header::from_string_pair("Content-Type"sv, type->span()))));
} }
// 37. Let inputOrInitBody be initBody if it is non-null; otherwise inputBody. // 37. Let inputOrInitBody be initBody if it is non-null; otherwise inputBody.
@ -500,17 +500,21 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Request>> Request::construct_impl(JS::Realm
} }
// https://fetch.spec.whatwg.org/#dom-request-method // https://fetch.spec.whatwg.org/#dom-request-method
DeprecatedString Request::method() const WebIDL::ExceptionOr<String> Request::method() const
{ {
auto& vm = this->vm();
// The method getter steps are to return thiss requests method. // The method getter steps are to return thiss requests method.
return DeprecatedString::copy(m_request->method()); return TRY_OR_THROW_OOM(vm, String::from_utf8(m_request->method()));
} }
// https://fetch.spec.whatwg.org/#dom-request-url // https://fetch.spec.whatwg.org/#dom-request-url
DeprecatedString Request::url() const WebIDL::ExceptionOr<String> Request::url() const
{ {
auto& vm = this->vm();
// The url getter steps are to return thiss requests URL, serialized. // The url getter steps are to return thiss requests URL, serialized.
return m_request->url().serialize(); return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_request->url().serialize()));
} }
// https://fetch.spec.whatwg.org/#dom-request-headers // https://fetch.spec.whatwg.org/#dom-request-headers
@ -528,24 +532,25 @@ Bindings::RequestDestination Request::destination() const
} }
// https://fetch.spec.whatwg.org/#dom-request-referrer // https://fetch.spec.whatwg.org/#dom-request-referrer
DeprecatedString Request::referrer() const WebIDL::ExceptionOr<String> Request::referrer() const
{ {
auto& vm = this->vm();
return m_request->referrer().visit( return m_request->referrer().visit(
[&](Infrastructure::Request::Referrer const& referrer) { [&](Infrastructure::Request::Referrer const& referrer) -> WebIDL::ExceptionOr<String> {
switch (referrer) { switch (referrer) {
// 1. If thiss requests referrer is "no-referrer", then return the empty string. // 1. If thiss requests referrer is "no-referrer", then return the empty string.
case Infrastructure::Request::Referrer::NoReferrer: case Infrastructure::Request::Referrer::NoReferrer:
return DeprecatedString::empty(); return String {};
// 2. If thiss requests referrer is "client", then return "about:client". // 2. If thiss requests referrer is "client", then return "about:client".
case Infrastructure::Request::Referrer::Client: case Infrastructure::Request::Referrer::Client:
return DeprecatedString { "about:client"sv }; return TRY_OR_THROW_OOM(vm, "about:client"_string);
default: default:
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
}, },
[&](AK::URL const& url) { [&](AK::URL const& url) -> WebIDL::ExceptionOr<String> {
// 3. Return thiss requests referrer, serialized. // 3. Return thiss requests referrer, serialized.
return url.serialize(); return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(url.serialize()));
}); });
} }
@ -585,10 +590,12 @@ Bindings::RequestRedirect Request::redirect() const
} }
// https://fetch.spec.whatwg.org/#dom-request-integrity // https://fetch.spec.whatwg.org/#dom-request-integrity
DeprecatedString Request::integrity() const WebIDL::ExceptionOr<String> Request::integrity() const
{ {
auto& vm = this->vm();
// The integrity getter steps are to return thiss requests integrity metadata. // The integrity getter steps are to return thiss requests integrity metadata.
return m_request->integrity_metadata(); return TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_request->integrity_metadata()));
} }
// https://fetch.spec.whatwg.org/#dom-request-keepalive // https://fetch.spec.whatwg.org/#dom-request-keepalive

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -19,20 +19,20 @@
namespace Web::Fetch { namespace Web::Fetch {
// https://fetch.spec.whatwg.org/#requestinfo // https://fetch.spec.whatwg.org/#requestinfo
using RequestInfo = Variant<JS::Handle<Request>, DeprecatedString>; using RequestInfo = Variant<JS::Handle<Request>, String>;
// https://fetch.spec.whatwg.org/#requestinit // https://fetch.spec.whatwg.org/#requestinit
struct RequestInit { struct RequestInit {
Optional<DeprecatedString> method; Optional<String> method;
Optional<HeadersInit> headers; Optional<HeadersInit> headers;
Optional<Optional<BodyInit>> body; Optional<Optional<BodyInit>> body;
Optional<DeprecatedString> referrer; Optional<String> referrer;
Optional<Bindings::ReferrerPolicy> referrer_policy; Optional<Bindings::ReferrerPolicy> referrer_policy;
Optional<Bindings::RequestMode> mode; Optional<Bindings::RequestMode> mode;
Optional<Bindings::RequestCredentials> credentials; Optional<Bindings::RequestCredentials> credentials;
Optional<Bindings::RequestCache> cache; Optional<Bindings::RequestCache> cache;
Optional<Bindings::RequestRedirect> redirect; Optional<Bindings::RequestRedirect> redirect;
Optional<DeprecatedString> integrity; Optional<String> integrity;
Optional<bool> keepalive; Optional<bool> keepalive;
Optional<JS::GCPtr<DOM::AbortSignal>> signal; Optional<JS::GCPtr<DOM::AbortSignal>> signal;
Optional<Bindings::RequestDuplex> duplex; Optional<Bindings::RequestDuplex> duplex;
@ -78,17 +78,17 @@ public:
[[nodiscard]] JS::NonnullGCPtr<Infrastructure::Request> request() const { return m_request; } [[nodiscard]] JS::NonnullGCPtr<Infrastructure::Request> request() const { return m_request; }
// JS API functions // JS API functions
[[nodiscard]] DeprecatedString method() const; [[nodiscard]] WebIDL::ExceptionOr<String> method() const;
[[nodiscard]] DeprecatedString url() const; [[nodiscard]] WebIDL::ExceptionOr<String> url() const;
[[nodiscard]] JS::NonnullGCPtr<Headers> headers() const; [[nodiscard]] JS::NonnullGCPtr<Headers> headers() const;
[[nodiscard]] Bindings::RequestDestination destination() const; [[nodiscard]] Bindings::RequestDestination destination() const;
[[nodiscard]] DeprecatedString referrer() const; [[nodiscard]] WebIDL::ExceptionOr<String> referrer() const;
[[nodiscard]] Bindings::ReferrerPolicy referrer_policy() const; [[nodiscard]] Bindings::ReferrerPolicy referrer_policy() const;
[[nodiscard]] Bindings::RequestMode mode() const; [[nodiscard]] Bindings::RequestMode mode() const;
[[nodiscard]] Bindings::RequestCredentials credentials() const; [[nodiscard]] Bindings::RequestCredentials credentials() const;
[[nodiscard]] Bindings::RequestCache cache() const; [[nodiscard]] Bindings::RequestCache cache() const;
[[nodiscard]] Bindings::RequestRedirect redirect() const; [[nodiscard]] Bindings::RequestRedirect redirect() const;
[[nodiscard]] DeprecatedString integrity() const; [[nodiscard]] WebIDL::ExceptionOr<String> integrity() const;
[[nodiscard]] bool keepalive() const; [[nodiscard]] bool keepalive() const;
[[nodiscard]] bool is_reload_navigation() const; [[nodiscard]] bool is_reload_navigation() const;
[[nodiscard]] bool is_history_navigation() const; [[nodiscard]] bool is_history_navigation() const;

View file

@ -6,7 +6,7 @@
typedef (Request or USVString) RequestInfo; typedef (Request or USVString) RequestInfo;
// https://fetch.spec.whatwg.org/#request // https://fetch.spec.whatwg.org/#request
[Exposed=(Window,Worker)] [Exposed=(Window,Worker), UseNewAKString]
interface Request { interface Request {
constructor(RequestInfo input, optional RequestInit init = {}); constructor(RequestInfo input, optional RequestInit init = {});

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -168,7 +168,7 @@ JS::NonnullGCPtr<Response> Response::error(JS::VM& vm)
} }
// https://fetch.spec.whatwg.org/#dom-response-redirect // https://fetch.spec.whatwg.org/#dom-response-redirect
WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(JS::VM& vm, DeprecatedString const& url, u16 status) WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> Response::redirect(JS::VM& vm, String const& url, u16 status)
{ {
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
@ -236,12 +236,14 @@ Bindings::ResponseType Response::type() const
} }
// https://fetch.spec.whatwg.org/#dom-response-url // https://fetch.spec.whatwg.org/#dom-response-url
DeprecatedString Response::url() const WebIDL::ExceptionOr<String> Response::url() const
{ {
auto& vm = this->vm();
// The url getter steps are to return the empty string if thiss responses URL is null; otherwise thiss responses URL, serialized with exclude fragment set to true. // The url getter steps are to return the empty string if thiss responses URL is null; otherwise thiss responses URL, serialized with exclude fragment set to true.
return !m_response->url().has_value() return !m_response->url().has_value()
? DeprecatedString::empty() ? String {}
: m_response->url()->serialize(AK::URL::ExcludeFragment::Yes); : TRY_OR_THROW_OOM(vm, String::from_deprecated_string(m_response->url()->serialize(AK::URL::ExcludeFragment::Yes)));
} }
// https://fetch.spec.whatwg.org/#dom-response-redirected // https://fetch.spec.whatwg.org/#dom-response-redirected
@ -266,10 +268,12 @@ bool Response::ok() const
} }
// https://fetch.spec.whatwg.org/#dom-response-statustext // https://fetch.spec.whatwg.org/#dom-response-statustext
DeprecatedString Response::status_text() const WebIDL::ExceptionOr<String> Response::status_text() const
{ {
auto& vm = this->vm();
// The statusText getter steps are to return thiss responses status message. // The statusText getter steps are to return thiss responses status message.
return DeprecatedString::copy(m_response->status_message()); return TRY_OR_THROW_OOM(vm, String::from_utf8(m_response->status_message()));
} }
// https://fetch.spec.whatwg.org/#dom-response-headers // https://fetch.spec.whatwg.org/#dom-response-headers

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org> * Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -21,7 +21,7 @@ namespace Web::Fetch {
// https://fetch.spec.whatwg.org/#responseinit // https://fetch.spec.whatwg.org/#responseinit
struct ResponseInit { struct ResponseInit {
u16 status; u16 status;
DeprecatedString status_text; String status_text;
Optional<HeadersInit> headers; Optional<HeadersInit> headers;
}; };
@ -46,14 +46,14 @@ public:
// JS API functions // JS API functions
[[nodiscard]] static JS::NonnullGCPtr<Response> error(JS::VM&); [[nodiscard]] static JS::NonnullGCPtr<Response> error(JS::VM&);
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> redirect(JS::VM&, DeprecatedString const& url, u16 status); static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> redirect(JS::VM&, String const& url, u16 status);
[[nodiscard]] static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> json(JS::VM&, JS::Value data, ResponseInit const& init = {}); static WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> json(JS::VM&, JS::Value data, ResponseInit const& init = {});
[[nodiscard]] Bindings::ResponseType type() const; [[nodiscard]] Bindings::ResponseType type() const;
[[nodiscard]] DeprecatedString url() const; [[nodiscard]] WebIDL::ExceptionOr<String> url() const;
[[nodiscard]] bool redirected() const; [[nodiscard]] bool redirected() const;
[[nodiscard]] u16 status() const; [[nodiscard]] u16 status() const;
[[nodiscard]] bool ok() const; [[nodiscard]] bool ok() const;
[[nodiscard]] DeprecatedString status_text() const; [[nodiscard]] WebIDL::ExceptionOr<String> status_text() const;
[[nodiscard]] JS::NonnullGCPtr<Headers> headers() const; [[nodiscard]] JS::NonnullGCPtr<Headers> headers() const;
[[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> clone() const; [[nodiscard]] WebIDL::ExceptionOr<JS::NonnullGCPtr<Response>> clone() const;

View file

@ -2,7 +2,7 @@
#import <Fetch/BodyInit.idl> #import <Fetch/BodyInit.idl>
#import <Fetch/Headers.idl> #import <Fetch/Headers.idl>
[Exposed=(Window,Worker)] [Exposed=(Window,Worker), UseNewAKString]
interface Response { interface Response {
constructor(optional BodyInit? body = null, optional ResponseInit init = {}); constructor(optional BodyInit? body = null, optional ResponseInit init = {});