From 5a99a6afb40106a72058aabf474231ba956c58f6 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 29 Jan 2024 07:50:36 -0500 Subject: [PATCH] LibWeb: Implement ReadableStreamBYOBRequest.respondWithNewView The AO behind this prototype was added in commit ed1076d9ca12d3ec3492fc, so we can now trivially expose the prototype as well. --- ...bleStreamBYOBReader-respondWithNewView.txt | 4 + ...leStreamBYOBReader-respondWithNewView.html | 80 +++++++++++++++++++ .../Streams/ReadableStreamBYOBRequest.cpp | 17 ++++ .../Streams/ReadableStreamBYOBRequest.h | 1 + .../Streams/ReadableStreamBYOBRequest.idl | 2 +- 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-respondWithNewView.txt create mode 100644 Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-respondWithNewView.html diff --git a/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-respondWithNewView.txt b/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-respondWithNewView.txt new file mode 100644 index 00000000000..72557e8cfe0 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-respondWithNewView.txt @@ -0,0 +1,4 @@ +abcdefghijklmnopqrstuvwxyz +ABCDEFGHIJKLMNOPQRSTUVWXYZ +0123456789!@#$%^&*()-=_+,< +Done! diff --git a/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-respondWithNewView.html b/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-respondWithNewView.html new file mode 100644 index 00000000000..0926b8efe36 --- /dev/null +++ b/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-respondWithNewView.html @@ -0,0 +1,80 @@ + + diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp index f7bc1eacb39..9f53144368c 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp @@ -60,4 +60,21 @@ WebIDL::ExceptionOr ReadableStreamBYOBRequest::respond(WebIDL::UnsignedLon return readable_byte_stream_controller_respond(*m_controller, bytes_written); } +// https://streams.spec.whatwg.org/#rs-byob-request-respond-with-new-view +WebIDL::ExceptionOr ReadableStreamBYOBRequest::respond_with_new_view(JS::Handle const& view) +{ + auto& realm = this->realm(); + + // 1. If this.[[controller]] is undefined, throw a TypeError exception. + if (!m_controller) + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Controller is undefined"_string }; + + // 2. If ! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, throw a TypeError exception. + if (view->viewed_array_buffer()->is_detached()) + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Unable to respond with a detached ArrayBuffer"_string }; + + // 3. Return ? ReadableByteStreamControllerRespondWithNewView(this.[[controller]], view). + return TRY(readable_byte_stream_controller_respond_with_new_view(realm, *m_controller, *view)); +} + } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h index f5a6007b5f9..0bf6e6315fc 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h @@ -30,6 +30,7 @@ public: void set_view(JS::GCPtr value) { m_view = value; } WebIDL::ExceptionOr respond(WebIDL::UnsignedLongLong bytes_written); + WebIDL::ExceptionOr respond_with_new_view(JS::Handle const& view); private: explicit ReadableStreamBYOBRequest(JS::Realm&); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl index 36ce9d8d622..66514449104 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl @@ -4,5 +4,5 @@ interface ReadableStreamBYOBRequest { readonly attribute ArrayBufferView? view; undefined respond([EnforceRange] unsigned long long bytesWritten); - // FIXME: undefined respondWithNewView(ArrayBufferView view); + undefined respondWithNewView(ArrayBufferView view); };