mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
LibWeb: Start fleshing out the ReadableStream interface
This is so we can just assume it exists in Fetch APIs (while still skipping functionality that relies on a full implementation, of course).
This commit is contained in:
parent
1ace80235b
commit
87654f5b51
9 changed files with 199 additions and 4 deletions
71
Userland/Libraries/LibWeb/Streams/ReadableStream.cpp
Normal file
71
Userland/Libraries/LibWeb/Streams/ReadableStream.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Streams/AbstractOperations.h>
|
||||
#include <LibWeb/Streams/ReadableStream.h>
|
||||
|
||||
namespace Web::Streams {
|
||||
|
||||
// https://streams.spec.whatwg.org/#rs-constructor
|
||||
DOM::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> ReadableStream::create_with_global_object(HTML::Window& window)
|
||||
{
|
||||
auto* readable_stream = window.heap().allocate<ReadableStream>(window.realm(), window);
|
||||
|
||||
return JS::NonnullGCPtr { *readable_stream };
|
||||
}
|
||||
|
||||
ReadableStream::ReadableStream(HTML::Window& window)
|
||||
: PlatformObject(window.realm())
|
||||
{
|
||||
set_prototype(&window.cached_web_prototype("ReadableStream"));
|
||||
}
|
||||
|
||||
ReadableStream::~ReadableStream() = default;
|
||||
|
||||
void ReadableStream::visit_edges(Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_controller);
|
||||
visitor.visit(m_reader);
|
||||
visitor.visit(m_stored_error);
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-locked
|
||||
bool ReadableStream::is_readable() const
|
||||
{
|
||||
// A ReadableStream stream is readable if stream.[[state]] is "readable".
|
||||
return m_state == State::Readable;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-closed
|
||||
bool ReadableStream::is_closed() const
|
||||
{
|
||||
// A ReadableStream stream is closed if stream.[[state]] is "closed".
|
||||
return m_state == State::Closed;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-errored
|
||||
bool ReadableStream::is_errored() const
|
||||
{
|
||||
// A ReadableStream stream is errored if stream.[[state]] is "errored".
|
||||
return m_state == State::Errored;
|
||||
}
|
||||
// https://streams.spec.whatwg.org/#readablestream-locked
|
||||
bool ReadableStream::is_locked() const
|
||||
{
|
||||
// A ReadableStream stream is locked if ! IsReadableStreamLocked(stream) returns true.
|
||||
return is_readable_stream_locked(*this);
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#is-readable-stream-disturbed
|
||||
bool ReadableStream::is_disturbed() const
|
||||
{
|
||||
// A ReadableStream stream is disturbed if stream.[[disturbed]] is true.
|
||||
return m_disturbed;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue