core: Dispatch IOErrorEvent when connection fails

This commit is contained in:
sleepycatcoding 2023-07-15 18:17:47 +03:00 committed by Nathan Adams
parent d1a17ebeb1
commit ea7264eab5
2 changed files with 17 additions and 2 deletions

View File

@ -26,7 +26,6 @@ pub fn connect<'gc>(
} = &mut activation.context; } = &mut activation.context;
sockets.connect(*navigator, socket, host.to_utf8_lossy().into_owned(), port); sockets.connect(*navigator, socket, host.to_utf8_lossy().into_owned(), port);
// FIXME: Are we supposed to throw and IOError when a connection fails?
Ok(Value::Undefined) Ok(Value::Undefined)
} }

View File

@ -129,7 +129,23 @@ impl<'gc> Sockets<'gc> {
EventObject::bare_default_event(&mut activation.context, "connect"); EventObject::bare_default_event(&mut activation.context, "connect");
Avm2::dispatch_event(&mut activation.context, connect_evt, target.into()); Avm2::dispatch_event(&mut activation.context, connect_evt, target.into());
} else { } else {
// FIXME: Dispatch ioError event as connection failed. let target = activation
.context
.sockets
.sockets
.get(handle)
.expect("only valid handles in SocketAction")
.target;
let io_error_evt = activation.avm2().classes().ioerrorevent.construct(&mut activation, &[
"ioError".into(),
false.into(),
false.into(),
"TODO".into(),
0.into()
]).expect("IOErrorEvent should be constructed");
Avm2::dispatch_event(&mut activation.context, io_error_evt, target.into());
} }
} }
SocketAction::Data(handle, data) => { SocketAction::Data(handle, data) => {