Script implement TransformStream and TransformStreamDefaultController (#36739)

Part of https://github.com/servo/servo/issues/34676

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Signed-off-by: Taym <haddadi.taym@gmail.com>
Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Taym Haddadi 2025-05-08 10:45:57 +02:00 committed by GitHub
parent d39b9f05ff
commit f3f4cc5500
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 1784 additions and 48 deletions

View file

@ -20,6 +20,7 @@ use crate::dom::defaultteeunderlyingsource::DefaultTeeUnderlyingSource;
use crate::dom::globalscope::GlobalScope;
use crate::dom::messageport::MessagePort;
use crate::dom::promise::Promise;
use crate::dom::transformstream::TransformStream;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
/// <https://streams.spec.whatwg.org/#underlying-source-api>
@ -46,8 +47,7 @@ pub(crate) enum UnderlyingSourceType {
/// A struct representing a JS object as underlying source,
/// and the actual JS object for use as `thisArg` in callbacks.
/// This is used for the `TransformStream` API.
#[allow(unused)]
Transform(/* Dom<TransformStream>, Rc<Promise>*/),
Transform(Dom<TransformStream>, Rc<Promise>),
}
impl UnderlyingSourceType {
@ -139,9 +139,9 @@ impl UnderlyingSourceContainer {
// Call the cancel algorithm for the appropriate branch.
tee_underlying_source.cancel_algorithm(cx, global, reason, can_gc)
},
UnderlyingSourceType::Transform() => {
UnderlyingSourceType::Transform(stream, _) => {
// Return ! TransformStreamDefaultSourceCancelAlgorithm(stream, reason).
todo!();
Some(stream.transform_stream_default_source_cancel(cx, global, reason, can_gc))
},
UnderlyingSourceType::Transfer(port) => {
// Let cancelAlgorithm be the following steps, taking a reason argument:
@ -213,9 +213,9 @@ impl UnderlyingSourceContainer {
Some(Ok(promise))
},
// Note: other source type have no pull steps for now.
UnderlyingSourceType::Transform() => {
UnderlyingSourceType::Transform(stream, _) => {
// Return ! TransformStreamDefaultSourcePullAlgorithm(stream).
todo!();
Some(stream.transform_stream_default_source_pull(&self.global(), can_gc))
},
_ => None,
}
@ -280,9 +280,9 @@ impl UnderlyingSourceContainer {
// from <https://streams.spec.whatwg.org/#abstract-opdef-setupcrossrealmtransformreadable
None
},
UnderlyingSourceType::Transform() => {
// Some(transform_underlying_source.start_algorithm())
todo!();
UnderlyingSourceType::Transform(_, start_promise) => {
// Let startAlgorithm be an algorithm that returns startPromise.
Some(Ok(start_promise.clone()))
},
_ => None,
}