diff options
6 files changed, 79 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index fc7f380299..76dabc2736 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -465,6 +465,7 @@ set(SOURCES SecureContexts/AbstractOperations.cpp Streams/AbstractOperations.cpp Streams/ReadableStream.cpp + Streams/ReadableStreamBYOBRequest.cpp Streams/ReadableStreamDefaultController.cpp Streams/ReadableStreamDefaultReader.cpp Streams/ReadableStreamGenericReader.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index e76773a934..47b0f117d1 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -426,6 +426,7 @@ class Selection; namespace Web::Streams { class ReadableStream; +class ReadableStreamBYOBRequest; class ReadableStreamDefaultController; class ReadableStreamDefaultReader; class ReadableStreamGenericReaderMixin; diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp new file mode 100644 index 0000000000..a73ff2a125 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <LibWeb/Streams/ReadableStreamBYOBRequest.h> + +namespace Web::Streams { + +// https://streams.spec.whatwg.org/#rs-byob-request-view +JS::GCPtr<JS::TypedArrayBase> ReadableStreamBYOBRequest::view() +{ + // 1. Return this.[[view]]. + return m_view; +} + +ReadableStreamBYOBRequest::ReadableStreamBYOBRequest(JS::Realm& realm) + : Bindings::PlatformObject(realm) +{ +} + +void ReadableStreamBYOBRequest::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_controller); + visitor.visit(m_view); +} + +} diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h new file mode 100644 index 0000000000..e60253ad8f --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <LibJS/Runtime/TypedArray.h> +#include <LibWeb/Bindings/PlatformObject.h> + +namespace Web::Streams { + +// https://streams.spec.whatwg.org/#readablestreambyobrequest +class ReadableStreamBYOBRequest : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(ReadableStreamBYOBRequest, Bindings::PlatformObject); + +public: + virtual ~ReadableStreamBYOBRequest() override = default; + + JS::GCPtr<JS::TypedArrayBase> view(); + +private: + explicit ReadableStreamBYOBRequest(JS::Realm&); + + virtual void visit_edges(Cell::Visitor&) override; + + // https://streams.spec.whatwg.org/#readablestreambyobrequest-controller + // The parent ReadableByteStreamController instance + JS::GCPtr<JS::Object> m_controller; + + // https://streams.spec.whatwg.org/#readablestreambyobrequest-view + // A typed array representing the destination region to which the controller can write generated data, or null after the BYOB request has been invalidated. + JS::GCPtr<JS::TypedArrayBase> m_view; +}; + +} diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl new file mode 100644 index 0000000000..916bdc6846 --- /dev/null +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBRequest.idl @@ -0,0 +1,9 @@ +[Exposed=*] +interface ReadableStreamBYOBRequest { + // FIXME: This should be an ArrayBufferView + readonly attribute any? view; + + // FIXME: Implement + // undefined respond([EnforceRange] unsigned long long bytesWritten); + // undefined respondWithNewView(ArrayBufferView view); +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index c99071189e..0374e39b55 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -180,6 +180,7 @@ libweb_js_bindings(PerformanceTimeline/PerformanceEntry) libweb_js_bindings(RequestIdleCallback/IdleDeadline) libweb_js_bindings(ResizeObserver/ResizeObserver) libweb_js_bindings(Streams/ReadableStream) +libweb_js_bindings(Streams/ReadableStreamBYOBRequest) libweb_js_bindings(Streams/ReadableStreamDefaultController) libweb_js_bindings(Streams/ReadableStreamDefaultReader) libweb_js_bindings(Streams/WritableStream) |