diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index f8bda1e1e9..9f67644251 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -1741,6 +1741,25 @@ WebIDL::ExceptionOr> create_readable_stream(JS: return stream; } +// https://streams.spec.whatwg.org/#abstract-opdef-createreadablebytestream +WebIDL::ExceptionOr> create_readable_byte_stream(JS::Realm& realm, StartAlgorithm&& start_algorithm, PullAlgorithm&& pull_algorithm, CancelAlgorithm&& cancel_algorithm) +{ + // 1. Let stream be a new ReadableStream. + auto stream = realm.heap().allocate(realm, realm); + + // 2. Perform ! InitializeReadableStream(stream). + initialize_readable_stream(*stream); + + // 3. Let controller be a new ReadableByteStreamController. + auto controller = realm.heap().allocate(realm, realm); + + // 4. Perform ? SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithm, cancelAlgorithm, 0, undefined). + TRY(set_up_readable_byte_stream_controller(stream, controller, move(start_algorithm), move(pull_algorithm), move(cancel_algorithm), 0, JS::js_undefined())); + + // 5. Return stream. + return stream; +} + // https://streams.spec.whatwg.org/#create-writable-stream WebIDL::ExceptionOr> create_writable_stream(JS::Realm& realm, StartAlgorithm&& start_algorithm, WriteAlgorithm&& write_algorithm, CloseAlgorithm&& close_algorithm, AbortAlgorithm&& abort_algorithm, double high_water_mark, SizeAlgorithm&& size_algorithm) { diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index d7d2be43eb..b9bd9d1892 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -109,6 +109,7 @@ void readable_byte_stream_controller_invalidate_byob_request(ReadableByteStreamC bool readable_byte_stream_controller_should_call_pull(ReadableByteStreamController const&); WebIDL::ExceptionOr> create_readable_stream(JS::Realm& realm, StartAlgorithm&& start_algorithm, PullAlgorithm&& pull_algorithm, CancelAlgorithm&& cancel_algorithm, Optional high_water_mark = {}, Optional&& size_algorithm = {}); +WebIDL::ExceptionOr> create_readable_byte_stream(JS::Realm& realm, StartAlgorithm&& start_algorithm, PullAlgorithm&& pull_algorithm, CancelAlgorithm&& cancel_algorithm); WebIDL::ExceptionOr> create_writable_stream(JS::Realm& realm, StartAlgorithm&& start_algorithm, WriteAlgorithm&& write_algorithm, CloseAlgorithm&& close_algorithm, AbortAlgorithm&& abort_algorithm, double high_water_mark, SizeAlgorithm&& size_algorithm); void initialize_readable_stream(ReadableStream&); void initialize_writable_stream(WritableStream&);