Skip to content

Commit 88d46b5

Browse files
trflynn89awesomekling
authored andcommitted
LibWeb: Implement operation to error a ReadableStream
1 parent 2a2c59e commit 88d46b5

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Userland/Libraries/LibWeb/Streams/ReadableStream.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,22 @@ void ReadableStream::close()
186186
});
187187
}
188188

189+
// https://streams.spec.whatwg.org/#readablestream-error
190+
void ReadableStream::error(JS::Value error)
191+
{
192+
controller()->visit(
193+
// 1. If stream.[[controller]] implements ReadableByteStreamController, then perform
194+
// ! ReadableByteStreamControllerError(stream.[[controller]], e).
195+
[&](JS::NonnullGCPtr<ReadableByteStreamController> controller) {
196+
readable_byte_stream_controller_error(controller, error);
197+
},
198+
199+
// 2. Otherwise, perform ! ReadableStreamDefaultControllerError(stream.[[controller]], e).
200+
[&](JS::NonnullGCPtr<ReadableStreamDefaultController> controller) {
201+
readable_stream_default_controller_error(controller, error);
202+
});
203+
}
204+
189205
void ReadableStream::initialize(JS::Realm& realm)
190206
{
191207
Base::initialize(realm);

Userland/Libraries/LibWeb/Streams/ReadableStream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class ReadableStream final : public Bindings::PlatformObject {
8080
WebIDL::ExceptionOr<ReadableStreamPair> tee();
8181

8282
void close();
83+
void error(JS::Value);
8384

8485
Optional<ReadableStreamController>& controller() { return m_controller; }
8586
void set_controller(Optional<ReadableStreamController> value) { m_controller = move(value); }

0 commit comments

Comments
 (0)