chore: fmt

This commit is contained in:
sleepycatcoding 2023-08-02 00:50:34 +03:00 committed by Nathan Adams
parent 705042c1ee
commit 2b18a5999b
2 changed files with 43 additions and 19 deletions

View File

@ -6,8 +6,8 @@ use crate::avm1::{Activation, Error, Executable, ExecutionReason, TObject, Value
use crate::avm_warn;
use crate::context::{GcContext, UpdateContext};
use crate::socket::SocketHandle;
use std::cell::Cell;
use gc_arena::{Collect, Gc};
use std::cell::Cell;
#[derive(Clone, Debug, Collect)]
#[collect(require_static)]
@ -26,10 +26,7 @@ impl<'gc> XmlSocket<'gc> {
self.0.handle.get()
}
pub fn set_handle(
&self,
handle: SocketHandle,
) -> Option<SocketHandle> {
pub fn set_handle(&self, handle: SocketHandle) -> Option<SocketHandle> {
self.0.handle.replace(Some(handle))
}
@ -109,13 +106,17 @@ pub fn connect<'gc>(
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(_) = XmlSocket::cast(this.into()) {
// FIXME: When host is null, use the current movie domain.
let host = args.get(0).unwrap_or(&Value::Undefined).coerce_to_string(activation)?;
let port = args.get(1).unwrap_or(&Value::Undefined).coerce_to_u16(activation)?;
let host = args
.get(0)
.unwrap_or(&Value::Undefined)
.coerce_to_string(activation)?;
let port = args
.get(1)
.unwrap_or(&Value::Undefined)
.coerce_to_u16(activation)?;
let UpdateContext {
sockets,
navigator,
..
sockets, navigator, ..
} = &mut activation.context;
sockets.connect_avm1(*navigator, this, host.to_utf8_lossy().into_owned(), port);
@ -135,9 +136,14 @@ pub fn send<'gc>(
) -> Result<Value<'gc>, Error<'gc>> {
if let Some(xml_socket) = XmlSocket::cast(this.into()) {
if let Some(handle) = xml_socket.handle() {
let data = args.get(0).unwrap_or(&Value::Undefined).coerce_to_string(activation)?.to_string().into_bytes();
let data = args
.get(0)
.unwrap_or(&Value::Undefined)
.coerce_to_string(activation)?
.to_string()
.into_bytes();
activation.context.sockets.send(handle, data);
activation.context.sockets.send(handle, data);
}
}

View File

@ -1,6 +1,12 @@
use crate::{
avm1::{globals::xml_socket::XmlSocket, Activation, ActivationIdentifier, ExecutionReason, TObject, Object},
avm2::{object::SocketObject, Activation as Avm2Activation, Avm2, EventObject, TObject as Avm2TObject},
avm1::{
globals::xml_socket::XmlSocket, Activation, ActivationIdentifier, ExecutionReason, Object,
TObject,
},
avm2::{
object::SocketObject, Activation as Avm2Activation, Avm2, EventObject,
TObject as Avm2TObject,
},
backend::navigator::NavigatorBackend,
context::UpdateContext,
};
@ -116,7 +122,7 @@ impl<'gc> Sockets<'gc> {
port: u16,
) {
let (sender, receiver) = unbounded();
let xml_socket = match XmlSocket::cast(target.into()) {
Some(xml_socket) => xml_socket,
None => return,
@ -187,7 +193,10 @@ impl<'gc> Sockets<'gc> {
);
}
SocketKind::Avm1(target) => {
let mut activation = Activation::from_stub(context.reborrow(), ActivationIdentifier::root("[XMLSocket]"));
let mut activation = Activation::from_stub(
context.reborrow(),
ActivationIdentifier::root("[XMLSocket]"),
);
let _ = target.call_method(
"onConnect".into(),
@ -236,7 +245,10 @@ impl<'gc> Sockets<'gc> {
}
// TODO: Not sure if avm1 xmlsocket has a way to notify a error. (Probably should just fire connect event with success as false).
SocketKind::Avm1(target) => {
let mut activation = Activation::from_stub(context.reborrow(), ActivationIdentifier::root("[XMLSocket]"));
let mut activation = Activation::from_stub(
context.reborrow(),
ActivationIdentifier::root("[XMLSocket]"),
);
let _ = target.call_method(
"onConnect".into(),
@ -286,7 +298,10 @@ impl<'gc> Sockets<'gc> {
}
// TODO: Implement this.
SocketKind::Avm1(_) => {
let mut activation = Activation::from_stub(context.reborrow(), ActivationIdentifier::root("[XMLSocket]"));
let mut activation = Activation::from_stub(
context.reborrow(),
ActivationIdentifier::root("[XMLSocket]"),
);
}
}
}
@ -306,7 +321,10 @@ impl<'gc> Sockets<'gc> {
Avm2::dispatch_event(&mut activation.context, close_evt, target.into());
}
SocketKind::Avm1(target) => {
let mut activation = Activation::from_stub(context.reborrow(), ActivationIdentifier::root("[XMLSocket]"));
let mut activation = Activation::from_stub(
context.reborrow(),
ActivationIdentifier::root("[XMLSocket]"),
);
let _ = target.call_method(
"onClose".into(),