1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:47:35 +00:00

LibWeb/Fetch: Port infrastructure to new String

This commit is contained in:
Linus Groh 2023-03-02 23:26:35 +00:00
parent 7f9ddcf420
commit 11023a3c53
20 changed files with 144 additions and 142 deletions

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
*/
@ -41,14 +41,15 @@ WebIDL::ExceptionOr<Body> Body::clone() const
}
// https://fetch.spec.whatwg.org/#fully-reading-body-as-promise
JS::NonnullGCPtr<WebIDL::Promise> Body::fully_read_as_promise() const
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> Body::fully_read_as_promise() const
{
auto& vm = Bindings::main_thread_vm();
auto& realm = *vm.current_realm();
// FIXME: Implement the streams spec - this is completely made up for now :^)
if (auto const* byte_buffer = m_source.get_pointer<ByteBuffer>()) {
auto result = DeprecatedString::copy(*byte_buffer);
// FIXME: The buffer may or may not be valid UTF-8.
auto result = TRY_OR_THROW_OOM(vm, String::from_utf8(*byte_buffer));
return WebIDL::create_resolved_promise(realm, JS::PrimitiveString::create(vm, move(result)));
}
// Empty, Blob, FormData