LibWeb: Mark readable stream cancel/pull/release steps as infallible
These don't throw. We can remove a decent amount of exception handling by marking them infallible.
This commit is contained in:
parent
13021a0fb9
commit
fc070c8cbd
Notes:
sideshowbarker
2024-07-17 20:22:04 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/fc070c8cbd Pull-request: https://github.com/SerenityOS/serenity/pull/24165 Reviewed-by: https://github.com/kennethmyhra ✅ Reviewed-by: https://github.com/shannonbooth ✅
11 changed files with 63 additions and 82 deletions
|
@ -372,7 +372,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> Blob::text()
|
|||
auto reader = reader_or_exception.release_value();
|
||||
|
||||
// 3. Let promise be the result of reading all bytes from stream with reader
|
||||
auto promise = TRY(reader->read_all_bytes_deprecated());
|
||||
auto promise = reader->read_all_bytes_deprecated();
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns the result of running UTF-8 decode on its first argument.
|
||||
return WebIDL::upon_fulfillment(*promise, JS::create_heap_function(heap(), [&vm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
|
@ -401,7 +401,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> Blob::array_buffer()
|
|||
auto reader = reader_or_exception.release_value();
|
||||
|
||||
// 3. Let promise be the result of reading all bytes from stream with reader.
|
||||
auto promise = TRY(reader->read_all_bytes_deprecated());
|
||||
auto promise = reader->read_all_bytes_deprecated();
|
||||
|
||||
// 4. Return the result of transforming promise by a fulfillment handler that returns a new ArrayBuffer whose contents are its first argument.
|
||||
return WebIDL::upon_fulfillment(*promise, JS::create_heap_function(heap(), [&realm](JS::Value first_argument) -> WebIDL::ExceptionOr<JS::Value> {
|
||||
|
|
|
@ -86,7 +86,7 @@ bool is_readable_stream_locked(ReadableStream const& stream)
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-cancel
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_cancel(ReadableStream& stream, JS::Value reason)
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_cancel(ReadableStream& stream, JS::Value reason)
|
||||
{
|
||||
auto& realm = stream.realm();
|
||||
|
||||
|
@ -121,9 +121,9 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_cancel(Re
|
|||
}
|
||||
|
||||
// 7. Let sourceCancelPromise be ! stream.[[controller]].[[CancelSteps]](reason).
|
||||
auto source_cancel_promise = TRY(stream.controller()->visit([&](auto const& controller) {
|
||||
auto source_cancel_promise = stream.controller()->visit([&](auto const& controller) {
|
||||
return controller->cancel_steps(reason);
|
||||
}));
|
||||
});
|
||||
|
||||
// 8. Return the result of reacting to sourceCancelPromise with a fulfillment step that returns undefined.
|
||||
auto react_result = WebIDL::react_to_promise(*source_cancel_promise,
|
||||
|
@ -242,7 +242,7 @@ bool readable_stream_has_default_reader(ReadableStream const& stream)
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-pipe-to
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, Optional<JS::Value> signal)
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool, bool, bool, Optional<JS::Value> signal)
|
||||
{
|
||||
auto& realm = source.realm();
|
||||
|
||||
|
@ -319,7 +319,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_pipe_to(R
|
|||
WebIDL::reject_promise(realm, promise, error);
|
||||
};
|
||||
|
||||
TRY(reader->read_all_bytes(move(success_steps), move(failure_steps)));
|
||||
reader->read_all_bytes(move(success_steps), move(failure_steps));
|
||||
|
||||
// 16. Return promise.
|
||||
return promise;
|
||||
|
@ -420,7 +420,7 @@ public:
|
|||
readable_stream_default_controller_error(controller2, completion.value().value());
|
||||
|
||||
// 3. Resolve cancelPromise with ! ReadableStreamCancel(stream, cloneResult.[[Value]]).
|
||||
auto cancel_result = MUST(readable_stream_cancel(m_stream, completion.value().value()));
|
||||
auto cancel_result = readable_stream_cancel(m_stream, completion.value().value());
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
||||
WebIDL::resolve_promise(m_realm, m_cancel_promise, cancel_value);
|
||||
|
@ -548,7 +548,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_default_tee(JS::Realm& r
|
|||
auto read_request = realm.heap().allocate_without_realm<DefaultStreamTeeReadRequest>(realm, stream, params, cancel_promise, clone_for_branch2);
|
||||
|
||||
// 4. Perform ! ReadableStreamDefaultReaderRead(reader, readRequest).
|
||||
MUST(readable_stream_default_reader_read(reader, read_request));
|
||||
readable_stream_default_reader_read(reader, read_request);
|
||||
|
||||
// 5. Return a promise resolved with undefined.
|
||||
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
|
||||
|
@ -571,7 +571,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_default_tee(JS::Realm& r
|
|||
auto composite_reason = JS::Array::create_from(realm, AK::Array { params->reason1, params->reason2 });
|
||||
|
||||
// 2. Let cancelResult be ! ReadableStreamCancel(stream, compositeReason).
|
||||
auto cancel_result = MUST(readable_stream_cancel(stream, composite_reason));
|
||||
auto cancel_result = readable_stream_cancel(stream, composite_reason);
|
||||
|
||||
// 3. Resolve cancelPromise with cancelResult.
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
@ -596,7 +596,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_default_tee(JS::Realm& r
|
|||
auto composite_reason = JS::Array::create_from(realm, AK::Array { params->reason1, params->reason2 });
|
||||
|
||||
// 2. Let cancelResult be ! ReadableStreamCancel(stream, compositeReason).
|
||||
auto cancel_result = MUST(readable_stream_cancel(stream, composite_reason));
|
||||
auto cancel_result = readable_stream_cancel(stream, composite_reason);
|
||||
|
||||
// 3. Resolve cancelPromise with cancelResult.
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
@ -733,7 +733,7 @@ public:
|
|||
readable_byte_stream_controller_error(controller2, completion.value().value());
|
||||
|
||||
// 3. Resolve cancelPromise with ! ReadableStreamCancel(stream, cloneResult.[[Value]]).
|
||||
auto cancel_result = MUST(readable_stream_cancel(m_stream, completion.value().value()));
|
||||
auto cancel_result = readable_stream_cancel(m_stream, completion.value().value());
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
||||
WebIDL::resolve_promise(m_realm, m_cancel_promise, cancel_value);
|
||||
|
@ -898,7 +898,7 @@ public:
|
|||
readable_byte_stream_controller_error(other_controller, completion.value().value());
|
||||
|
||||
// 3. Resolve cancelPromise with ! ReadableStreamCancel(stream, cloneResult.[[Value]]).
|
||||
auto cancel_result = MUST(readable_stream_cancel(m_stream, completion.value().value()));
|
||||
auto cancel_result = readable_stream_cancel(m_stream, completion.value().value());
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
||||
WebIDL::resolve_promise(m_realm, m_cancel_promise, cancel_value);
|
||||
|
@ -1093,7 +1093,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& real
|
|||
auto read_request = realm.heap().allocate_without_realm<ByteStreamTeeDefaultReadRequest>(realm, stream, params, cancel_promise);
|
||||
|
||||
// 3. Perform ! ReadableStreamDefaultReaderRead(reader, readRequest).
|
||||
MUST(readable_stream_default_reader_read(params->reader.get<JS::NonnullGCPtr<ReadableStreamDefaultReader>>(), read_request));
|
||||
readable_stream_default_reader_read(params->reader.get<JS::NonnullGCPtr<ReadableStreamDefaultReader>>(), read_request);
|
||||
});
|
||||
|
||||
// 16. Let pullWithBYOBReader be the following steps, given view and forBranch2:
|
||||
|
@ -1104,7 +1104,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& real
|
|||
VERIFY((*default_reader)->read_requests().is_empty());
|
||||
|
||||
// 3. Perform ! ReadableStreamDefaultReaderRelease(reader).
|
||||
MUST(readable_stream_default_reader_release(*default_reader));
|
||||
readable_stream_default_reader_release(*default_reader);
|
||||
|
||||
// 4. Set reader to ! AcquireReadableStreamBYOBReader(stream).
|
||||
params->reader = MUST(acquire_readable_stream_byob_reader(stream));
|
||||
|
@ -1208,7 +1208,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& real
|
|||
auto composite_reason = JS::Array::create_from(realm, AK::Array { params->reason1, params->reason2 });
|
||||
|
||||
// 2. Let cancelResult be ! ReadableStreamCancel(stream, compositeReason).
|
||||
auto cancel_result = MUST(readable_stream_cancel(stream, composite_reason));
|
||||
auto cancel_result = readable_stream_cancel(stream, composite_reason);
|
||||
|
||||
// 3. Resolve cancelPromise with cancelResult.
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
@ -1233,7 +1233,7 @@ WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& real
|
|||
auto composite_reason = JS::Array::create_from(realm, AK::Array { params->reason1, params->reason2 });
|
||||
|
||||
// 2. Let cancelResult be ! ReadableStreamCancel(stream, compositeReason).
|
||||
auto cancel_result = MUST(readable_stream_cancel(stream, composite_reason));
|
||||
auto cancel_result = readable_stream_cancel(stream, composite_reason);
|
||||
|
||||
// 3. Resolve cancelPromise with cancelResult.
|
||||
JS::NonnullGCPtr cancel_value = verify_cast<JS::Promise>(*cancel_result->promise().ptr());
|
||||
|
@ -1401,7 +1401,7 @@ void readable_stream_add_read_into_request(ReadableStream& stream, JS::NonnullGC
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-reader-generic-cancel
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin& reader, JS::Value reason)
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin& reader, JS::Value reason)
|
||||
{
|
||||
// 1. Let stream be reader.[[stream]]
|
||||
auto stream = reader.stream();
|
||||
|
@ -1410,7 +1410,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_reader_ge
|
|||
VERIFY(stream);
|
||||
|
||||
// 3. Return ! ReadableStreamCancel(stream, reason)
|
||||
return TRY(readable_stream_cancel(*stream, reason));
|
||||
return readable_stream_cancel(*stream, reason);
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-reader-generic-initialize
|
||||
|
@ -1451,7 +1451,7 @@ void readable_stream_reader_generic_initialize(ReadableStreamReader reader, Read
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-reader-generic-release
|
||||
WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin& reader)
|
||||
void readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin& reader)
|
||||
{
|
||||
// 1. Let stream be reader.[[stream]].
|
||||
auto stream = reader.stream();
|
||||
|
@ -1478,15 +1478,13 @@ WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamG
|
|||
WebIDL::mark_promise_as_handled(*reader.closed_promise_capability());
|
||||
|
||||
// 7. Perform ! stream.[[controller]].[[ReleaseSteps]]().
|
||||
TRY(stream->controller()->visit([](auto const& controller) { return controller->release_steps(); }));
|
||||
stream->controller()->visit([](auto const& controller) { return controller->release_steps(); });
|
||||
|
||||
// 8. Set stream.[[reader]] to undefined.
|
||||
stream->set_reader({});
|
||||
|
||||
// 9. Set reader.[[stream]] to undefined.
|
||||
reader.set_stream({});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultreadererrorreadrequests
|
||||
|
@ -1626,7 +1624,7 @@ bool readable_byte_stream_controller_fill_pull_into_descriptor_from_queue(Readab
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-stream-default-reader-read
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefaultReader& reader, ReadRequest& read_request)
|
||||
void readable_stream_default_reader_read(ReadableStreamDefaultReader& reader, ReadRequest& read_request)
|
||||
{
|
||||
// 1. Let stream be reader.[[stream]].
|
||||
auto stream = reader.stream();
|
||||
|
@ -1651,12 +1649,10 @@ WebIDL::ExceptionOr<void> readable_stream_default_reader_read(ReadableStreamDefa
|
|||
VERIFY(stream->is_readable());
|
||||
|
||||
// 2. Perform ! stream.[[controller]].[[PullSteps]](readRequest).
|
||||
TRY(stream->controller()->visit([&](auto const& controller) {
|
||||
stream->controller()->visit([&](auto const& controller) {
|
||||
return controller->pull_steps(read_request);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readable-byte-stream-controller-convert-pull-into-descriptor
|
||||
|
@ -1841,20 +1837,18 @@ void readable_stream_byob_reader_read(ReadableStreamBYOBReader& reader, WebIDL::
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultreaderrelease
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader& reader)
|
||||
void readable_stream_default_reader_release(ReadableStreamDefaultReader& reader)
|
||||
{
|
||||
auto& realm = reader.realm();
|
||||
|
||||
// 1. Perform ! ReadableStreamReaderGenericRelease(reader).
|
||||
TRY(readable_stream_reader_generic_release(reader));
|
||||
readable_stream_reader_generic_release(reader);
|
||||
|
||||
// 2. Let e be a new TypeError exception.
|
||||
auto exception = JS::TypeError::create(realm, "Reader has been released"sv);
|
||||
|
||||
// 3. Perform ! ReadableStreamDefaultReaderErrorReadRequests(reader, e).
|
||||
readable_stream_default_reader_error_read_requests(reader, exception);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreambyobreaderrelease
|
||||
|
@ -1863,7 +1857,7 @@ void readable_stream_byob_reader_release(ReadableStreamBYOBReader& reader)
|
|||
auto& realm = reader.realm();
|
||||
|
||||
// 1. Perform ! ReadableStreamReaderGenericRelease(reader).
|
||||
MUST(readable_stream_reader_generic_release(reader));
|
||||
readable_stream_reader_generic_release(reader);
|
||||
|
||||
// 2. Let e be a new TypeError exception.
|
||||
auto exception = JS::TypeError::create(realm, "Reader has been released"sv);
|
||||
|
|
|
@ -39,7 +39,7 @@ void readable_stream_close(ReadableStream&);
|
|||
void readable_stream_error(ReadableStream&, JS::Value error);
|
||||
void readable_stream_add_read_request(ReadableStream&, JS::NonnullGCPtr<ReadRequest>);
|
||||
void readable_stream_add_read_into_request(ReadableStream&, JS::NonnullGCPtr<ReadIntoRequest>);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_cancel(ReadableStream&, JS::Value reason);
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_cancel(ReadableStream&, JS::Value reason);
|
||||
void readable_stream_fulfill_read_into_request(ReadableStream&, JS::Value chunk, bool done);
|
||||
void readable_stream_fulfill_read_request(ReadableStream&, JS::Value chunk, bool done);
|
||||
size_t readable_stream_get_num_read_into_requests(ReadableStream const&);
|
||||
|
@ -47,15 +47,15 @@ size_t readable_stream_get_num_read_requests(ReadableStream const&);
|
|||
bool readable_stream_has_byob_reader(ReadableStream const&);
|
||||
bool readable_stream_has_default_reader(ReadableStream const&);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool prevent_close, bool prevent_abort, bool prevent_cancel, Optional<JS::Value> signal);
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_pipe_to(ReadableStream& source, WritableStream& dest, bool prevent_close, bool prevent_abort, bool prevent_cancel, Optional<JS::Value> signal);
|
||||
|
||||
WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_tee(JS::Realm&, ReadableStream&, bool clone_for_branch2);
|
||||
WebIDL::ExceptionOr<ReadableStreamPair> readable_stream_default_tee(JS::Realm& realm, ReadableStream& stream, bool clone_for_branch2);
|
||||
WebIDL::ExceptionOr<ReadableStreamPair> readable_byte_stream_tee(JS::Realm& realm, ReadableStream& stream);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin&, JS::Value reason);
|
||||
JS::NonnullGCPtr<WebIDL::Promise> readable_stream_reader_generic_cancel(ReadableStreamGenericReaderMixin&, JS::Value reason);
|
||||
void readable_stream_reader_generic_initialize(ReadableStreamReader, ReadableStream&);
|
||||
WebIDL::ExceptionOr<void> readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin&);
|
||||
void readable_stream_reader_generic_release(ReadableStreamGenericReaderMixin&);
|
||||
|
||||
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);
|
||||
|
@ -64,8 +64,8 @@ void readable_byte_stream_controller_pull_into(ReadableByteStreamController&, We
|
|||
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<void> readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
|
||||
WebIDL::ExceptionOr<void> readable_stream_default_reader_release(ReadableStreamDefaultReader&);
|
||||
void readable_stream_default_reader_read(ReadableStreamDefaultReader&, ReadRequest&);
|
||||
void readable_stream_default_reader_release(ReadableStreamDefaultReader&);
|
||||
void readable_stream_byob_reader_release(ReadableStreamBYOBReader&);
|
||||
WebIDL::ExceptionOr<void> set_up_readable_stream_default_reader(ReadableStreamDefaultReader&, ReadableStream&);
|
||||
WebIDL::ExceptionOr<void> set_up_readable_stream_byob_reader(ReadableStreamBYOBReader&, ReadableStream&);
|
||||
|
|
|
@ -91,7 +91,7 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::enqueue(JS::Handle<WebID
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rbs-controller-private-cancel
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableByteStreamController::cancel_steps(JS::Value reason)
|
||||
JS::NonnullGCPtr<WebIDL::Promise> ReadableByteStreamController::cancel_steps(JS::Value reason)
|
||||
{
|
||||
// 1. Perform ! ReadableByteStreamControllerClearPendingPullIntos(this).
|
||||
readable_byte_stream_controller_clear_pending_pull_intos(*this);
|
||||
|
@ -110,7 +110,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableByteStreamControl
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rbs-controller-private-pull
|
||||
WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGCPtr<ReadRequest> read_request)
|
||||
void ReadableByteStreamController::pull_steps(JS::NonnullGCPtr<ReadRequest> read_request)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -128,7 +128,7 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
|
|||
readable_byte_stream_controller_fill_read_request_from_queue(*this, read_request);
|
||||
|
||||
// 3. Return.
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. Let autoAllocateChunkSize be this.[[autoAllocateChunkSize]].
|
||||
|
@ -144,7 +144,7 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
|
|||
read_request->on_error(*buffer.throw_completion().value());
|
||||
|
||||
// 2. Return.
|
||||
return {};
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Let pullIntoDescriptor be a new pull-into descriptor with buffer buffer.[[Value]], buffer byte length autoAllocateChunkSize, byte offset 0,
|
||||
|
@ -169,12 +169,10 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::pull_steps(JS::NonnullGC
|
|||
|
||||
// 7. Perform ! ReadableByteStreamControllerCallPullIfNeeded(this).
|
||||
readable_byte_stream_controller_call_pull_if_needed(*this);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rbs-controller-private-pull
|
||||
WebIDL::ExceptionOr<void> ReadableByteStreamController::release_steps()
|
||||
void ReadableByteStreamController::release_steps()
|
||||
{
|
||||
// 1. If this.[[pendingPullIntos]] is not empty,
|
||||
if (!m_pending_pull_intos.is_empty()) {
|
||||
|
@ -188,8 +186,6 @@ WebIDL::ExceptionOr<void> ReadableByteStreamController::release_steps()
|
|||
m_pending_pull_intos.clear();
|
||||
m_pending_pull_intos.append(first_pending_pull_into);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void ReadableByteStreamController::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
|
@ -127,9 +127,9 @@ public:
|
|||
JS::GCPtr<ReadableStream> stream() { return m_stream; }
|
||||
void set_stream(JS::GCPtr<ReadableStream> stream) { m_stream = stream; }
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> cancel_steps(JS::Value reason);
|
||||
WebIDL::ExceptionOr<void> pull_steps(JS::NonnullGCPtr<ReadRequest>);
|
||||
WebIDL::ExceptionOr<void> release_steps();
|
||||
JS::NonnullGCPtr<WebIDL::Promise> cancel_steps(JS::Value reason);
|
||||
void pull_steps(JS::NonnullGCPtr<ReadRequest>);
|
||||
void release_steps();
|
||||
|
||||
private:
|
||||
explicit ReadableByteStreamController(JS::Realm&);
|
||||
|
|
|
@ -94,7 +94,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> ReadableStream::cancel(JS::Value reas
|
|||
}
|
||||
|
||||
// 2. Return ! ReadableStreamCancel(this, reason).
|
||||
return TRY(readable_stream_cancel(*this, reason))->promise();
|
||||
return readable_stream_cancel(*this, reason)->promise();
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rs-get-reader
|
||||
|
@ -125,7 +125,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<ReadableStream>> ReadableStream::pipe_throu
|
|||
auto signal = options.signal ? JS::Value(options.signal) : JS::js_undefined();
|
||||
|
||||
// 4. Let promise be ! ReadableStreamPipeTo(this, transform["writable"], options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
|
||||
auto promise = MUST(readable_stream_pipe_to(*this, *transform.writable, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal));
|
||||
auto promise = readable_stream_pipe_to(*this, *transform.writable, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal);
|
||||
|
||||
// 5. Set promise.[[PromiseIsHandled]] to true.
|
||||
WebIDL::mark_promise_as_handled(*promise);
|
||||
|
@ -156,7 +156,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> ReadableStream::pipe_to(Writab
|
|||
auto signal = options.signal ? JS::Value(options.signal) : JS::js_undefined();
|
||||
|
||||
// 4. Return ! ReadableStreamPipeTo(this, destination, options["preventClose"], options["preventAbort"], options["preventCancel"], signal).
|
||||
return MUST(readable_stream_pipe_to(*this, destination, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal))->promise();
|
||||
return readable_stream_pipe_to(*this, destination, options.prevent_close, options.prevent_abort, options.prevent_cancel, signal)->promise();
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestream-tee
|
||||
|
|
|
@ -65,7 +65,7 @@ void ReadableStreamDefaultController::error(JS::Value error)
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rs-default-controller-private-cancel
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableStreamDefaultController::cancel_steps(JS::Value reason)
|
||||
JS::NonnullGCPtr<WebIDL::Promise> ReadableStreamDefaultController::cancel_steps(JS::Value reason)
|
||||
{
|
||||
// 1. Perform ! ResetQueue(this).
|
||||
reset_queue(*this);
|
||||
|
@ -81,7 +81,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableStreamDefaultCont
|
|||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#rs-default-controller-private-pull
|
||||
WebIDL::ExceptionOr<void> ReadableStreamDefaultController::pull_steps(Web::Streams::ReadRequest& read_request)
|
||||
void ReadableStreamDefaultController::pull_steps(Web::Streams::ReadRequest& read_request)
|
||||
{
|
||||
// 1. Let stream be this.[[stream]].
|
||||
auto& stream = *m_stream;
|
||||
|
@ -115,15 +115,12 @@ WebIDL::ExceptionOr<void> ReadableStreamDefaultController::pull_steps(Web::Strea
|
|||
// 2. Perform ! ReadableStreamDefaultControllerCallPullIfNeeded(this).
|
||||
readable_stream_default_controller_can_pull_if_needed(*this);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#abstract-opdef-readablestreamdefaultcontroller-releasesteps
|
||||
WebIDL::ExceptionOr<void> ReadableStreamDefaultController::release_steps()
|
||||
void ReadableStreamDefaultController::release_steps()
|
||||
{
|
||||
// 1. Return.
|
||||
return {};
|
||||
}
|
||||
|
||||
void ReadableStreamDefaultController::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -64,9 +64,9 @@ public:
|
|||
JS::GCPtr<ReadableStream> stream() { return m_stream; }
|
||||
void set_stream(JS::GCPtr<ReadableStream> value) { m_stream = value; }
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> cancel_steps(JS::Value reason);
|
||||
WebIDL::ExceptionOr<void> pull_steps(ReadRequest&);
|
||||
WebIDL::ExceptionOr<void> release_steps();
|
||||
JS::NonnullGCPtr<WebIDL::Promise> cancel_steps(JS::Value reason);
|
||||
void pull_steps(ReadRequest&);
|
||||
void release_steps();
|
||||
|
||||
private:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
|
|
@ -94,11 +94,7 @@ void ReadLoopReadRequest::on_chunk(JS::Value chunk)
|
|||
// up more than one chunk at a time, we may run into stack overflow problems.
|
||||
//
|
||||
// 3. Read-loop given reader, bytes, successSteps, and failureSteps.
|
||||
auto maybe_error = readable_stream_default_reader_read(m_reader, *this);
|
||||
if (maybe_error.is_exception()) {
|
||||
auto throw_completion = Bindings::dom_exception_to_throw_completion(m_vm, maybe_error.exception());
|
||||
m_failure_steps(*throw_completion.release_error().value());
|
||||
}
|
||||
readable_stream_default_reader_read(m_reader, *this);
|
||||
}
|
||||
|
||||
// close steps
|
||||
|
@ -179,14 +175,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ReadableStreamDefaultReader::
|
|||
auto read_request = heap().allocate_without_realm<DefaultReaderReadRequest>(realm, promise_capability);
|
||||
|
||||
// 4. Perform ! ReadableStreamDefaultReaderRead(this, readRequest).
|
||||
TRY(readable_stream_default_reader_read(*this, read_request));
|
||||
readable_stream_default_reader_read(*this, read_request);
|
||||
|
||||
// 5. Return promise.
|
||||
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise()) };
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#readablestreamdefaultreader-read-all-bytes
|
||||
WebIDL::ExceptionOr<void> ReadableStreamDefaultReader::read_all_bytes(ReadLoopReadRequest::SuccessSteps success_steps, ReadLoopReadRequest::FailureSteps failure_steps)
|
||||
void ReadableStreamDefaultReader::read_all_bytes(ReadLoopReadRequest::SuccessSteps success_steps, ReadLoopReadRequest::FailureSteps failure_steps)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
auto& vm = realm.vm();
|
||||
|
@ -196,15 +192,13 @@ WebIDL::ExceptionOr<void> ReadableStreamDefaultReader::read_all_bytes(ReadLoopRe
|
|||
auto read_request = heap().allocate_without_realm<ReadLoopReadRequest>(vm, realm, *this, move(success_steps), move(failure_steps));
|
||||
|
||||
// 2. Perform ! ReadableStreamDefaultReaderRead(this, readRequest).
|
||||
TRY(readable_stream_default_reader_read(*this, read_request));
|
||||
|
||||
return {};
|
||||
readable_stream_default_reader_read(*this, read_request);
|
||||
}
|
||||
|
||||
// FIXME: This function is a promise-based wrapper around "read all bytes". The spec changed this function to not use promises
|
||||
// in https://github.com/whatwg/streams/commit/f894acdd417926a2121710803cef593e15127964 - however, it seems that the
|
||||
// FileAPI blob specification has not been updated to match, see: https://github.com/w3c/FileAPI/issues/187.
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableStreamDefaultReader::read_all_bytes_deprecated()
|
||||
JS::NonnullGCPtr<WebIDL::Promise> ReadableStreamDefaultReader::read_all_bytes_deprecated()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
|
@ -223,20 +217,20 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> ReadableStreamDefaultRead
|
|||
WebIDL::reject_promise(realm, promise, error);
|
||||
};
|
||||
|
||||
TRY(read_all_bytes(move(success_steps), move(failure_steps)));
|
||||
read_all_bytes(move(success_steps), move(failure_steps));
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#default-reader-release-lock
|
||||
WebIDL::ExceptionOr<void> ReadableStreamDefaultReader::release_lock()
|
||||
void ReadableStreamDefaultReader::release_lock()
|
||||
{
|
||||
// 1. If this.[[stream]] is undefined, return.
|
||||
if (!m_stream)
|
||||
return {};
|
||||
return;
|
||||
|
||||
// 2. Perform ! ReadableStreamDefaultReaderRelease(this).
|
||||
return readable_stream_default_reader_release(*this);
|
||||
readable_stream_default_reader_release(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -75,10 +75,10 @@ public:
|
|||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> read();
|
||||
|
||||
WebIDL::ExceptionOr<void> read_all_bytes(ReadLoopReadRequest::SuccessSteps, ReadLoopReadRequest::FailureSteps);
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> read_all_bytes_deprecated();
|
||||
void read_all_bytes(ReadLoopReadRequest::SuccessSteps, ReadLoopReadRequest::FailureSteps);
|
||||
JS::NonnullGCPtr<WebIDL::Promise> read_all_bytes_deprecated();
|
||||
|
||||
WebIDL::ExceptionOr<void> release_lock();
|
||||
void release_lock();
|
||||
|
||||
SinglyLinkedList<JS::NonnullGCPtr<ReadRequest>>& read_requests() { return m_read_requests; }
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ReadableStreamGenericReaderMi
|
|||
}
|
||||
|
||||
// 2. Return ! ReadableStreamReaderGenericCancel(this, reason).
|
||||
auto promise_capability = TRY(readable_stream_reader_generic_cancel(*this, reason));
|
||||
auto promise_capability = readable_stream_reader_generic_cancel(*this, reason);
|
||||
return JS::NonnullGCPtr { verify_cast<JS::Promise>(*promise_capability->promise().ptr()) };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue