mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
LibWeb: Add ReadableStreamBYOBReader interface
This commit is contained in:
parent
2b269d4a49
commit
e8ad571082
6 changed files with 93 additions and 0 deletions
|
@ -475,6 +475,7 @@ set(SOURCES
|
||||||
Streams/AbstractOperations.cpp
|
Streams/AbstractOperations.cpp
|
||||||
Streams/ReadableByteStreamController.cpp
|
Streams/ReadableByteStreamController.cpp
|
||||||
Streams/ReadableStream.cpp
|
Streams/ReadableStream.cpp
|
||||||
|
Streams/ReadableStreamBYOBReader.cpp
|
||||||
Streams/ReadableStreamBYOBRequest.cpp
|
Streams/ReadableStreamBYOBRequest.cpp
|
||||||
Streams/ReadableStreamDefaultController.cpp
|
Streams/ReadableStreamDefaultController.cpp
|
||||||
Streams/ReadableStreamDefaultReader.cpp
|
Streams/ReadableStreamDefaultReader.cpp
|
||||||
|
|
|
@ -509,6 +509,7 @@ class Selection;
|
||||||
namespace Web::Streams {
|
namespace Web::Streams {
|
||||||
class ReadableByteStreamController;
|
class ReadableByteStreamController;
|
||||||
class ReadableStream;
|
class ReadableStream;
|
||||||
|
class ReadableStreamBYOBReader;
|
||||||
class ReadableStreamBYOBRequest;
|
class ReadableStreamBYOBRequest;
|
||||||
class ReadableStreamDefaultController;
|
class ReadableStreamDefaultController;
|
||||||
class ReadableStreamDefaultReader;
|
class ReadableStreamDefaultReader;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/PromiseCapability.h>
|
||||||
|
#include <LibWeb/Streams/ReadableStream.h>
|
||||||
|
#include <LibWeb/Streams/ReadableStreamBYOBReader.h>
|
||||||
|
|
||||||
|
namespace Web::Streams {
|
||||||
|
|
||||||
|
ReadableStreamBYOBReader::ReadableStreamBYOBReader(JS::Realm& realm)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
, ReadableStreamGenericReaderMixin(realm)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadableStreamBYOBReader::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
ReadableStreamGenericReaderMixin::visit_edges(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h
Normal file
54
Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Matthew Olsson <mattco@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Forward.h>
|
||||||
|
#include <AK/Function.h>
|
||||||
|
#include <LibJS/Forward.h>
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/Forward.h>
|
||||||
|
#include <LibWeb/Streams/ReadableStreamGenericReader.h>
|
||||||
|
|
||||||
|
namespace Web::Streams {
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#read-into-request
|
||||||
|
class ReadIntoRequest : public RefCounted<ReadIntoRequest> {
|
||||||
|
public:
|
||||||
|
virtual ~ReadIntoRequest() = default;
|
||||||
|
|
||||||
|
// An algorithm taking a chunk, called when a chunk is available for reading
|
||||||
|
virtual void on_chunk(JS::Value chunk) = 0;
|
||||||
|
|
||||||
|
// An algorithm taking a chunk or undefined, called when no chunks are available because the stream is closed
|
||||||
|
virtual void on_close(JS::Value chunk_or_undefined) = 0;
|
||||||
|
|
||||||
|
// An algorithm taking a JavaScript value, called when no chunks are available because the stream is errored
|
||||||
|
virtual void on_error(JS::Value error) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#readablestreambyobreader
|
||||||
|
class ReadableStreamBYOBReader final
|
||||||
|
: public Bindings::PlatformObject
|
||||||
|
, public ReadableStreamGenericReaderMixin {
|
||||||
|
WEB_PLATFORM_OBJECT(ReadableStreamBYOBReader, Bindings::PlatformObject);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ReadableStreamBYOBReader() override = default;
|
||||||
|
|
||||||
|
Vector<NonnullRefPtr<ReadIntoRequest>>& read_into_requests() { return m_read_into_requests; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit ReadableStreamBYOBReader(JS::Realm&);
|
||||||
|
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
// https://streams.spec.whatwg.org/#readablestreambyobreader-readintorequests
|
||||||
|
// A list of read-into requests, used when a consumer requests chunks sooner than they are available
|
||||||
|
Vector<NonnullRefPtr<ReadIntoRequest>> m_read_into_requests;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#import <Streams/ReadableStreamGenericReader.idl>
|
||||||
|
|
||||||
|
[Exposed=*]
|
||||||
|
interface ReadableStreamBYOBReader {
|
||||||
|
// FIXME: Implement
|
||||||
|
// constructor(ReadableStream stream);
|
||||||
|
|
||||||
|
// Promise<ReadableStreamReadResult> read(ArrayBufferView view);
|
||||||
|
// undefined releaseLock();
|
||||||
|
};
|
||||||
|
ReadableStreamBYOBReader includes ReadableStreamGenericReader;
|
|
@ -184,6 +184,7 @@ libweb_js_bindings(RequestIdleCallback/IdleDeadline)
|
||||||
libweb_js_bindings(ResizeObserver/ResizeObserver)
|
libweb_js_bindings(ResizeObserver/ResizeObserver)
|
||||||
libweb_js_bindings(Streams/ReadableByteStreamController)
|
libweb_js_bindings(Streams/ReadableByteStreamController)
|
||||||
libweb_js_bindings(Streams/ReadableStream)
|
libweb_js_bindings(Streams/ReadableStream)
|
||||||
|
libweb_js_bindings(Streams/ReadableStreamBYOBReader)
|
||||||
libweb_js_bindings(Streams/ReadableStreamBYOBRequest)
|
libweb_js_bindings(Streams/ReadableStreamBYOBRequest)
|
||||||
libweb_js_bindings(Streams/ReadableStreamDefaultController)
|
libweb_js_bindings(Streams/ReadableStreamDefaultController)
|
||||||
libweb_js_bindings(Streams/ReadableStreamDefaultReader)
|
libweb_js_bindings(Streams/ReadableStreamDefaultReader)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue