[#26488] Refactored RTCDataChannel for safer dropping and added Promise comment (#37332)

Fixes (partially) #26488 and apply the
https://github.com/servo/servo/pull/37324#discussion_r2133989190
comment.

Testing: No tests added
Fixes: Partially #26488

---------

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This commit is contained in:
Domenico Rizzo 2025-06-13 14:20:45 +02:00 committed by GitHub
parent f451dccd0b
commit b8738074d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 25 deletions

View file

@ -8,6 +8,7 @@ use std::rc::Rc;
use dom_struct::dom_struct;
use js::rust::HandleObject;
use script_bindings::weakref::WeakReferenceable;
use servo_media::ServoMedia;
use servo_media::streams::MediaStreamType;
use servo_media::streams::registry::MediaStreamId;
@ -309,15 +310,16 @@ impl RTCPeerConnection {
event.upcast::<Event>().fire(self.upcast(), can_gc);
},
_ => {
let channel = if let Some(channel) = self.data_channels.borrow().get(&channel_id) {
DomRoot::from_ref(&**channel)
} else {
warn!(
"Got an event for an unregistered data channel {:?}",
channel_id
);
return;
};
let channel: DomRoot<RTCDataChannel> =
if let Some(channel) = self.data_channels.borrow().get(&channel_id) {
DomRoot::from_ref(&**channel)
} else {
warn!(
"Got an event for an unregistered data channel {:?}",
channel_id
);
return;
};
match event {
DataChannelEvent::Open => channel.on_open(can_gc),
@ -789,6 +791,8 @@ impl RTCPeerConnectionMethods<crate::DomTypeHolder> for RTCPeerConnection {
}
}
impl WeakReferenceable for RTCPeerConnection {}
impl Convert<RTCSessionDescriptionInit> for SessionDescription {
fn convert(self) -> RTCSessionDescriptionInit {
let type_ = match self.type_ {