mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:08:13 +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:
parent
1f7f63ae5a
commit
48b67e41f0
2 changed files with 28 additions and 5 deletions
|
@ -453,7 +453,7 @@ WebIDL::ExceptionOr<void> readable_stream_default_controller_enqueue(ReadableStr
|
|||
}
|
||||
|
||||
// 3. Let chunkSize be result.[[Value]].
|
||||
auto chunk_size = TRY(result.release_value().release_value().to_double(vm));
|
||||
auto chunk_size = result.release_value().release_value();
|
||||
|
||||
// 4. Let enqueueResult be EnqueueValueWithSize(controller, chunk, chunkSize).
|
||||
auto enqueue_result = enqueue_value_with_size(controller, chunk, chunk_size);
|
||||
|
@ -1489,7 +1489,7 @@ void writable_stream_default_controller_clear_algorithms(WritableStreamDefaultCo
|
|||
WebIDL::ExceptionOr<void> writable_stream_default_controller_close(WritableStreamDefaultController& controller)
|
||||
{
|
||||
// 1. Perform ! EnqueueValueWithSize(controller, close sentinel, 0).
|
||||
TRY(enqueue_value_with_size(controller, create_close_sentinel(), 0.0));
|
||||
TRY(enqueue_value_with_size(controller, create_close_sentinel(), JS::Value(0.0)));
|
||||
|
||||
// 2. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller).
|
||||
TRY(writable_stream_default_controller_advance_queue_if_needed(controller));
|
||||
|
@ -1626,6 +1626,25 @@ WebIDL::ExceptionOr<void> writable_stream_default_controller_process_write(Writa
|
|||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#is-non-negative-number
|
||||
bool is_non_negative_number(JS::Value value)
|
||||
{
|
||||
// 1. If Type(v) is not Number, return false.
|
||||
if (!value.is_number())
|
||||
return false;
|
||||
|
||||
// 2. If v is NaN, return false.
|
||||
if (value.is_nan())
|
||||
return false;
|
||||
|
||||
// 3. If v < 0, return false.
|
||||
if (value.as_double() < 0.0)
|
||||
return false;
|
||||
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#close-sentinel
|
||||
// Non-standard function that implements the "close sentinel" value.
|
||||
JS::Value create_close_sentinel()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue