1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:37:35 +00:00

LibWeb: Implement WritableStream.getWriter()

This commit is contained in:
Matthew Olsson 2023-04-02 07:22:11 -07:00 committed by Linus Groh
parent f358ae1b13
commit ae2d67c28b
5 changed files with 27 additions and 1 deletions

View file

@ -738,6 +738,21 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underly
return set_up_readable_stream_default_controller(stream, controller, move(start_algorithm), move(pull_algorithm), move(cancel_algorithm), high_water_mark, move(size_algorithm));
}
// https://streams.spec.whatwg.org/#acquire-writable-stream-default-writer
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writable_stream_default_writer(WritableStream& stream)
{
auto& realm = stream.realm();
// 1. Let writer be a new WritableStreamDefaultWriter.
auto writer = MUST_OR_THROW_OOM(stream.heap().allocate<WritableStreamDefaultWriter>(realm, realm));
// 2. Perform ? SetUpWritableStreamDefaultWriter(writer, stream).
TRY(set_up_writable_stream_default_writer(*writer, stream));
// 3. Return writer.
return writer;
}
// https://streams.spec.whatwg.org/#is-writable-stream-locked
bool is_writable_stream_locked(WritableStream const& stream)
{

View file

@ -53,6 +53,7 @@ bool readable_stream_default_controller_can_close_or_enqueue(ReadableStreamDefau
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStream&, ReadableStreamDefaultController&, StartAlgorithm&&, PullAlgorithm&&, CancelAlgorithm&&, double high_water_mark, SizeAlgorithm&&);
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source_value, UnderlyingSource, double high_water_mark, SizeAlgorithm&&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writable_stream_default_writer(WritableStream&);
bool is_writable_stream_locked(WritableStream const&);
WebIDL::ExceptionOr<void> set_up_writable_stream_default_writer(WritableStreamDefaultWriter&, WritableStream&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(WritableStream&);

View file

@ -76,6 +76,13 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStream::close()
return TRY(writable_stream_close(*this))->promise();
}
// https://streams.spec.whatwg.org/#ws-get-writer
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> WritableStream::get_writer()
{
// 1. Return ? AcquireWritableStreamDefaultWriter(this).
return acquire_writable_stream_default_writer(*this);
}
WritableStream::WritableStream(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{

View file

@ -48,6 +48,7 @@ public:
bool locked() const;
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> close();
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> get_writer();
bool backpressure() const { return m_backpressure; }
void set_backpressure(bool value) { m_backpressure = value; }

View file

@ -1,3 +1,5 @@
#import <Streams/WritableStreamDefaultWriter.idl>
[Exposed=*, Transferable]
interface WritableStream {
// FIXME: optional QueuingStrategy strategy = {}
@ -7,7 +9,7 @@ interface WritableStream {
// FIXME:
// Promise<undefined> abort(optional any reason);
// WritableStreamDefaultWriter getWriter();
Promise<undefined> close();
WritableStreamDefaultWriter getWriter();
};