From 13021a0fb9b871bd561e36d719fd95850f7ae6b9 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 29 Apr 2024 16:29:02 -0400 Subject: [PATCH] LibWeb: Remove small OOM error propagation from stream AOs --- .../LibWeb/Streams/AbstractOperations.cpp | 23 ++++++++----------- .../LibWeb/Streams/AbstractOperations.h | 6 ++--- .../Streams/ReadableByteStreamController.cpp | 10 ++++---- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index e9c97a2a205..ecfdd40be46 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -2654,7 +2654,7 @@ void readable_byte_stream_controller_error(ReadableByteStreamController& control } // https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerfillreadrequestfromqueue -WebIDL::ExceptionOr readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr read_request) +void readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr read_request) { auto& vm = controller.vm(); auto& realm = controller.realm(); @@ -2673,12 +2673,10 @@ WebIDL::ExceptionOr readable_byte_stream_controller_fill_read_request_from readable_byte_stream_controller_handle_queue_drain(controller); // 6. Let view be ! Construct(%Uint8Array%, « entry’s buffer, entry’s byte offset, entry’s byte length »). - auto view = MUST_OR_THROW_OOM(JS::construct(vm, *realm.intrinsics().uint8_array_constructor(), entry.buffer, JS::Value(entry.byte_offset), JS::Value(entry.byte_length))); + auto view = MUST(JS::construct(vm, *realm.intrinsics().uint8_array_constructor(), entry.buffer, JS::Value(entry.byte_offset), JS::Value(entry.byte_length))); // 7. Perform readRequest’s chunk steps, given view. read_request->on_chunk(view); - - return {}; } // https://streams.spec.whatwg.org/#readable-byte-stream-controller-get-desired-size @@ -3166,7 +3164,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_enqueue(ReadableByteSt // 9. If ! ReadableStreamHasDefaultReader(stream) is true, if (readable_stream_has_default_reader(*stream)) { // 1. Perform ! ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller). - TRY(readable_byte_stream_controller_process_read_requests_using_queue(controller)); + readable_byte_stream_controller_process_read_requests_using_queue(controller); // 2. If ! ReadableStreamGetNumReadRequests(stream) is 0, if (readable_stream_get_num_read_requests(*stream) == 0) { @@ -3191,7 +3189,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_enqueue(ReadableByteSt } // 3. Let transferredView be ! Construct(%Uint8Array%, « transferredBuffer, byteOffset, byteLength »). - auto transferred_view = MUST_OR_THROW_OOM(JS::construct(vm, *realm.intrinsics().uint8_array_constructor(), transferred_buffer, JS::Value(byte_offset), JS::Value(byte_length))); + auto transferred_view = MUST(JS::construct(vm, *realm.intrinsics().uint8_array_constructor(), transferred_buffer, JS::Value(byte_offset), JS::Value(byte_length))); // 4. Perform ! ReadableStreamFulfillReadRequest(stream, transferredView, false). readable_stream_fulfill_read_request(*stream, transferred_view, false); @@ -3323,7 +3321,7 @@ void readable_byte_stream_controller_process_pull_into_descriptors_using_queue(R } // https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerprocessreadrequestsusingqueue -WebIDL::ExceptionOr readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller) +void readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller) { // 1. Let reader be controller.[[stream]].[[reader]]. auto reader = controller.stream()->reader(); @@ -3336,17 +3334,15 @@ WebIDL::ExceptionOr readable_byte_stream_controller_process_read_requests_ while (!readable_stream_default_reader->read_requests().is_empty()) { // 1. If controller.[[queueTotalSize]] is 0, return. if (controller.queue_total_size() == 0.0) - return {}; + return; // 2. Let readRequest be reader.[[readRequests]][0]. // 3. Remove readRequest from reader.[[readRequests]]. auto read_request = readable_stream_default_reader->read_requests().take_first(); // 4. Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest). - TRY(readable_byte_stream_controller_fill_read_request_from_queue(controller, read_request)); + readable_byte_stream_controller_fill_read_request_from_queue(controller, read_request); } - - return {}; } // https://streams.spec.whatwg.org/#readable-byte-stream-controller-enqueue-chunk-to-queue @@ -3546,10 +3542,9 @@ WebIDL::ExceptionOr> writable_stream_close(Wri } // https://streams.spec.whatwg.org/#writable-stream-add-write-request -WebIDL::ExceptionOr> writable_stream_add_write_request(WritableStream& stream) +JS::NonnullGCPtr writable_stream_add_write_request(WritableStream& stream) { auto& realm = stream.realm(); - auto& vm = stream.vm(); // 1. Assert: ! IsWritableStreamLocked(stream) is true. VERIFY(is_writable_stream_locked(stream)); @@ -3561,7 +3556,7 @@ WebIDL::ExceptionOr> writable_stream_add_write auto promise = WebIDL::create_promise(realm); // 4. Append promise to stream.[[writeRequests]]. - TRY_OR_THROW_OOM(vm, stream.write_requests().try_append(promise)); + stream.write_requests().append(promise); // 5. Return promise. return promise; diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h index 94768ee91c8..3c15e510008 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.h +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.h @@ -97,7 +97,7 @@ WebIDL::ExceptionOr readable_byte_stream_controller_enqueue(ReadableByteSt WebIDL::ExceptionOr> transfer_array_buffer(JS::Realm& realm, JS::ArrayBuffer& buffer); WebIDL::ExceptionOr readable_byte_stream_controller_enqueue_detached_pull_into_queue(ReadableByteStreamController& controller, PullIntoDescriptor& pull_into_descriptor); void readable_byte_stream_controller_commit_pull_into_descriptor(ReadableStream&, PullIntoDescriptor const&); -WebIDL::ExceptionOr readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller); +void readable_byte_stream_controller_process_read_requests_using_queue(ReadableByteStreamController& controller); void readable_byte_stream_controller_process_pull_into_descriptors_using_queue(ReadableByteStreamController&); void readable_byte_stream_controller_enqueue_chunk_to_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr buffer, u32 byte_offset, u32 byte_length); WebIDL::ExceptionOr readable_byte_stream_controller_enqueue_cloned_chunk_to_queue(ReadableByteStreamController& controller, JS::ArrayBuffer& buffer, u64 byte_offset, u64 byte_length); @@ -108,7 +108,7 @@ void readable_byte_stream_controller_clear_algorithms(ReadableByteStreamControll void readable_byte_stream_controller_clear_pending_pull_intos(ReadableByteStreamController&); WebIDL::ExceptionOr readable_byte_stream_controller_close(ReadableByteStreamController&); void readable_byte_stream_controller_error(ReadableByteStreamController&, JS::Value error); -WebIDL::ExceptionOr readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController&, JS::NonnullGCPtr); +void readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController&, JS::NonnullGCPtr); bool readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(ReadableByteStreamController&, PullIntoDescriptor&); Optional readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const&); void readable_byte_stream_controller_handle_queue_drain(ReadableByteStreamController&); @@ -127,7 +127,7 @@ WebIDL::ExceptionOr set_up_writable_stream_default_writer(WritableStreamDe WebIDL::ExceptionOr> writable_stream_abort(WritableStream&, JS::Value reason); WebIDL::ExceptionOr> writable_stream_close(WritableStream&); -WebIDL::ExceptionOr> writable_stream_add_write_request(WritableStream&); +JS::NonnullGCPtr writable_stream_add_write_request(WritableStream&); bool writable_stream_close_queued_or_in_flight(WritableStream const&); WebIDL::ExceptionOr writable_stream_deal_with_rejection(WritableStream&, JS::Value error); WebIDL::ExceptionOr writable_stream_finish_erroring(WritableStream&); diff --git a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp index 520af0e6019..430b0d6db08 100644 --- a/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp +++ b/Userland/Libraries/LibWeb/Streams/ReadableByteStreamController.cpp @@ -112,7 +112,6 @@ WebIDL::ExceptionOr> ReadableByteStreamControl // https://streams.spec.whatwg.org/#rbs-controller-private-pull WebIDL::ExceptionOr ReadableByteStreamController::pull_steps(JS::NonnullGCPtr read_request) { - auto& vm = this->vm(); auto& realm = this->realm(); // 1. Let stream be this.[[stream]]. @@ -126,7 +125,8 @@ WebIDL::ExceptionOr ReadableByteStreamController::pull_steps(JS::NonnullGC VERIFY(readable_stream_get_num_read_requests(*m_stream) == 0); // 2. Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(this, readRequest). - TRY(readable_byte_stream_controller_fill_read_request_from_queue(*this, read_request)); + readable_byte_stream_controller_fill_read_request_from_queue(*this, read_request); + // 3. Return. return {}; } @@ -161,7 +161,7 @@ WebIDL::ExceptionOr ReadableByteStreamController::pull_steps(JS::NonnullGC }; // 4. Append pullIntoDescriptor to this.[[pendingPullIntos]]. - TRY_OR_THROW_OOM(vm, m_pending_pull_intos.try_append(move(pull_into_descriptor))); + m_pending_pull_intos.append(move(pull_into_descriptor)); } // 6. Perform ! ReadableStreamAddReadRequest(stream, readRequest). @@ -176,8 +176,6 @@ WebIDL::ExceptionOr ReadableByteStreamController::pull_steps(JS::NonnullGC // https://streams.spec.whatwg.org/#rbs-controller-private-pull WebIDL::ExceptionOr ReadableByteStreamController::release_steps() { - auto& vm = this->vm(); - // 1. If this.[[pendingPullIntos]] is not empty, if (!m_pending_pull_intos.is_empty()) { // 1. Let firstPendingPullInto be this.[[pendingPullIntos]][0]. @@ -188,7 +186,7 @@ WebIDL::ExceptionOr ReadableByteStreamController::release_steps() // 3. Set this.[[pendingPullIntos]] to the list « firstPendingPullInto ». m_pending_pull_intos.clear(); - TRY_OR_THROW_OOM(vm, m_pending_pull_intos.try_append(first_pending_pull_into)); + m_pending_pull_intos.append(first_pending_pull_into); } return {};