1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:18:12 +00:00

LibWeb: Stub out Fetch::Infrastructure::Body::fully_read_as_promise()

This commit is contained in:
Linus Groh 2022-09-25 19:27:02 +01:00
parent a7164f2674
commit 924d7721f0
2 changed files with 19 additions and 0 deletions

View file

@ -4,8 +4,10 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/PromiseReaction.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::Fetch::Infrastructure {
@ -38,4 +40,19 @@ WebIDL::ExceptionOr<Body> Body::clone() const
return Body { JS::make_handle(out2), m_source, m_length };
}
// https://fetch.spec.whatwg.org/#fully-reading-body-as-promise
JS::PromiseCapability 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 = String::copy(*byte_buffer);
return WebIDL::create_resolved_promise(realm, JS::js_string(vm, move(result)));
}
// Empty, Blob, FormData
return WebIDL::create_rejected_promise(realm, JS::InternalError::create(realm, "Reading body isn't fully implemented"sv));
}
}