LibWeb: Implement QueuingStrategy for Web::Streams::WritableStream

This commit is contained in:
Shannon Booth 2023-06-18 21:58:04 +12:00 committed by Andreas Kling
parent 33f6e5d516
commit 9cb4bf0683
Notes: sideshowbarker 2024-07-16 20:12:13 +09:00
3 changed files with 9 additions and 8 deletions

View File

@ -17,7 +17,7 @@
namespace Web::Streams {
// https://streams.spec.whatwg.org/#ws-constructor
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> WritableStream::construct_impl(JS::Realm& realm, Optional<JS::Handle<JS::Object>> const& underlying_sink_object)
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> WritableStream::construct_impl(JS::Realm& realm, Optional<JS::Handle<JS::Object>> const& underlying_sink_object, QueuingStrategy const& strategy)
{
auto& vm = realm.vm();
@ -36,11 +36,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> WritableStream::construct_
// 4. Perform ! InitializeWritableStream(this).
// Note: This AO configures slot values which are already specified in the class's field initializers.
// FIXME: 5. Let sizeAlgorithm be ! ExtractSizeAlgorithm(strategy).
SizeAlgorithm size_algorithm = [](auto const&) { return JS::normal_completion(JS::Value(1)); };
// 5. Let sizeAlgorithm be ! ExtractSizeAlgorithm(strategy).
auto size_algorithm = extract_size_algorithm(strategy);
// FIXME: 6. Let highWaterMark be ? ExtractHighWaterMark(strategy, 1).
auto high_water_mark = 1.0;
// 6. Let highWaterMark be ? ExtractHighWaterMark(strategy, 1).
auto high_water_mark = TRY(extract_high_water_mark(strategy, 1));
// 7. Perform ? SetUpWritableStreamDefaultControllerFromUnderlyingSink(this, underlyingSink, underlyingSinkDict, highWaterMark, sizeAlgorithm).
TRY(set_up_writable_stream_default_controller_from_underlying_sink(*writable_stream, underlying_sink, underlying_sink_dict, high_water_mark, move(size_algorithm)));

View File

@ -11,6 +11,7 @@
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Streams/QueuingStrategy.h>
#include <LibWeb/WebIDL/Promise.h>
namespace Web::Streams {
@ -42,7 +43,7 @@ public:
Errored,
};
static WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> construct_impl(JS::Realm& realm, Optional<JS::Handle<JS::Object>> const& underlying_sink);
static WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStream>> construct_impl(JS::Realm& realm, Optional<JS::Handle<JS::Object>> const& underlying_sink, QueuingStrategy const& = {});
virtual ~WritableStream() = default;

View File

@ -1,9 +1,9 @@
#import <Streams/QueuingStrategy.idl>
#import <Streams/WritableStreamDefaultWriter.idl>
[Exposed=*, Transferable]
interface WritableStream {
// FIXME: optional QueuingStrategy strategy = {}
constructor(optional object underlyingSink);
constructor(optional object underlyingSink, optional QueuingStrategy strategy = {});
readonly attribute boolean locked;