Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(webrtc): convert explicit null data channel IDs to zero

ldm089be11fb1b44
diff --git a/moli-renderer-v8/src/context_bootstrap/webrtc/peer_options.rs b/moli-renderer-v8/src/context_bootstrap/webrtc/peer_options.rs
index f5f6960d7..b5dce779b 100644
--- a/moli-renderer-v8/src/context_bootstrap/webrtc/peer_options.rs
+++ b/moli-renderer-v8/src/context_bootstrap/webrtc/peer_options.rs
@@ -38,7 +38,7 @@ pub(super) struct LocalDescriptionArgs<'s> {
#[derive(webidl::WebIdlDictionary)]
#[webidl(prefix = "RTCDataChannelInit", snapshot)]
pub(super) struct DataChannelInit {
- #[webidl(nullable, converter = "enforce_range_unsigned_short", snapshot_slot = RTC_DATA_CHANNEL_ID_SLOT)]
+ #[webidl(converter = "enforce_range_unsigned_short", snapshot_slot = RTC_DATA_CHANNEL_ID_SLOT, snapshot_default = v8::null(scope).into())]
pub(super) id: Option<u16>,
#[webidl(name = "maxPacketLifeTime", snapshot_slot = RTC_DATA_CHANNEL_MAX_PACKET_LIFETIME_SLOT, snapshot_default = v8::null(scope).into())]
pub(super) max_packet_lifetime: Option<u16>,
diff --git a/moli-renderer-v8/tests/fixtures/rtc-peer-dictionaries.js b/moli-renderer-v8/tests/fixtures/rtc-peer-dictionaries.js
index 5f32a4571..2a2724f2c 100644
--- a/moli-renderer-v8/tests/fixtures/rtc-peer-dictionaries.js
+++ b/moli-renderer-v8/tests/fixtures/rtc-peer-dictionaries.js
@@ -33,7 +33,18 @@
channel.close();
const wrapped=live.createDataChannel('wrapped',{maxPacketLifeTime:65536});
assert(wrapped.maxPacketLifeTime===0,'ordinary ushort wraps');wrapped.close();
- for(const init of [{id:-1},{id:65536},{id:65535},{negotiated:true},{maxPacketLifeTime:1,maxRetransmits:1}]){
+ for(const init of [{},{id:undefined}]) {
+ const missing=live.createDataChannel('missing',init);
+ assert(missing.id===null,'missing or undefined id snapshot default');missing.close();
+ }
+ for(const [id,expected] of [[null,0],[false,0],[true,1],['7',7]]) {
+ const converted=live.createDataChannel('converted',{negotiated:true,id});
+ assert(converted.id===expected,'non-nullable id numeric conversion');converted.close();
+ }
+ let idReads=0;
+ const coerced=live.createDataChannel('coerced',{negotiated:true,id:{valueOf(){idReads++;return 7;}}});
+ assert(coerced.id===7 && idReads===1,'id conversion once');coerced.close();
+ for(const init of [{id:-1},{id:65536},{id:65535},{negotiated:true},{negotiated:true,id:undefined},{maxPacketLifeTime:1,maxRetransmits:1}]){
let caught;try{live.createDataChannel('bad',init);}catch(e){caught=e;}
assert(caught instanceof TypeError,'invalid channel options');
}