LibWeb: Implement operation to error a ReadableStream

This commit is contained in:
Timothy Flynn 2024-05-25 16:55:38 -04:00 committed by Andreas Kling
parent 2a2c59e74b
commit 88d46b51ed
Notes: sideshowbarker 2024-07-17 02:38:39 +09:00
2 changed files with 17 additions and 0 deletions

View file

@ -186,6 +186,22 @@ void ReadableStream::close()
});
}
// https://streams.spec.whatwg.org/#readablestream-error
void ReadableStream::error(JS::Value error)
{
controller()->visit(
// 1. If stream.[[controller]] implements ReadableByteStreamController, then perform
// ! ReadableByteStreamControllerError(stream.[[controller]], e).
[&](JS::NonnullGCPtr<ReadableByteStreamController> controller) {
readable_byte_stream_controller_error(controller, error);
},
// 2. Otherwise, perform ! ReadableStreamDefaultControllerError(stream.[[controller]], e).
[&](JS::NonnullGCPtr<ReadableStreamDefaultController> controller) {
readable_stream_default_controller_error(controller, error);
});
}
void ReadableStream::initialize(JS::Realm& realm)
{
Base::initialize(realm);

View file

@ -80,6 +80,7 @@ public:
WebIDL::ExceptionOr<ReadableStreamPair> tee();
void close();
void error(JS::Value);
Optional<ReadableStreamController>& controller() { return m_controller; }
void set_controller(Optional<ReadableStreamController> value) { m_controller = move(value); }