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

LibWeb: Implement Streams AO ExtractHighWaterMark(strategy, defaultHWM)

This commit is contained in:
Shannon Booth 2023-06-18 21:45:39 +12:00 committed by Andreas Kling
parent e1d71454eb
commit 9ea597016a
2 changed files with 21 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <LibWeb/Bindings/ExceptionOrUtils.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/QueuingStrategy.h>
#include <LibWeb/Streams/ReadableByteStreamController.h>
#include <LibWeb/Streams/ReadableStream.h>
#include <LibWeb/Streams/ReadableStreamBYOBReader.h>
@ -186,6 +187,24 @@ bool readable_stream_has_default_reader(ReadableStream const& stream)
return false;
}
// https://streams.spec.whatwg.org/#validate-and-normalize-high-water-mark
WebIDL::ExceptionOr<double> extract_high_water_mark(QueuingStrategy const& strategy, double default_hwm)
{
// 1. If strategy["highWaterMark"] does not exist, return defaultHWM.
if (!strategy.high_water_mark.has_value())
return default_hwm;
// 2. Let highWaterMark be strategy["highWaterMark"].
auto high_water_mark = strategy.high_water_mark.value();
// 3. If highWaterMark is NaN or highWaterMark < 0, throw a RangeError exception.
if (isnan(high_water_mark) || high_water_mark < 0)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Invalid value for high water mark"sv };
// 4. Return highWaterMark.
return high_water_mark;
}
// https://streams.spec.whatwg.org/#readable-stream-close
void readable_stream_close(ReadableStream& stream)
{