LibWeb: Implement Streams AO ExtractSizeAlgorithm(strategy)

This commit is contained in:
Shannon Booth 2023-06-18 21:54:40 +12:00 committed by Andreas Kling
parent 060c130c82
commit 33f6e5d516
Notes: sideshowbarker 2024-07-17 22:09:47 +09:00
2 changed files with 15 additions and 0 deletions

View File

@ -187,6 +187,20 @@ bool readable_stream_has_default_reader(ReadableStream const& stream)
return false;
}
// https://streams.spec.whatwg.org/#make-size-algorithm-from-size-function
SizeAlgorithm extract_size_algorithm(QueuingStrategy const& strategy)
{
// 1. If strategy["size"] does not exist, return an algorithm that returns 1.
if (!strategy.size)
return [](auto const&) { return JS::normal_completion(JS::Value(1)); };
// 2. Return an algorithm that performs the following steps, taking a chunk argument:
return [strategy](auto const& chunk) {
// 1. Return the result of invoking strategy["size"] with argument list « chunk ».
return WebIDL::invoke_callback(*strategy.size, JS::js_undefined(), chunk);
};
}
// https://streams.spec.whatwg.org/#validate-and-normalize-high-water-mark
WebIDL::ExceptionOr<double> extract_high_water_mark(QueuingStrategy const& strategy, double default_hwm)
{

View File

@ -28,6 +28,7 @@ using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<Web
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
bool is_readable_stream_locked(ReadableStream const&);
SizeAlgorithm extract_size_algorithm(QueuingStrategy const&);
WebIDL::ExceptionOr<double> extract_high_water_mark(QueuingStrategy const&, double default_hwm);
void readable_stream_close(ReadableStream&);