mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb/Streams: Move "set up transform stream" to TransformStream
This is not marked as an AO in the spec, and is a publically exported API exposed on TransformStream.
This commit is contained in:
parent
3f572d9ab7
commit
19bbfb023a
Notes:
github-actions[bot]
2024-12-11 14:12:37 +00:00
Author: https://github.com/shannonbooth
Commit: 19bbfb023a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2831
Reviewed-by: https://github.com/kennethmyhra ✅
Reviewed-by: https://github.com/trflynn89
7 changed files with 84 additions and 82 deletions
|
@ -5176,84 +5176,6 @@ void transform_stream_set_backpressure(TransformStream& stream, bool backpressur
|
|||
stream.set_backpressure(backpressure);
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#transformstream-set-up
|
||||
void transform_stream_set_up(TransformStream& stream, GC::Ref<TransformAlgorithm> transform_algorithm, GC::Ptr<FlushAlgorithm> flush_algorithm, GC::Ptr<CancelAlgorithm> cancel_algorithm)
|
||||
{
|
||||
auto& realm = stream.realm();
|
||||
|
||||
// 1. Let writableHighWaterMark be 1.
|
||||
auto writable_high_water_mark = 1.0;
|
||||
|
||||
// 2. Let writableSizeAlgorithm be an algorithm that returns 1.
|
||||
auto writable_size_algorithm = GC::create_function(realm.heap(), [](JS::Value) {
|
||||
return JS::normal_completion(JS::Value { 1 });
|
||||
});
|
||||
|
||||
// 3. Let readableHighWaterMark be 0.
|
||||
auto readable_high_water_mark = 0.0;
|
||||
|
||||
// 4. Let readableSizeAlgorithm be an algorithm that returns 1.
|
||||
auto readable_size_algorithm = GC::create_function(realm.heap(), [](JS::Value) {
|
||||
return JS::normal_completion(JS::Value { 1 });
|
||||
});
|
||||
|
||||
// 5. Let transformAlgorithmWrapper be an algorithm that runs these steps given a value chunk:
|
||||
auto transform_algorithm_wrapper = GC::create_function(realm.heap(), [&realm, transform_algorithm](JS::Value chunk) -> GC::Ref<WebIDL::Promise> {
|
||||
// 1. Let result be the result of running transformAlgorithm given chunk. If this throws an exception e, return a promise rejected with e.
|
||||
GC::Ptr<JS::PromiseCapability> result = nullptr;
|
||||
result = transform_algorithm->function()(chunk);
|
||||
|
||||
// 2. If result is a Promise, then return result.
|
||||
if (result)
|
||||
return GC::Ref { *result };
|
||||
|
||||
// 3. Return a promise resolved with undefined.
|
||||
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
|
||||
});
|
||||
|
||||
// 6. Let flushAlgorithmWrapper be an algorithm that runs these steps:
|
||||
auto flush_algorithm_wrapper = GC::create_function(realm.heap(), [&realm, flush_algorithm]() -> GC::Ref<WebIDL::Promise> {
|
||||
// 1. Let result be the result of running flushAlgorithm, if flushAlgorithm was given, or null otherwise. If this throws an exception e, return a promise rejected with e.
|
||||
GC::Ptr<JS::PromiseCapability> result = nullptr;
|
||||
if (flush_algorithm)
|
||||
result = flush_algorithm->function()();
|
||||
|
||||
// 2. If result is a Promise, then return result.
|
||||
if (result)
|
||||
return GC::Ref { *result };
|
||||
|
||||
// 3. Return a promise resolved with undefined.
|
||||
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
|
||||
});
|
||||
|
||||
// 7. Let cancelAlgorithmWrapper be an algorithm that runs these steps given a value reason:
|
||||
auto cancel_algorithm_wrapper = GC::create_function(realm.heap(), [&realm, cancel_algorithm](JS::Value reason) -> GC::Ref<WebIDL::Promise> {
|
||||
// 1. Let result be the result of running cancelAlgorithm given reason, if cancelAlgorithm was given, or null otherwise. If this throws an exception e, return a promise rejected with e.
|
||||
GC::Ptr<JS::PromiseCapability> result = nullptr;
|
||||
if (cancel_algorithm)
|
||||
result = cancel_algorithm->function()(reason);
|
||||
|
||||
// 2. If result is a Promise, then return result.
|
||||
if (result)
|
||||
return GC::Ref { *result };
|
||||
|
||||
// 3. Return a promise resolved with undefined.
|
||||
return WebIDL::create_resolved_promise(realm, JS::js_undefined());
|
||||
});
|
||||
|
||||
// 8. Let startPromise be a promise resolved with undefined.
|
||||
auto start_promise = WebIDL::create_resolved_promise(realm, JS::js_undefined());
|
||||
|
||||
// 9. Perform ! InitializeTransformStream(stream, startPromise, writableHighWaterMark, writableSizeAlgorithm, readableHighWaterMark, readableSizeAlgorithm).
|
||||
initialize_transform_stream(stream, start_promise, writable_high_water_mark, writable_size_algorithm, readable_high_water_mark, readable_size_algorithm);
|
||||
|
||||
// 10. Let controller be a new TransformStreamDefaultController.
|
||||
auto controller = realm.create<TransformStreamDefaultController>(realm);
|
||||
|
||||
// 11. Perform ! SetUpTransformStreamDefaultController(stream, controller, transformAlgorithmWrapper, flushAlgorithmWrapper, cancelAlgorithmWrapper).
|
||||
set_up_transform_stream_default_controller(stream, controller, transform_algorithm_wrapper, flush_algorithm_wrapper, cancel_algorithm_wrapper);
|
||||
}
|
||||
|
||||
// https://streams.spec.whatwg.org/#transform-stream-unblock-write
|
||||
void transform_stream_unblock_write(TransformStream& stream)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue