refactor: merge cross_realm_transform_* fields into one (#37102)

In https://github.com/servo/servo/pull/36977, when transferring
`TransformStream`, `CrossRealmTransform::Writable` and
`CrossRealmTransform::Readable` are set to different message ports. The
message port will not be readable and writable at the same time when
transferring the stream, so we can now merge
`cross_realm_transform_readable` and `cross_realm_transform_writable`
into a single field `cross_realm_transform`.

Testing: WPT ([passed on try
branch](https://github.com/pewsheen/servo/actions/runs/15209389525/job/42784179519))
Fixes: https://github.com/servo/servo/issues/37084

---------

Signed-off-by: Jason Tsai <git@pews.dev>
This commit is contained in:
Jason Tsai 2025-05-27 11:27:13 +09:00 committed by GitHub
parent 983bfb2518
commit d76b4a14df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 68 additions and 61 deletions

View file

@ -21,7 +21,9 @@ use super::bindings::structuredclone::StructuredData;
use super::bindings::transferable::Transferable;
use super::messageport::MessagePort;
use super::promisenativehandler::Callback;
use super::readablestream::CrossRealmTransformReadable;
use super::types::{TransformStreamDefaultController, WritableStream};
use super::writablestream::CrossRealmTransformWritable;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::QueuingStrategyBinding::QueuingStrategy;
use crate::dom::bindings::codegen::Bindings::TransformStreamBinding::TransformStreamMethods;
@ -368,6 +370,19 @@ impl Callback for FlushPromiseRejection {
}
}
impl js::gc::Rootable for CrossRealmTransform {}
/// A wrapper to handle `message` and `messageerror` events
/// for the message port used by the transfered stream.
#[derive(Clone, JSTraceable, MallocSizeOf)]
#[cfg_attr(crown, crown::unrooted_must_root_lint::must_root)]
pub(crate) enum CrossRealmTransform {
/// <https://streams.spec.whatwg.org/#abstract-opdef-setupcrossrealmtransformreadable>
Readable(CrossRealmTransformReadable),
/// <https://streams.spec.whatwg.org/#abstract-opdef-setupcrossrealmtransformwritable>
Writable(CrossRealmTransformWritable),
}
/// <https://streams.spec.whatwg.org/#ts-class>
#[dom_struct]
pub struct TransformStream {