From feb7fbb95db8f6765d8f55f21a9f9074d2f6c609 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 2 Dec 2023 21:30:36 +1300 Subject: [PATCH] LibWeb: Implement ReadableStreamBYOBRequest.respond The parameter in IDL is left as an unsigned long instead of an unsigned long long as the IDL generator does not currently support that. --- .../Streams/ReadableStreamBYOBRequest.cpp | 20 +++++++++++++++++++ .../Streams/ReadableStreamBYOBRequest.h | 2 ++ .../Streams/ReadableStreamBYOBRequest.idl | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp index fc0437e9e3..d2fe96fe05 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp @@ -39,4 +39,24 @@ void ReadableStreamBYOBRequest::visit_edges(Cell::Visitor& visitor) visitor.visit(m_view); } +WebIDL::ExceptionOr ReadableStreamBYOBRequest::respond(u64 bytes_written) +{ + // 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(this.[[view]].[[ArrayBuffer]]) is true, throw a TypeError exception. + if (m_view->viewed_array_buffer()->is_detached()) + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Unable to respond to detached ArrayBuffer"_string }; + + // 3. Assert: this.[[view]].[[ByteLength]] > 0. + VERIFY(m_view->viewed_array_buffer()->byte_length() > 0); + + // 4. Assert: this.[[view]].[[ViewedArrayBuffer]].[[ByteLength]] > 0. + VERIFY(m_view->viewed_array_buffer()->byte_length() > 0); + + // 5. Perform ? ReadableByteStreamControllerRespond(this.[[controller]], bytesWritten). + return readable_byte_stream_controller_respond(*m_controller, bytes_written); +} + } diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h index 9d4450d70a..6f651e9169 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h @@ -28,6 +28,8 @@ public: void set_view(JS::GCPtr value) { m_view = value; } + WebIDL::ExceptionOr respond(u64 bytes_written); + private: explicit ReadableStreamBYOBRequest(JS::Realm&); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl index 9efd281b8e..a84671a484 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl @@ -3,6 +3,7 @@ interface ReadableStreamBYOBRequest { readonly attribute ArrayBufferView? view; - // FIXME: undefined respond([EnforceRange] unsigned long long bytesWritten); + // FIXME: Should be unsigned long long + undefined respond([EnforceRange] unsigned long bytesWritten); // FIXME: undefined respondWithNewView(ArrayBufferView view); };