mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
LibWeb: Stub out Fetch::Infrastructure::Body::fully_read_as_promise()
This commit is contained in:
parent
a7164f2674
commit
924d7721f0
2 changed files with 19 additions and 0 deletions
|
@ -4,8 +4,10 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/PromiseReaction.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
#include <LibWeb/Fetch/Infrastructure/HTTP/Bodies.h>
|
||||||
|
#include <LibWeb/WebIDL/Promise.h>
|
||||||
|
|
||||||
namespace Web::Fetch::Infrastructure {
|
namespace Web::Fetch::Infrastructure {
|
||||||
|
|
||||||
|
@ -38,4 +40,19 @@ WebIDL::ExceptionOr<Body> Body::clone() const
|
||||||
return Body { JS::make_handle(out2), m_source, m_length };
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] WebIDL::ExceptionOr<Body> clone() const;
|
[[nodiscard]] WebIDL::ExceptionOr<Body> clone() const;
|
||||||
|
|
||||||
|
[[nodiscard]] JS::PromiseCapability fully_read_as_promise() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// https://fetch.spec.whatwg.org/#concept-body-stream
|
// https://fetch.spec.whatwg.org/#concept-body-stream
|
||||||
// A stream (a ReadableStream object).
|
// A stream (a ReadableStream object).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue