LibWeb: Mark stream AOs as infallible as required by the spec

There were several instances where the spec marks an AO invocation as
infallible, but we were propagating WebIDL::ExceptionOr. These mostly
cannot throw due to knowledge about the values they are provided. By
unwinding these, we can remove a decent amount of exception handling.
This commit is contained in:
Timothy Flynn 2024-04-29 18:01:44 -04:00 committed by Andreas Kling
parent 3aa6ef8ac0
commit c29916775e
Notes: sideshowbarker 2024-07-17 01:51:00 +09:00
13 changed files with 77 additions and 98 deletions

View File

@ -49,12 +49,12 @@ WebIDL::ExceptionOr<Infrastructure::BodyWithType> extract_body(JS::Realm& realm,
}
// 3. Otherwise, if object is a Blob object, set stream to the result of running objects get stream.
else if (auto const* blob_handle = object.get_pointer<JS::Handle<FileAPI::Blob>>()) {
stream = TRY(blob_handle->cell()->get_stream());
stream = blob_handle->cell()->get_stream();
}
// 4. Otherwise, set stream to a new ReadableStream object, and set up stream with byte reading support.
else {
stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
TRY(Streams::set_up_readable_stream_controller_with_byte_reading_support(*stream));
Streams::set_up_readable_stream_controller_with_byte_reading_support(*stream);
}
// 5. Assert: stream is a ReadableStream object.

View File

@ -288,14 +288,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> Blob::slice(Optional<i64> start, Opt
}
// https://w3c.github.io/FileAPI/#dom-blob-stream
WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> Blob::stream()
JS::NonnullGCPtr<Streams::ReadableStream> Blob::stream()
{
// The stream() method, when invoked, must return the result of calling get stream on this.
return this->get_stream();
return get_stream();
}
// https://w3c.github.io/FileAPI/#blob-get-stream
WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> Blob::get_stream()
JS::NonnullGCPtr<Streams::ReadableStream> Blob::get_stream()
{
auto& realm = this->realm();
@ -303,7 +303,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> Blob::get_stream(
auto stream = realm.heap().allocate<Streams::ReadableStream>(realm, realm);
// 2. Set up stream with byte reading support.
TRY(set_up_readable_stream_controller_with_byte_reading_support(stream));
set_up_readable_stream_controller_with_byte_reading_support(stream);
// FIXME: 3. Run the following steps in parallel:
{
@ -357,13 +357,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> Blob::get_stream(
}
// https://w3c.github.io/FileAPI/#dom-blob-text
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> Blob::text()
JS::NonnullGCPtr<JS::Promise> Blob::text()
{
auto& realm = this->realm();
auto& vm = realm.vm();
// 1. Let stream be the result of calling get stream on this.
auto stream = TRY(this->get_stream());
auto stream = get_stream();
// 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception.
auto reader_or_exception = acquire_readable_stream_default_reader(*stream);
@ -387,12 +387,12 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> Blob::text()
}
// https://w3c.github.io/FileAPI/#dom-blob-arraybuffer
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> Blob::array_buffer()
JS::NonnullGCPtr<JS::Promise> Blob::array_buffer()
{
auto& realm = this->realm();
// 1. Let stream be the result of calling get stream on this.
auto stream = TRY(this->get_stream());
auto stream = get_stream();
// 2. Let reader be the result of getting a reader from stream. If that threw an exception, return a new promise rejected with that exception.
auto reader_or_exception = acquire_readable_stream_default_reader(*stream);

View File

@ -47,13 +47,13 @@ public:
WebIDL::ExceptionOr<JS::NonnullGCPtr<Blob>> slice(Optional<i64> start = {}, Optional<i64> end = {}, Optional<String> const& content_type = {});
WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> stream();
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> text();
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> array_buffer();
JS::NonnullGCPtr<Streams::ReadableStream> stream();
JS::NonnullGCPtr<JS::Promise> text();
JS::NonnullGCPtr<JS::Promise> array_buffer();
ReadonlyBytes bytes() const { return m_byte_buffer.bytes(); }
WebIDL::ExceptionOr<JS::NonnullGCPtr<Streams::ReadableStream>> get_stream();
JS::NonnullGCPtr<Streams::ReadableStream> get_stream();
virtual StringView interface_name() const override { return "Blob"sv; }

View File

@ -130,7 +130,7 @@ WebIDL::ExceptionOr<void> FileReader::read_operation(Blob& blob, Type type, Opti
m_error = {};
// 5. Let stream be the result of calling get stream on blob.
auto stream = TRY(blob.get_stream());
auto stream = blob.get_stream();
// 6. Let reader be the result of getting a reader from stream.
auto reader = TRY(acquire_readable_stream_default_reader(*stream));

View File

@ -3148,7 +3148,7 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_enqueue(ReadableByteSt
readable_byte_stream_controller_invalidate_byob_request(controller);
// 4. Set firstPendingPullIntos buffer to ! TransferArrayBuffer(firstPendingPullIntos buffer).
first_pending_pull_into.buffer = TRY(transfer_array_buffer(realm, first_pending_pull_into.buffer));
first_pending_pull_into.buffer = MUST(transfer_array_buffer(realm, first_pending_pull_into.buffer));
// 5. If firstPendingPullIntos reader type is "none", perform ? ReadableByteStreamControllerEnqueueDetachedPullIntoToQueue(controller, firstPendingPullInto).
if (first_pending_pull_into.reader_type == ReaderType::None)
@ -3394,7 +3394,7 @@ PullIntoDescriptor readable_byte_stream_controller_shift_pending_pull_into(Reada
}
// https://streams.spec.whatwg.org/#readablestream-set-up-with-byte-reading-support
WebIDL::ExceptionOr<void> set_up_readable_stream_controller_with_byte_reading_support(ReadableStream& stream, JS::GCPtr<PullAlgorithm> pull_algorithm, JS::GCPtr<CancelAlgorithm> cancel_algorithm, double high_water_mark)
void set_up_readable_stream_controller_with_byte_reading_support(ReadableStream& stream, JS::GCPtr<PullAlgorithm> pull_algorithm, JS::GCPtr<CancelAlgorithm> cancel_algorithm, double high_water_mark)
{
auto& realm = stream.realm();
@ -3436,9 +3436,7 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_controller_with_byte_reading_su
auto controller = stream.heap().allocate<ReadableByteStreamController>(realm, realm);
// 6. Perform ! SetUpReadableByteStreamController(stream, controller, startAlgorithm, pullAlgorithmWrapper, cancelAlgorithmWrapper, highWaterMark, undefined).
TRY(set_up_readable_byte_stream_controller(stream, controller, start_algorithm, pull_algorithm_wrapper, cancel_algorithm_wrapper, high_water_mark, JS::js_undefined()));
return {};
MUST(set_up_readable_byte_stream_controller(stream, controller, start_algorithm, pull_algorithm_wrapper, cancel_algorithm_wrapper, high_water_mark, JS::js_undefined()));
}
// https://streams.spec.whatwg.org/#writable-stream-abort
@ -3495,7 +3493,7 @@ JS::NonnullGCPtr<WebIDL::Promise> writable_stream_abort(WritableStream& stream,
}
// https://streams.spec.whatwg.org/#writable-stream-close
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(WritableStream& stream)
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_close(WritableStream& stream)
{
auto& realm = stream.realm();
@ -3529,7 +3527,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(Wri
WebIDL::resolve_promise(realm, *writer->ready_promise(), JS::js_undefined());
// 9. Perform ! WritableStreamDefaultControllerClose(stream.[[controller]]).
TRY(writable_stream_default_controller_close(*stream.controller()));
writable_stream_default_controller_close(*stream.controller());
// 10. Return promise.
return promise;
@ -3942,7 +3940,7 @@ JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_abort(WritableS
}
// https://streams.spec.whatwg.org/#writable-stream-default-writer-close
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_default_writer_close(WritableStreamDefaultWriter& writer)
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_close(WritableStreamDefaultWriter& writer)
{
// 1. Let stream be writer.[[stream]].
auto stream = writer.stream();
@ -4313,15 +4311,13 @@ void writable_stream_default_controller_clear_algorithms(WritableStreamDefaultCo
}
// https://streams.spec.whatwg.org/#writable-stream-default-controller-close
WebIDL::ExceptionOr<void> writable_stream_default_controller_close(WritableStreamDefaultController& controller)
void writable_stream_default_controller_close(WritableStreamDefaultController& controller)
{
// 1. Perform ! EnqueueValueWithSize(controller, close sentinel, 0).
TRY(enqueue_value_with_size(controller, create_close_sentinel(), JS::Value(0.0)));
MUST(enqueue_value_with_size(controller, create_close_sentinel(), JS::Value(0.0)));
// 2. Perform ! WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller).
writable_stream_default_controller_advance_queue_if_needed(controller);
return {};
}
// https://streams.spec.whatwg.org/#writable-stream-default-controller-error
@ -4512,7 +4508,7 @@ void writable_stream_default_controller_write(WritableStreamDefaultController& c
}
// https://streams.spec.whatwg.org/#initialize-transform-stream
WebIDL::ExceptionOr<void> initialize_transform_stream(TransformStream& stream, JS::NonnullGCPtr<JS::PromiseCapability> start_promise, double writable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> writable_size_algorithm, double readable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> readable_size_algorithm)
void initialize_transform_stream(TransformStream& stream, JS::NonnullGCPtr<JS::PromiseCapability> start_promise, double writable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> writable_size_algorithm, double readable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> readable_size_algorithm)
{
auto& realm = stream.realm();
@ -4534,7 +4530,7 @@ WebIDL::ExceptionOr<void> initialize_transform_stream(TransformStream& stream, J
// 3. Let abortAlgorithm be the following steps, taking a reason argument:
auto abort_algorithm = JS::create_heap_function(realm.heap(), [&stream](JS::Value reason) {
// 1. Return ! TransformStreamDefaultSinkAbortAlgorithm(stream, reason).
return MUST(transform_stream_default_sink_abort_algorithm(stream, reason));
return transform_stream_default_sink_abort_algorithm(stream, reason);
});
// 4. Let closeAlgorithm be the following steps:
@ -4544,37 +4540,35 @@ WebIDL::ExceptionOr<void> initialize_transform_stream(TransformStream& stream, J
});
// 5. Set stream.[[writable]] to ! CreateWritableStream(startAlgorithm, writeAlgorithm, closeAlgorithm, abortAlgorithm, writableHighWaterMark, writableSizeAlgorithm).
stream.set_writable(TRY(create_writable_stream(realm, writable_start_algorithm, write_algorithm, close_algorithm, abort_algorithm, writable_high_water_mark, writable_size_algorithm)));
stream.set_writable(MUST(create_writable_stream(realm, writable_start_algorithm, write_algorithm, close_algorithm, abort_algorithm, writable_high_water_mark, writable_size_algorithm)));
// 6. Let pullAlgorithm be the following steps:
auto pull_algorithm = JS::create_heap_function(realm.heap(), [&stream]() {
// 1. Return ! TransformStreamDefaultSourcePullAlgorithm(stream).
return MUST(transform_stream_default_source_pull_algorithm(stream));
return transform_stream_default_source_pull_algorithm(stream);
});
// 7. Let cancelAlgorithm be the following steps, taking a reason argument:
auto cancel_algorithm = JS::create_heap_function(realm.heap(), [&stream, &realm](JS::Value reason) {
// 1. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, reason).
MUST(transform_stream_error_writable_and_unblock_write(stream, reason));
transform_stream_error_writable_and_unblock_write(stream, reason);
// 2. Return a promise resolved with undefined.
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
});
// 8. Set stream.[[readable]] to ! CreateReadableStream(startAlgorithm, pullAlgorithm, cancelAlgorithm, readableHighWaterMark, readableSizeAlgorithm).
stream.set_readable(TRY(create_readable_stream(realm, readable_start_algorithm, pull_algorithm, cancel_algorithm, readable_high_water_mark, readable_size_algorithm)));
stream.set_readable(MUST(create_readable_stream(realm, readable_start_algorithm, pull_algorithm, cancel_algorithm, readable_high_water_mark, readable_size_algorithm)));
// 9. Set stream.[[backpressure]] and stream.[[backpressureChangePromise]] to undefined.
stream.set_backpressure({});
stream.set_backpressure_change_promise({});
// 10. Perform ! TransformStreamSetBackpressure(stream, true).
TRY(transform_stream_set_backpressure(stream, true));
transform_stream_set_backpressure(stream, true);
// 11. Set stream.[[controller]] to undefined.
stream.set_controller({});
return {};
}
// https://streams.spec.whatwg.org/#set-up-transform-stream-default-controller
@ -4688,7 +4682,7 @@ WebIDL::ExceptionOr<void> transform_stream_default_controller_enqueue(TransformS
auto throw_completion = Bindings::dom_exception_to_throw_completion(vm, enqueue_result.exception());
// 1. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, enqueueResult.[[Value]]).
TRY(transform_stream_error_writable_and_unblock_write(*stream, throw_completion.value().value()));
transform_stream_error_writable_and_unblock_write(*stream, throw_completion.value().value());
// 2. Throw stream.[[readable]].[[storedError]].
return JS::throw_completion(stream->readable()->stored_error());
@ -4703,23 +4697,21 @@ WebIDL::ExceptionOr<void> transform_stream_default_controller_enqueue(TransformS
VERIFY(backpressure);
// 2. Perform ! TransformStreamSetBackpressure(stream, true).
TRY(transform_stream_set_backpressure(*stream, true));
transform_stream_set_backpressure(*stream, true);
}
return {};
}
// https://streams.spec.whatwg.org/#transform-stream-default-controller-error
WebIDL::ExceptionOr<void> transform_stream_default_controller_error(TransformStreamDefaultController& controller, JS::Value error)
void transform_stream_default_controller_error(TransformStreamDefaultController& controller, JS::Value error)
{
// 1. Perform ! TransformStreamError(controller.[[stream]], e).
TRY(transform_stream_error(*controller.stream(), error));
return {};
transform_stream_error(*controller.stream(), error);
}
// https://streams.spec.whatwg.org/#transform-stream-default-controller-terminate
WebIDL::ExceptionOr<void> transform_stream_default_controller_terminate(TransformStreamDefaultController& controller)
void transform_stream_default_controller_terminate(TransformStreamDefaultController& controller)
{
auto& realm = controller.realm();
@ -4737,9 +4729,7 @@ WebIDL::ExceptionOr<void> transform_stream_default_controller_terminate(Transfor
auto error = JS::TypeError::create(realm, "Stream has been terminated."sv);
// 5. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, error).
TRY(transform_stream_error_writable_and_unblock_write(*stream, error));
return {};
transform_stream_error_writable_and_unblock_write(*stream, error);
}
// https://streams.spec.whatwg.org/#transform-stream-default-controller-perform-transform
@ -4755,7 +4745,7 @@ JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_controller_perform_tr
{},
JS::create_heap_function(realm.heap(), [&controller](JS::Value reason) -> WebIDL::ExceptionOr<JS::Value> {
// 1. Perform ! TransformStreamError(controller.[[stream]], r).
TRY(transform_stream_error(*controller.stream(), reason));
transform_stream_error(*controller.stream(), reason);
// 2. Throw r.
return JS::throw_completion(reason);
@ -4765,12 +4755,12 @@ JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_controller_perform_tr
}
// https://streams.spec.whatwg.org/#transform-stream-default-sink-abort-algorithm
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_abort_algorithm(TransformStream& stream, JS::Value reason)
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_abort_algorithm(TransformStream& stream, JS::Value reason)
{
auto& realm = stream.realm();
// 1. Perform ! TransformStreamError(stream, reason).
TRY(transform_stream_error(stream, reason));
transform_stream_error(stream, reason);
// 2. Return a promise resolved with undefined.
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
@ -4811,7 +4801,7 @@ JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_close_algorithm(
// 2. If flushPromise was rejected with reason r, then:
JS::create_heap_function(realm.heap(), [&stream, readable](JS::Value reason) -> WebIDL::ExceptionOr<JS::Value> {
// 1. Perform ! TransformStreamError(stream, r).
TRY(transform_stream_error(stream, reason));
transform_stream_error(stream, reason);
// 2. Throw readable.[[storedError]].
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, readable->stored_error().as_string().utf8_string() };
@ -4867,7 +4857,7 @@ JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_write_algorithm(
return transform_stream_default_controller_perform_transform(*controller, chunk);
}
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_source_pull_algorithm(TransformStream& stream)
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_source_pull_algorithm(TransformStream& stream)
{
// 1. Assert: stream.[[backpressure]] is true.
VERIFY(stream.backpressure().has_value() && *stream.backpressure());
@ -4876,14 +4866,14 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_
VERIFY(stream.backpressure_change_promise());
// 3. Perform ! TransformStreamSetBackpressure(stream, false).
TRY(transform_stream_set_backpressure(stream, false));
transform_stream_set_backpressure(stream, false);
// 4. Return stream.[[backpressureChangePromise]].
return JS::NonnullGCPtr { *stream.backpressure_change_promise() };
}
// https://streams.spec.whatwg.org/#transform-stream-error
WebIDL::ExceptionOr<void> transform_stream_error(TransformStream& stream, JS::Value error)
void transform_stream_error(TransformStream& stream, JS::Value error)
{
VERIFY(stream.readable()->controller().has_value() && stream.readable()->controller()->has<JS::NonnullGCPtr<ReadableStreamDefaultController>>());
@ -4893,13 +4883,11 @@ WebIDL::ExceptionOr<void> transform_stream_error(TransformStream& stream, JS::Va
readable_stream_default_controller_error(*readable_controller, error);
// 2. Perform ! TransformStreamErrorWritableAndUnblockWrite(stream, e).
TRY(transform_stream_error_writable_and_unblock_write(stream, error));
return {};
transform_stream_error_writable_and_unblock_write(stream, error);
}
// https://streams.spec.whatwg.org/#transform-stream-error-writable-and-unblock-write
WebIDL::ExceptionOr<void> transform_stream_error_writable_and_unblock_write(TransformStream& stream, JS::Value error)
void transform_stream_error_writable_and_unblock_write(TransformStream& stream, JS::Value error)
{
// 1. Perform ! TransformStreamDefaultControllerClearAlgorithms(stream.[[controller]]).
transform_stream_default_controller_clear_algorithms(*stream.controller());
@ -4909,13 +4897,11 @@ WebIDL::ExceptionOr<void> transform_stream_error_writable_and_unblock_write(Tran
// 3. If stream.[[backpressure]] is true, perform ! TransformStreamSetBackpressure(stream, false).
if (stream.backpressure().has_value() && *stream.backpressure())
TRY(transform_stream_set_backpressure(stream, false));
return {};
transform_stream_set_backpressure(stream, false);
}
// https://streams.spec.whatwg.org/#transform-stream-set-backpressure
WebIDL::ExceptionOr<void> transform_stream_set_backpressure(TransformStream& stream, bool backpressure)
void transform_stream_set_backpressure(TransformStream& stream, bool backpressure)
{
auto& realm = stream.realm();
@ -4931,8 +4917,6 @@ WebIDL::ExceptionOr<void> transform_stream_set_backpressure(TransformStream& str
// 4. Set stream.[[backpressure]] to backpressure.
stream.set_backpressure(backpressure);
return {};
}
// https://streams.spec.whatwg.org/#is-non-negative-number

View File

@ -81,7 +81,7 @@ Optional<double> readable_stream_default_controller_get_desired_size(ReadableStr
bool readable_stream_default_controller_can_close_or_enqueue(ReadableStreamDefaultController&);
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStream&, ReadableStreamDefaultController&, JS::NonnullGCPtr<StartAlgorithm>, JS::NonnullGCPtr<PullAlgorithm>, JS::NonnullGCPtr<CancelAlgorithm>, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm>);
WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source_value, UnderlyingSource, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm>);
WebIDL::ExceptionOr<void> set_up_readable_stream_controller_with_byte_reading_support(ReadableStream&, JS::GCPtr<PullAlgorithm> = {}, JS::GCPtr<CancelAlgorithm> = {}, double high_water_mark = 0);
void set_up_readable_stream_controller_with_byte_reading_support(ReadableStream&, JS::GCPtr<PullAlgorithm> = {}, JS::GCPtr<CancelAlgorithm> = {}, double high_water_mark = 0);
WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller(ReadableStream&, ReadableByteStreamController&, JS::NonnullGCPtr<StartAlgorithm>, JS::NonnullGCPtr<PullAlgorithm>, JS::NonnullGCPtr<CancelAlgorithm>, double high_water_mark, JS::Value auto_allocate_chunk_size);
WebIDL::ExceptionOr<void> set_up_readable_byte_stream_controller_from_underlying_source(ReadableStream&, JS::Value underlying_source, UnderlyingSource const& underlying_source_dict, double high_water_mark);
JS::GCPtr<ReadableStreamBYOBRequest> readable_byte_stream_controller_get_byob_request(JS::NonnullGCPtr<ReadableByteStreamController>);
@ -125,7 +125,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> acquire_writa
bool is_writable_stream_locked(WritableStream const&);
WebIDL::ExceptionOr<void> set_up_writable_stream_default_writer(WritableStreamDefaultWriter&, WritableStream&);
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_abort(WritableStream&, JS::Value reason);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_close(WritableStream&);
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_close(WritableStream&);
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_add_write_request(WritableStream&);
bool writable_stream_close_queued_or_in_flight(WritableStream const&);
@ -143,7 +143,7 @@ void writable_stream_start_erroring(WritableStream&, JS::Value reason);
void writable_stream_update_backpressure(WritableStream&, bool backpressure);
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_abort(WritableStreamDefaultWriter&, JS::Value reason);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> writable_stream_default_writer_close(WritableStreamDefaultWriter&);
JS::NonnullGCPtr<WebIDL::Promise> writable_stream_default_writer_close(WritableStreamDefaultWriter&);
void writable_stream_default_writer_ensure_closed_promise_rejected(WritableStreamDefaultWriter&, JS::Value error);
void writable_stream_default_writer_ensure_ready_promise_rejected(WritableStreamDefaultWriter&, JS::Value error);
Optional<double> writable_stream_default_writer_get_desired_size(WritableStreamDefaultWriter const&);
@ -154,7 +154,7 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller(WritableStre
WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underlying_sink(WritableStream&, JS::Value underlying_sink_value, UnderlyingSink&, double high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> size_algorithm);
void writable_stream_default_controller_advance_queue_if_needed(WritableStreamDefaultController&);
void writable_stream_default_controller_clear_algorithms(WritableStreamDefaultController&);
WebIDL::ExceptionOr<void> writable_stream_default_controller_close(WritableStreamDefaultController&);
void writable_stream_default_controller_close(WritableStreamDefaultController&);
void writable_stream_default_controller_error(WritableStreamDefaultController&, JS::Value error);
void writable_stream_default_controller_error_if_needed(WritableStreamDefaultController&, JS::Value error);
bool writable_stream_default_controller_get_backpressure(WritableStreamDefaultController const&);
@ -164,21 +164,21 @@ void writable_stream_default_controller_process_close(WritableStreamDefaultContr
void writable_stream_default_controller_process_write(WritableStreamDefaultController&, JS::Value chunk);
void writable_stream_default_controller_write(WritableStreamDefaultController&, JS::Value chunk, JS::Value chunk_size);
WebIDL::ExceptionOr<void> initialize_transform_stream(TransformStream&, JS::NonnullGCPtr<JS::PromiseCapability> start_promise, double writable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> writable_size_algorithm, double readable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> readable_size_algorithm);
void initialize_transform_stream(TransformStream&, JS::NonnullGCPtr<JS::PromiseCapability> start_promise, double writable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> writable_size_algorithm, double readable_high_water_mark, JS::NonnullGCPtr<SizeAlgorithm> readable_size_algorithm);
void set_up_transform_stream_default_controller(TransformStream&, TransformStreamDefaultController&, JS::NonnullGCPtr<TransformAlgorithm>, JS::NonnullGCPtr<FlushAlgorithm>);
WebIDL::ExceptionOr<void> set_up_transform_stream_default_controller_from_transformer(TransformStream&, JS::Value transformer, Transformer&);
void transform_stream_default_controller_clear_algorithms(TransformStreamDefaultController&);
WebIDL::ExceptionOr<void> transform_stream_default_controller_enqueue(TransformStreamDefaultController&, JS::Value chunk);
WebIDL::ExceptionOr<void> transform_stream_default_controller_error(TransformStreamDefaultController&, JS::Value error);
WebIDL::ExceptionOr<void> transform_stream_default_controller_terminate(TransformStreamDefaultController&);
void transform_stream_default_controller_error(TransformStreamDefaultController&, JS::Value error);
void transform_stream_default_controller_terminate(TransformStreamDefaultController&);
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_controller_perform_transform(TransformStreamDefaultController&, JS::Value chunk);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_sink_abort_algorithm(TransformStream&, JS::Value reason);
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_abort_algorithm(TransformStream&, JS::Value reason);
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_close_algorithm(TransformStream&);
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_sink_write_algorithm(TransformStream&, JS::Value chunk);
WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>> transform_stream_default_source_pull_algorithm(TransformStream&);
WebIDL::ExceptionOr<void> transform_stream_error(TransformStream&, JS::Value error);
WebIDL::ExceptionOr<void> transform_stream_error_writable_and_unblock_write(TransformStream&, JS::Value error);
WebIDL::ExceptionOr<void> transform_stream_set_backpressure(TransformStream&, bool backpressure);
JS::NonnullGCPtr<WebIDL::Promise> transform_stream_default_source_pull_algorithm(TransformStream&);
void transform_stream_error(TransformStream&, JS::Value error);
void transform_stream_error_writable_and_unblock_write(TransformStream&, JS::Value error);
void transform_stream_set_backpressure(TransformStream&, bool backpressure);
bool is_non_negative_number(JS::Value);
bool can_transfer_array_buffer(JS::ArrayBuffer const& array_buffer);

View File

@ -54,9 +54,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<TransformStream>> TransformStream::construc
// 9. Let startPromise be a new promise.
auto start_promise = WebIDL::create_promise(realm);
// 10. Perform ! InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm,
// readableHighWaterMark, readableSizeAlgorithm).
TRY(initialize_transform_stream(*stream, start_promise, writable_high_water_mark, move(writable_size_algorithm), readable_high_water_mark, move(readable_size_algorithm)));
// 10. Perform ! InitializeTransformStream(this, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm).
initialize_transform_stream(*stream, start_promise, writable_high_water_mark, move(writable_size_algorithm), readable_high_water_mark, move(readable_size_algorithm));
// 11. Perform ? SetUpTransformStreamDefaultControllerFromTransformer(this, transformer, transformerDict).
TRY(set_up_transform_stream_default_controller_from_transformer(*stream, transformer, transformer_dict));

View File

@ -56,21 +56,17 @@ WebIDL::ExceptionOr<void> TransformStreamDefaultController::enqueue(Optional<JS:
}
// https://streams.spec.whatwg.org/#ts-default-controller-error
WebIDL::ExceptionOr<void> TransformStreamDefaultController::error(Optional<JS::Value> reason)
void TransformStreamDefaultController::error(Optional<JS::Value> reason)
{
// 1. Perform ? TransformStreamDefaultControllerError(this, e).
TRY(transform_stream_default_controller_error(*this, reason.has_value() ? reason.value() : JS::js_undefined()));
return {};
transform_stream_default_controller_error(*this, reason.has_value() ? reason.value() : JS::js_undefined());
}
// https://streams.spec.whatwg.org/#ts-default-controller-terminate
WebIDL::ExceptionOr<void> TransformStreamDefaultController::terminate()
void TransformStreamDefaultController::terminate()
{
// 1. Perform ? TransformStreamDefaultControllerTerminate(this).
TRY(transform_stream_default_controller_terminate(*this));
return {};
transform_stream_default_controller_terminate(*this);
}
}

View File

@ -21,8 +21,8 @@ public:
Optional<double> desired_size();
WebIDL::ExceptionOr<void> enqueue(Optional<JS::Value> chunk);
WebIDL::ExceptionOr<void> error(Optional<JS::Value> reason = {});
WebIDL::ExceptionOr<void> terminate();
void error(Optional<JS::Value> reason = {});
void terminate();
JS::GCPtr<FlushAlgorithm> flush_algorithm() { return m_flush_algorithm; }
void set_flush_algorithm(JS::GCPtr<FlushAlgorithm>&& value) { m_flush_algorithm = move(value); }

View File

@ -58,7 +58,7 @@ bool WritableStream::locked() const
}
// https://streams.spec.whatwg.org/#ws-close
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStream::close()
JS::GCPtr<JS::Object> WritableStream::close()
{
auto& realm = this->realm();
@ -75,7 +75,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStream::close()
}
// 3. Return ! WritableStreamClose(this).
return TRY(writable_stream_close(*this))->promise();
return writable_stream_close(*this)->promise();
}
// https://streams.spec.whatwg.org/#ws-abort

View File

@ -50,7 +50,7 @@ public:
bool locked() const;
JS::GCPtr<JS::Object> abort(JS::Value reason);
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> close();
JS::GCPtr<JS::Object> close();
WebIDL::ExceptionOr<JS::NonnullGCPtr<WritableStreamDefaultWriter>> get_writer();
bool backpressure() const { return m_backpressure; }

View File

@ -52,7 +52,7 @@ JS::GCPtr<JS::Object> WritableStreamDefaultWriter::ready()
}
// https://streams.spec.whatwg.org/#default-writer-abort
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::abort(JS::Value reason)
JS::GCPtr<JS::Object> WritableStreamDefaultWriter::abort(JS::Value reason)
{
auto& realm = this->realm();
@ -67,7 +67,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::abort(JS
}
// https://streams.spec.whatwg.org/#default-writer-close
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::close()
JS::GCPtr<JS::Object> WritableStreamDefaultWriter::close()
{
auto& realm = this->realm();
@ -86,7 +86,7 @@ WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::close()
}
// 4. Return ! WritableStreamDefaultWriterClose(this).
return TRY(writable_stream_default_writer_close(*this))->promise();
return writable_stream_default_writer_close(*this)->promise();
}
// https://streams.spec.whatwg.org/#default-writer-release-lock
@ -106,7 +106,7 @@ WebIDL::ExceptionOr<void> WritableStreamDefaultWriter::release_lock()
}
// https://streams.spec.whatwg.org/#default-writer-write
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> WritableStreamDefaultWriter::write(JS::Value chunk)
JS::GCPtr<JS::Object> WritableStreamDefaultWriter::write(JS::Value chunk)
{
auto& realm = this->realm();

View File

@ -28,10 +28,10 @@ public:
JS::GCPtr<JS::Object> closed();
WebIDL::ExceptionOr<Optional<double>> desired_size() const;
JS::GCPtr<JS::Object> ready();
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> abort(JS::Value reason);
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> close();
JS::GCPtr<JS::Object> abort(JS::Value reason);
JS::GCPtr<JS::Object> close();
WebIDL::ExceptionOr<void> release_lock();
WebIDL::ExceptionOr<JS::GCPtr<JS::Object>> write(JS::Value chunk);
JS::GCPtr<JS::Object> write(JS::Value chunk);
JS::GCPtr<WebIDL::Promise> closed_promise() { return m_closed_promise; }
void set_closed_promise(JS::GCPtr<WebIDL::Promise> value) { m_closed_promise = value; }