1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

LibWeb: Make StartAlgorithm return a Value instead of a Promise

This commit is contained in:
Matthew Olsson 2023-04-16 17:40:15 -07:00 committed by Linus Groh
parent bad541a0d4
commit bb9d51fd84
2 changed files with 11 additions and 13 deletions

View file

@ -672,7 +672,7 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller(ReadableStre
auto start_result = TRY(start_algorithm()); auto start_result = TRY(start_algorithm());
// 10. Let startPromise be a promise resolved with startResult. // 10. Let startPromise be a promise resolved with startResult.
auto start_promise = WebIDL::create_resolved_promise(realm, start_result ? start_result->promise() : JS::js_undefined()); auto start_promise = WebIDL::create_resolved_promise(realm, start_result);
// 11. Upon fulfillment of startPromise, // 11. Upon fulfillment of startPromise,
WebIDL::upon_fulfillment(start_promise, [&](auto const&) -> WebIDL::ExceptionOr<JS::Value> { WebIDL::upon_fulfillment(start_promise, [&](auto const&) -> WebIDL::ExceptionOr<JS::Value> {
@ -711,7 +711,7 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underly
auto controller = MUST_OR_THROW_OOM(stream.heap().allocate<ReadableStreamDefaultController>(realm, realm)); auto controller = MUST_OR_THROW_OOM(stream.heap().allocate<ReadableStreamDefaultController>(realm, realm));
// 2. Let startAlgorithm be an algorithm that returns undefined. // 2. Let startAlgorithm be an algorithm that returns undefined.
StartAlgorithm start_algorithm = [] { return JS::GCPtr<WebIDL::Promise> {}; }; StartAlgorithm start_algorithm = [] { return JS::js_undefined(); };
// 3. Let pullAlgorithm be an algorithm that returns a promise resolved with undefined. // 3. Let pullAlgorithm be an algorithm that returns a promise resolved with undefined.
PullAlgorithm pull_algorithm = [&realm]() { PullAlgorithm pull_algorithm = [&realm]() {
@ -725,10 +725,9 @@ WebIDL::ExceptionOr<void> set_up_readable_stream_default_controller_from_underly
// 5. If underlyingSourceDict["start"] exists, then set startAlgorithm to an algorithm which returns the result of invoking underlyingSourceDict["start"] with argument list « controller » and callback this value underlyingSource. // 5. If underlyingSourceDict["start"] exists, then set startAlgorithm to an algorithm which returns the result of invoking underlyingSourceDict["start"] with argument list « controller » and callback this value underlyingSource.
if (underlying_source.start) { if (underlying_source.start) {
start_algorithm = [&, callback = underlying_source.start]() -> WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> { start_algorithm = [&, callback = underlying_source.start]() -> WebIDL::ExceptionOr<JS::Value> {
// Note: callback return a promise, so invoke_callback will never return an abrupt completion // Note: callback does not return a promise, so invoke_callback may return an abrupt completion
auto result = MUST_OR_THROW_OOM(WebIDL::invoke_callback(*callback, underlying_source_value, controller)).release_value(); return WebIDL::invoke_callback(*callback, underlying_source_value, controller);
return WebIDL::create_resolved_promise(realm, result);
}; };
} }
@ -1668,7 +1667,7 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller(WritableStre
auto start_result = TRY(start_algorithm()); auto start_result = TRY(start_algorithm());
// 16. Let startPromise be a promise resolved with startResult. // 16. Let startPromise be a promise resolved with startResult.
auto start_promise = WebIDL::create_resolved_promise(realm, start_result ? start_result->promise() : JS::js_undefined()); auto start_promise = WebIDL::create_resolved_promise(realm, start_result);
// 17. Upon fulfillment of startPromise, // 17. Upon fulfillment of startPromise,
WebIDL::upon_fulfillment(*start_promise, [&](auto const&) -> WebIDL::ExceptionOr<JS::Value> { WebIDL::upon_fulfillment(*start_promise, [&](auto const&) -> WebIDL::ExceptionOr<JS::Value> {
@ -1712,7 +1711,7 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underly
auto controller = MUST_OR_THROW_OOM(realm.heap().allocate<WritableStreamDefaultController>(realm, realm)); auto controller = MUST_OR_THROW_OOM(realm.heap().allocate<WritableStreamDefaultController>(realm, realm));
// 2. Let startAlgorithm be an algorithm that returns undefined. // 2. Let startAlgorithm be an algorithm that returns undefined.
StartAlgorithm start_algorithm = [] { return JS::GCPtr<WebIDL::Promise> {}; }; StartAlgorithm start_algorithm = [] { return JS::js_undefined(); };
// 3. Let writeAlgorithm be an algorithm that returns a promise resolved with undefined. // 3. Let writeAlgorithm be an algorithm that returns a promise resolved with undefined.
WriteAlgorithm write_algorithm = [&realm](auto const&) { WriteAlgorithm write_algorithm = [&realm](auto const&) {
@ -1731,10 +1730,9 @@ WebIDL::ExceptionOr<void> set_up_writable_stream_default_controller_from_underly
// 6. If underlyingSinkDict["start"] exists, then set startAlgorithm to an algorithm which returns the result of invoking underlyingSinkDict["start"] with argument list « controller » and callback this value underlyingSink. // 6. If underlyingSinkDict["start"] exists, then set startAlgorithm to an algorithm which returns the result of invoking underlyingSinkDict["start"] with argument list « controller » and callback this value underlyingSink.
if (underlying_sink.start) { if (underlying_sink.start) {
start_algorithm = [&, callback = underlying_sink.start]() -> WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>> { start_algorithm = [&, callback = underlying_sink.start]() -> WebIDL::ExceptionOr<JS::Value> {
// Note: callback return a promise, so invoke_callback will never return an abrupt completion // Note: callback does not return a promise, so invoke_callback may return an abrupt completion
auto result = MUST_OR_THROW_OOM(WebIDL::invoke_callback(*callback, underlying_sink_value, controller)).release_value(); return WebIDL::invoke_callback(*callback, underlying_sink_value, controller);
return WebIDL::create_resolved_promise(realm, result);
}; };
} }

View file

@ -18,7 +18,7 @@ namespace Web::Streams {
using SizeAlgorithm = JS::SafeFunction<JS::Completion(JS::Value)>; using SizeAlgorithm = JS::SafeFunction<JS::Completion(JS::Value)>;
using PullAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>; using PullAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>;
using CancelAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>; using CancelAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
using StartAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::GCPtr<WebIDL::Promise>>()>; using StartAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::Value>()>;
using AbortAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>; using AbortAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;
using CloseAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>; using CloseAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>()>;
using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>; using WriteAlgorithm = JS::SafeFunction<WebIDL::ExceptionOr<JS::NonnullGCPtr<WebIDL::Promise>>(JS::Value)>;