1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 14:47:35 +00:00

LibWeb: Accept a JS::Value for size in enqueue_value instead of a double

This matches what the spec does, and consolidates all of the size-
related errors in one spot instead of distributing them throughout the
various uses of enqueue_value_with_size()
This commit is contained in:
Matthew Olsson 2023-04-09 15:21:54 -07:00 committed by Linus Groh
parent 1f7f63ae5a
commit 48b67e41f0
2 changed files with 28 additions and 5 deletions

View file

@ -89,6 +89,8 @@ double writable_stream_default_controller_get_desired_size(WritableStreamDefault
WebIDL::ExceptionOr<void> writable_stream_default_controller_process_close(WritableStreamDefaultController&);
WebIDL::ExceptionOr<void> writable_stream_default_controller_process_write(WritableStreamDefaultController&, JS::Value chunk);
bool is_non_negative_number(JS::Value);
JS::Value create_close_sentinel();
bool is_close_sentinel(JS::Value);
JS::ThrowCompletionOr<JS::Handle<WebIDL::CallbackType>> property_to_callback(JS::VM& vm, JS::Value value, JS::PropertyKey const& property_key);
@ -125,13 +127,15 @@ JS::Value dequeue_value(T& container)
// https://streams.spec.whatwg.org/#enqueue-value-with-size
template<typename T>
WebIDL::ExceptionOr<void> enqueue_value_with_size(T& container, JS::Value value, double size)
WebIDL::ExceptionOr<void> enqueue_value_with_size(T& container, JS::Value value, JS::Value size_value)
{
// 1. Assert: container has [[queue]] and [[queueTotalSize]] internal slots.
// 2. If ! IsNonNegativeNumber(size) is false, throw a RangeError exception.
if (size < 0.0)
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Chunk has negative size"sv };
if (!is_non_negative_number(size_value))
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::RangeError, "Chunk has non-positive size"sv };
auto size = size_value.as_double();
// 3. If size is +∞, throw a RangeError exception.
if (size == HUGE_VAL)