From 6b88fc2e053be0bf0fa082aa3f900b9e6a4d46c0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Thu, 28 Dec 2023 11:47:56 +1300 Subject: [PATCH] LibWeb: Properly convert UnderlyingSource's autoAllocateChunkSize to u64 The JS::Value being passed through is not a bigint, and needs to be converted using ConvertToInt, as per: https://webidl.spec.whatwg.org/#es-unsigned-long-long Furthermore, the IDL definition also specifies that this is associated with the [EnforceRange] extended attribute. This makes it actually possible to pass through an autoAllocateChunkSize to the ReadableStream constructor without it throwing a TypeError. --- ...eadableStream-autoAllocateChunkSize-constructor.txt | 1 + ...adableStream-autoAllocateChunkSize-constructor.html | 10 ++++++++++ Userland/Libraries/LibWeb/Streams/UnderlyingSource.cpp | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/Streams/ReadableStream-autoAllocateChunkSize-constructor.txt create mode 100644 Tests/LibWeb/Text/input/Streams/ReadableStream-autoAllocateChunkSize-constructor.html diff --git a/Tests/LibWeb/Text/expected/Streams/ReadableStream-autoAllocateChunkSize-constructor.txt b/Tests/LibWeb/Text/expected/Streams/ReadableStream-autoAllocateChunkSize-constructor.txt new file mode 100644 index 0000000000..1c2dbd9464 --- /dev/null +++ b/Tests/LibWeb/Text/expected/Streams/ReadableStream-autoAllocateChunkSize-constructor.txt @@ -0,0 +1 @@ +PASS. Made: ReadableStream diff --git a/Tests/LibWeb/Text/input/Streams/ReadableStream-autoAllocateChunkSize-constructor.html b/Tests/LibWeb/Text/input/Streams/ReadableStream-autoAllocateChunkSize-constructor.html new file mode 100644 index 0000000000..73843944f9 --- /dev/null +++ b/Tests/LibWeb/Text/input/Streams/ReadableStream-autoAllocateChunkSize-constructor.html @@ -0,0 +1,10 @@ + + diff --git a/Userland/Libraries/LibWeb/Streams/UnderlyingSource.cpp b/Userland/Libraries/LibWeb/Streams/UnderlyingSource.cpp index ec6846f4ca..644f468b8d 100644 --- a/Userland/Libraries/LibWeb/Streams/UnderlyingSource.cpp +++ b/Userland/Libraries/LibWeb/Streams/UnderlyingSource.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2023, Matthew Olsson + * Copyright (c) 2023, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,7 +8,9 @@ #include #include #include +#include #include +#include namespace Web::Streams { @@ -35,8 +38,10 @@ JS::ThrowCompletionOr UnderlyingSource::from_value(JS::VM& vm, return vm.throw_completion(ByteString::formatted("Unknown stream type '{}'", type_value)); } - if (TRY(object.has_property("autoAllocateChunkSize"))) - underlying_source.auto_allocate_chunk_size = TRY(TRY(object.get("autoAllocateChunkSize")).to_bigint_uint64(vm)); + if (TRY(object.has_property("autoAllocateChunkSize"))) { + auto value = TRY(object.get("autoAllocateChunkSize")); + underlying_source.auto_allocate_chunk_size = TRY(WebIDL::convert_to_int(vm, value, WebIDL::EnforceRange::Yes)); + } return underlying_source; }