LibWeb: Remove small OOM error propagation from stream AOs

This commit is contained in:
Timothy Flynn 2024-04-29 16:29:02 -04:00 committed by Andreas Kling
commit 13021a0fb9
Notes: sideshowbarker 2024-07-17 07:16:27 +09:00
3 changed files with 16 additions and 23 deletions

View file

@ -2654,7 +2654,7 @@ void readable_byte_stream_controller_error(ReadableByteStreamController& control
} }
// https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerfillreadrequestfromqueue // https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerfillreadrequestfromqueue
WebIDL::ExceptionOr<void> readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr<ReadRequest> read_request) void readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr<ReadRequest> read_request)
{ {
auto& vm = controller.vm(); auto& vm = controller.vm();
auto& realm = controller.realm(); auto& realm = controller.realm();
@ -2673,12 +2673,10 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_fill_read_request_from
readable_byte_stream_controller_handle_queue_drain(controller); readable_byte_stream_controller_handle_queue_drain(controller);
// 6. Let view be ! Construct(%Uint8Array%, « entrys buffer, entrys byte offset, entrys byte length »). // 6. Let view be ! Construct(%Uint8Array%, « entrys buffer, entrys byte offset, entrys 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 readRequests chunk steps, given view. // 7. Perform readRequests chunk steps, given view.
read_request->on_chunk(view); read_request->on_chunk(view);
return {};
} }
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-get-desired-size // https://streams.spec.whatwg.org/#readable-byte-stream-controller-get-desired-size
@ -3166,7 +3164,7 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteSt
// 9. If ! ReadableStreamHasDefaultReader(stream) is true, // 9. If ! ReadableStreamHasDefaultReader(stream) is true,
if (readable_stream_has_default_reader(*stream)) { if (readable_stream_has_default_reader(*stream)) {
// 1. Perform ! ReadableByteStreamControllerProcessReadRequestsUsingQueue(controller). // 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, // 2. If ! ReadableStreamGetNumReadRequests(stream) is 0,
if (readable_stream_get_num_read_requests(*stream) == 0) { if (readable_stream_get_num_read_requests(*stream) == 0) {
@ -3191,7 +3189,7 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteSt
} }
// 3. Let transferredView be ! Construct(%Uint8Array%, « transferredBuffer, byteOffset, byteLength »). // 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). // 4. Perform ! ReadableStreamFulfillReadRequest(stream, transferredView, false).
readable_stream_fulfill_read_request(*stream, transferred_view, 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 // https://streams.spec.whatwg.org/#abstract-opdef-readablebytestreamcontrollerprocessreadrequestsusingqueue
WebIDL::ExceptionOr<void> 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]]. // 1. Let reader be controller.[[stream]].[[reader]].
auto reader = controller.stream()->reader(); auto reader = controller.stream()->reader();
@ -3336,17 +3334,15 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_process_read_requests_
while (!readable_stream_default_reader->read_requests().is_empty()) { while (!readable_stream_default_reader->read_requests().is_empty()) {
// 1. If controller.[[queueTotalSize]] is 0, return. // 1. If controller.[[queueTotalSize]] is 0, return.
if (controller.queue_total_size() == 0.0) if (controller.queue_total_size() == 0.0)
return {}; return;
// 2. Let readRequest be reader.[[readRequests]][0]. // 2. Let readRequest be reader.[[readRequests]][0].
// 3. Remove readRequest from reader.[[readRequests]]. // 3. Remove readRequest from reader.[[readRequests]].
auto read_request = readable_stream_default_reader->read_requests().take_first(); auto read_request = readable_stream_default_reader->read_requests().take_first();
// 4. Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(controller, readRequest). // 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 // https://streams.spec.whatwg.org/#readable-byte-stream-controller-enqueue-chunk-to-queue
@ -3546,10 +3542,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(Wri
} }
// https://streams.spec.whatwg.org/#writable-stream-add-write-request // https://streams.spec.whatwg.org/#writable-stream-add-write-request
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_add_write_request(WritableStream& stream) JS::NonnullGCPtr<WebIDL::Promise> writable_stream_add_write_request(WritableStream& stream)
{ {
auto& realm = stream.realm(); auto& realm = stream.realm();
auto& vm = stream.vm();
// 1. Assert: ! IsWritableStreamLocked(stream) is true. // 1. Assert: ! IsWritableStreamLocked(stream) is true.
VERIFY(is_writable_stream_locked(stream)); VERIFY(is_writable_stream_locked(stream));
@ -3561,7 +3556,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_add_write
auto promise = WebIDL::create_promise(realm); auto promise = WebIDL::create_promise(realm);
// 4. Append promise to stream.[[writeRequests]]. // 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. // 5. Return promise.
return promise; return promise;

View file

@ -97,7 +97,7 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteSt
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> transfer_array_buffer(JS::Realm& realm, JS::ArrayBuffer& buffer); WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> transfer_array_buffer(JS::Realm& realm, JS::ArrayBuffer& buffer);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue_detached_pull_into_queue(ReadableByteStreamController& controller, PullIntoDescriptor& pull_into_descriptor); WebIDL::ExceptionOr<void> 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&); void readable_byte_stream_controller_commit_pull_into_descriptor(ReadableStream&, PullIntoDescriptor const&);
WebIDL::ExceptionOr<void> 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_process_pull_into_descriptors_using_queue(ReadableByteStreamController&);
void readable_byte_stream_controller_enqueue_chunk_to_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr<JS::ArrayBuffer> buffer, u32 byte_offset, u32 byte_length); void readable_byte_stream_controller_enqueue_chunk_to_queue(ReadableByteStreamController& controller, JS::NonnullGCPtr<JS::ArrayBuffer> buffer, u32 byte_offset, u32 byte_length);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue_cloned_chunk_to_queue(ReadableByteStreamController& controller, JS::ArrayBuffer& buffer, u64 byte_offset, u64 byte_length); WebIDL::ExceptionOr<void> 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&); void readable_byte_stream_controller_clear_pending_pull_intos(ReadableByteStreamController&);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_close(ReadableByteStreamController&); WebIDL::ExceptionOr<void> readable_byte_stream_controller_close(ReadableByteStreamController&);
void readable_byte_stream_controller_error(ReadableByteStreamController&, JS::Value error); void readable_byte_stream_controller_error(ReadableByteStreamController&, JS::Value error);
WebIDL::ExceptionOr<void> readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController&, JS::NonnullGCPtr<ReadRequest>); void readable_byte_stream_controller_fill_read_request_from_queue(ReadableByteStreamController&, JS::NonnullGCPtr<ReadRequest>);
bool readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(ReadableByteStreamController&, PullIntoDescriptor&); bool readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(ReadableByteStreamController&, PullIntoDescriptor&);
Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const&); Optional<double> readable_byte_stream_controller_get_desired_size(ReadableByteStreamController const&);
void readable_byte_stream_controller_handle_queue_drain(ReadableByteStreamController&); void readable_byte_stream_controller_handle_queue_drain(ReadableByteStreamController&);
@ -127,7 +127,7 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_writer(WritableStreamDe
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_abort(WritableStream&, JS::Value reason); WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_abort(WritableStream&, JS::Value reason);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(WritableStream&); WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(WritableStream&);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_add_write_request(WritableStream&); JS::NonnullGCPtr<WebIDL::Promise> writable_stream_add_write_request(WritableStream&);
bool writable_stream_close_queued_or_in_flight(WritableStream const&); bool writable_stream_close_queued_or_in_flight(WritableStream const&);
WebIDL::ExceptionOr<void> writable_stream_deal_with_rejection(WritableStream&, JS::Value error); WebIDL::ExceptionOr<void> writable_stream_deal_with_rejection(WritableStream&, JS::Value error);
WebIDL::ExceptionOr<void> writable_stream_finish_erroring(WritableStream&); WebIDL::ExceptionOr<void> writable_stream_finish_erroring(WritableStream&);

View file

@ -112,7 +112,6 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableByteStreamControl
// https://streams.spec.whatwg.org/#rbs-controller-private-pull // https://streams.spec.whatwg.org/#rbs-controller-private-pull
WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGCPtr<ReadRequest> read_request) WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGCPtr<ReadRequest> read_request)
{ {
auto& vm = this->vm();
auto& realm = this->realm(); auto& realm = this->realm();
// 1. Let stream be this.[[stream]]. // 1. Let stream be this.[[stream]].
@ -126,7 +125,8 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
VERIFY(readable_stream_get_num_read_requests(*m_stream) == 0); VERIFY(readable_stream_get_num_read_requests(*m_stream) == 0);
// 2. Perform ! ReadableByteStreamControllerFillReadRequestFromQueue(this, readRequest). // 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. // 3. Return.
return {}; return {};
} }
@ -161,7 +161,7 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
}; };
// 4. Append pullIntoDescriptor to this.[[pendingPullIntos]]. // 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). // 6. Perform ! ReadableStreamAddReadRequest(stream, readRequest).
@ -176,8 +176,6 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
// https://streams.spec.whatwg.org/#rbs-controller-private-pull // https://streams.spec.whatwg.org/#rbs-controller-private-pull
WebIDL::ExceptionOr<void> ReadableByteStreamController::release_steps() WebIDL::ExceptionOr<void> ReadableByteStreamController::release_steps()
{ {
auto& vm = this->vm();
// 1. If this.[[pendingPullIntos]] is not empty, // 1. If this.[[pendingPullIntos]] is not empty,
if (!m_pending_pull_intos.is_empty()) { if (!m_pending_pull_intos.is_empty()) {
// 1. Let firstPendingPullInto be this.[[pendingPullIntos]][0]. // 1. Let firstPendingPullInto be this.[[pendingPullIntos]][0].
@ -188,7 +186,7 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::release_steps()
// 3. Set this.[[pendingPullIntos]] to the list « firstPendingPullInto ». // 3. Set this.[[pendingPullIntos]] to the list « firstPendingPullInto ».
m_pending_pull_intos.clear(); 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 {}; return {};