|
@@ -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));
|
|
|
+}
|
|
|
+
|
|
|
}
|