diff --git a/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-read.txt b/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-read.txt index 17d0a84eda6..ddfdccff1e0 100644 --- a/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-read.txt +++ b/Tests/LibWeb/Text/expected/Streams/ReadableStreamBYOBReader-read.txt @@ -1,3 +1,6 @@ -About to read! [object ReadableStreamBYOBReader] +About to read into Uint8Array with [object ReadableStreamBYOBReader] +Total bytes: 34 +'This is some data to be read! 🦬' +About to read into DataView with [object ReadableStreamBYOBReader] Total bytes: 34 'This is some data to be read! 🦬' diff --git a/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-read.html b/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-read.html index 21ae02065f0..773422df51e 100644 --- a/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-read.html +++ b/Tests/LibWeb/Text/input/Streams/ReadableStreamBYOBReader-read.html @@ -1,6 +1,6 @@ diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index c0330becb7c..bcce3268004 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -659,15 +660,11 @@ JS::Value readable_byte_stream_controller_convert_pull_into_descriptor(JS::Realm } // https://streams.spec.whatwg.org/#readable-byte-stream-controller-pull-into -void readable_byte_stream_controller_pull_into(ReadableByteStreamController& controller, JS::Value view_value, ReadIntoRequest& read_into_request) +void readable_byte_stream_controller_pull_into(ReadableByteStreamController& controller, WebIDL::ArrayBufferView& view, ReadIntoRequest& read_into_request) { auto& vm = controller.vm(); auto& realm = controller.realm(); - // FIXME: Support DataView - auto& view_object = view_value.as_object(); - auto const& view = verify_cast(view_object); - // 1. Let stream be controller.[[stream]]. auto stream = controller.stream(); @@ -678,32 +675,34 @@ void readable_byte_stream_controller_pull_into(ReadableByteStreamController& con JS::NativeFunction* ctor = realm.intrinsics().data_view_constructor(); // 4. If view has a [[TypedArrayName]] internal slot (i.e., it is not a DataView), - if (!is(view_object)) { + if (view.bufferable_object().has>()) { + auto const& typed_array = view.bufferable_object().get>(); + // 1. Set elementSize to the element size specified in the typed array constructors table for view.[[TypedArrayName]]. - element_size = view.element_size(); + element_size = typed_array->element_size(); // 2. Set ctor to the constructor specified in the typed array constructors table for view.[[TypedArrayName]]. - if (is(view_object)) + if (is(*typed_array)) ctor = realm.intrinsics().int16_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().int32_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().int8_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().uint8_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().uint16_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().uint32_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().uint8_clamped_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().big_int64_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().big_uint64_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().float32_array_constructor(); - else if (is(view_object)) + else if (is(*typed_array)) ctor = realm.intrinsics().float64_array_constructor(); else VERIFY_NOT_REACHED(); @@ -812,7 +811,7 @@ void readable_byte_stream_controller_pull_into(ReadableByteStreamController& con } // https://streams.spec.whatwg.org/#readable-stream-byob-reader-read -void readable_stream_byob_reader_read(ReadableStreamBYOBReader& reader, JS::Value view, ReadIntoRequest& read_into_request) +void readable_stream_byob_reader_read(ReadableStreamBYOBReader& reader, WebIDL::ArrayBufferView& view, ReadIntoRequest& read_into_request) { // 1. Let stream be reader.[[stream]]. auto stream = reader.stream(); diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index bee6689110f..cfa401de28f 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -54,8 +54,8 @@ WebIDL::ExceptionOr readable_stream_reader_generic_release(ReadableStreamG void readable_stream_default_reader_error_read_requests(ReadableStreamDefaultReader&, JS::Value error); void readable_stream_byob_reader_error_read_into_requests(ReadableStreamBYOBReader&, JS::Value error); JS::Value readable_byte_stream_controller_convert_pull_into_descriptor(JS::Realm&, PullIntoDescriptor const&); -void readable_byte_stream_controller_pull_into(ReadableByteStreamController&, JS::Value view_value, ReadIntoRequest&); -void readable_stream_byob_reader_read(ReadableStreamBYOBReader&, JS::Value view, ReadIntoRequest&); +void readable_byte_stream_controller_pull_into(ReadableByteStreamController&, WebIDL::ArrayBufferView&, ReadIntoRequest&); +void readable_stream_byob_reader_read(ReadableStreamBYOBReader&, WebIDL::ArrayBufferView&, ReadIntoRequest&); void readable_byte_stream_controller_fill_head_pull_into_descriptor(ReadableByteStreamController const&, u64 size, PullIntoDescriptor&); WebIDL::ExceptionOr readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.cpp b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.cpp index 5d1345a2efa..cfcac0d9895 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include namespace Web::Streams { @@ -103,29 +104,26 @@ private: }; // https://streams.spec.whatwg.org/#byob-reader-read -WebIDL::ExceptionOr> ReadableStreamBYOBReader::read(JS::Value view_value) +WebIDL::ExceptionOr> ReadableStreamBYOBReader::read(JS::Handle& view) { auto& realm = this->realm(); - // FIXME: Support DataViews - auto& view = verify_cast(view_value.as_object()); - // 1. If view.[[ByteLength]] is 0, return a promise rejected with a TypeError exception. - if (view.byte_length() == 0) { + if (view->byte_length() == 0) { auto exception = JS::TypeError::create(realm, "Cannot read in an empty buffer"sv); auto promise_capability = WebIDL::create_rejected_promise(realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise()) }; } // 2. If view.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is 0, return a promise rejected with a TypeError exception. - if (view.viewed_array_buffer()->byte_length() == 0) { + if (view->viewed_array_buffer()->byte_length() == 0) { auto exception = JS::TypeError::create(realm, "Cannot read in an empty buffer"sv); auto promise_capability = WebIDL::create_rejected_promise(realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise()) }; } // 3. If ! IsDetachedBuffer(view.[[ViewedArrayBuffer]]) is true, return a promise rejected with a TypeError exception. - if (view.viewed_array_buffer()->is_detached()) { + if (view->viewed_array_buffer()->is_detached()) { auto exception = JS::TypeError::create(realm, "Cannot read in a detached buffer"sv); auto promise_capability = WebIDL::create_rejected_promise(realm, exception); return JS::NonnullGCPtr { verify_cast(*promise_capability->promise()) }; @@ -151,7 +149,7 @@ WebIDL::ExceptionOr> ReadableStreamBYOBReader::rea auto read_into_request = heap().allocate_without_realm(realm, promise_capability); // 7. Perform ! ReadableStreamBYOBReaderRead(this, view, readIntoRequest). - readable_stream_byob_reader_read(*this, view_value, *read_into_request); + readable_stream_byob_reader_read(*this, *view, *read_into_request); // 8. Return promise. return JS::NonnullGCPtr { verify_cast(*promise_capability->promise()) }; diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h index 2a7ba2cf272..9fc15f5cd0c 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.h @@ -45,7 +45,7 @@ public: virtual ~ReadableStreamBYOBReader() override = default; - WebIDL::ExceptionOr> read(JS::Value); + WebIDL::ExceptionOr> read(JS::Handle&); void release_lock(); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.idl b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.idl index bde2126efde..4e37bad9b2d 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.idl +++ b/Userland/Libraries/LibWeb/Streams/ReadableStreamBYOBReader.idl @@ -7,8 +7,7 @@ interface ReadableStreamBYOBReader { constructor(ReadableStream stream); - // FIXME: This should accept an ArrayBufferView - Promise read(any view); + Promise read(ArrayBufferView view); undefined releaseLock(); };