1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:17:35 +00:00

LibWeb: Add ReadableStreamBYOBRequest interface

This commit is contained in:
Matthew Olsson 2023-04-10 18:37:27 -07:00 committed by Linus Groh
parent dc5f213fa0
commit c7aa4fa166
6 changed files with 79 additions and 0 deletions

View file

@ -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

View file

@ -426,6 +426,7 @@ class Selection;
namespace Web::Streams {
class ReadableStream;
class ReadableStreamBYOBRequest;
class ReadableStreamDefaultController;
class ReadableStreamDefaultReader;
class ReadableStreamGenericReaderMixin;

View file

@ -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);
}
}

View file

@ -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;
};
}

View file

@ -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);
};

View file

@ -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)