mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
LibWeb: Implement Streams AO ExtractHighWaterMark(strategy, defaultHWM)
This commit is contained in:
parent
e1d71454eb
commit
9ea597016a
2 changed files with 21 additions and 0 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
#include <LibWeb/Bindings/ExceptionOrUtils.h>
|
||||||
#include <LibWeb/DOM/AbortSignal.h>
|
#include <LibWeb/DOM/AbortSignal.h>
|
||||||
#include <LibWeb/Streams/AbstractOperations.h>
|
#include <LibWeb/Streams/AbstractOperations.h>
|
||||||
|
#include <LibWeb/Streams/QueuingStrategy.h>
|
||||||
#include <LibWeb/Streams/ReadableByteStreamController.h>
|
#include <LibWeb/Streams/ReadableByteStreamController.h>
|
||||||
#include <LibWeb/Streams/ReadableStream.h>
|
#include <LibWeb/Streams/ReadableStream.h>
|
||||||
#include <LibWeb/Streams/ReadableStreamBYOBReader.h>
|
#include <LibWeb/Streams/ReadableStreamBYOBReader.h>
|
||||||
|
@ -186,6 +187,24 @@ bool readable_stream_has_default_reader(ReadableStream const& stream)
|
||||||
return false;
|
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
|
// https://streams.spec.whatwg.org/#readable-stream-close
|
||||||
void readable_stream_close(ReadableStream& stream)
|
void readable_stream_close(ReadableStream& stream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,8 @@ using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<Web
|
||||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStreamDefaultReader>> acquire_readable_stream_default_reader(ReadableStream&);
|
||||||
bool is_readable_stream_locked(ReadableStream const&);
|
bool is_readable_stream_locked(ReadableStream const&);
|
||||||
|
|
||||||
|
WebIDL::ExceptionOr<double> extract_high_water_mark(QueuingStrategy const&, double default_hwm);
|
||||||
|
|
||||||
void readable_stream_close(ReadableStream&);
|
void readable_stream_close(ReadableStream&);
|
||||||
void readable_stream_error(ReadableStream&, JS::Value error);
|
void readable_stream_error(ReadableStream&, JS::Value error);
|
||||||
void readable_stream_add_read_request(ReadableStream&, ReadRequest const&);
|
void readable_stream_add_read_request(ReadableStream&, ReadRequest const&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue