2022-09-21 23:27:13 +01:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
|
|
|
|
|
*
|
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <AK/Forward.h>
|
|
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
|
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Web::Streams {
|
|
|
|
|
|
|
2023-03-28 18:30:22 -07:00
|
|
|
|
// FIXME: Variant<DefaultReader, ByteStreamReader>
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#typedefdef-readablestreamreader
|
|
|
|
|
|
using ReadableStreamReader = JS::GCPtr<ReadableStreamDefaultReader>;
|
|
|
|
|
|
|
2023-03-28 18:56:11 -07:00
|
|
|
|
// FIXME: Variant<DefaultController, ByteStreamController>
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#typedefdef-readablestreamcontroller
|
|
|
|
|
|
using ReadableStreamController = JS::GCPtr<ReadableStreamDefaultController>;
|
|
|
|
|
|
|
2022-09-21 23:27:13 +01:00
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream
|
|
|
|
|
|
class ReadableStream final : public Bindings::PlatformObject {
|
2022-10-04 18:02:54 +01:00
|
|
|
|
WEB_PLATFORM_OBJECT(ReadableStream, Bindings::PlatformObject);
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
enum class State {
|
|
|
|
|
|
Readable,
|
|
|
|
|
|
Closed,
|
|
|
|
|
|
Errored,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-03-28 19:11:22 -07:00
|
|
|
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> construct_impl(JS::Realm&, Optional<JS::Handle<JS::Object>> const& underlying_source);
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
virtual ~ReadableStream() override;
|
|
|
|
|
|
|
2023-03-28 18:56:11 -07:00
|
|
|
|
ReadableStreamController controller() { return m_controller; }
|
|
|
|
|
|
void set_controller(ReadableStreamController value) { m_controller = value; }
|
|
|
|
|
|
|
2022-09-21 23:27:13 +01:00
|
|
|
|
JS::Value stored_error() const { return m_stored_error; }
|
2023-03-28 18:56:11 -07:00
|
|
|
|
void set_stored_error(JS::Value value) { m_stored_error = value; }
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
2023-03-28 18:30:22 -07:00
|
|
|
|
ReadableStreamReader reader() const { return m_reader; }
|
|
|
|
|
|
void set_reader(ReadableStreamReader value) { m_reader = value; }
|
|
|
|
|
|
|
2023-03-28 18:56:11 -07:00
|
|
|
|
bool is_disturbed() const;
|
|
|
|
|
|
void set_disturbed(bool value) { m_disturbed = value; }
|
|
|
|
|
|
|
2022-09-21 23:27:13 +01:00
|
|
|
|
bool is_readable() const;
|
|
|
|
|
|
bool is_closed() const;
|
|
|
|
|
|
bool is_errored() const;
|
|
|
|
|
|
bool is_locked() const;
|
2023-03-28 17:43:34 -07:00
|
|
|
|
void set_stream_state(State value) { m_state = value; }
|
|
|
|
|
|
|
2022-09-21 23:27:13 +01:00
|
|
|
|
private:
|
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-09-25 18:11:21 -06:00
|
|
|
|
explicit ReadableStream(JS::Realm&);
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
|
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
|
2022-09-21 23:27:13 +01:00
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-controller
|
|
|
|
|
|
// A ReadableStreamDefaultController or ReadableByteStreamController created with the ability to control the state and queue of this stream
|
2023-03-28 18:56:11 -07:00
|
|
|
|
ReadableStreamController m_controller;
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-detached
|
|
|
|
|
|
// A boolean flag set to true when the stream is transferred
|
|
|
|
|
|
bool m_detached { false };
|
|
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-disturbed
|
|
|
|
|
|
// A boolean flag set to true when the stream has been read from or canceled
|
|
|
|
|
|
bool m_disturbed { false };
|
|
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-reader
|
|
|
|
|
|
// A ReadableStreamDefaultReader or ReadableStreamBYOBReader instance, if the stream is locked to a reader, or undefined if it is not
|
2023-03-28 18:30:22 -07:00
|
|
|
|
ReadableStreamReader m_reader;
|
2022-09-21 23:27:13 +01:00
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-state
|
|
|
|
|
|
// A string containing the stream’s current state, used internally; one of "readable", "closed", or "errored"
|
|
|
|
|
|
State m_state { State::Readable };
|
|
|
|
|
|
|
|
|
|
|
|
// https://streams.spec.whatwg.org/#readablestream-storederror
|
|
|
|
|
|
// A value indicating how the stream failed, to be given as a failure reason or exception when trying to operate on an errored stream
|
|
|
|
|
|
JS::Value m_stored_error { JS::js_undefined() };
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|