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::avm_warn;
use crate::context::{GcContext, UpdateContext}; use crate::context::{GcContext, UpdateContext};
use crate::socket::SocketHandle; use crate::socket::SocketHandle;
use std::cell::Cell;
use gc_arena::{Collect, Gc}; use gc_arena::{Collect, Gc};
use std::cell::Cell;
#[derive(Clone, Debug, Collect)] #[derive(Clone, Debug, Collect)]
#[collect(require_static)] #[collect(require_static)]
@ -26,10 +26,7 @@ impl<'gc> XmlSocket<'gc> {
self.0.handle.get() self.0.handle.get()
} }
pub fn set_handle( pub fn set_handle(&self, handle: SocketHandle) -> Option<SocketHandle> {
&self,
handle: SocketHandle,
) -> Option<SocketHandle> {
self.0.handle.replace(Some(handle)) self.0.handle.replace(Some(handle))
} }
@ -109,13 +106,17 @@ pub fn connect<'gc>(
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
if let Some(_) = XmlSocket::cast(this.into()) { if let Some(_) = XmlSocket::cast(this.into()) {
// FIXME: When host is null, use the current movie domain. // FIXME: When host is null, use the current movie domain.
let host = args.get(0).unwrap_or(&Value::Undefined).coerce_to_string(activation)?; let host = args
let port = args.get(1).unwrap_or(&Value::Undefined).coerce_to_u16(activation)?; .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 { let UpdateContext {
sockets, sockets, navigator, ..
navigator,
..
} = &mut activation.context; } = &mut activation.context;
sockets.connect_avm1(*navigator, this, host.to_utf8_lossy().into_owned(), port); 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>> { ) -> Result<Value<'gc>, Error<'gc>> {
if let Some(xml_socket) = XmlSocket::cast(this.into()) { if let Some(xml_socket) = XmlSocket::cast(this.into()) {
if let Some(handle) = xml_socket.handle() { 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::{ use crate::{
avm1::{globals::xml_socket::XmlSocket, Activation, ActivationIdentifier, ExecutionReason, TObject, Object}, avm1::{
avm2::{object::SocketObject, Activation as Avm2Activation, Avm2, EventObject, TObject as Avm2TObject}, globals::xml_socket::XmlSocket, Activation, ActivationIdentifier, ExecutionReason, Object,
TObject,
},
avm2::{
object::SocketObject, Activation as Avm2Activation, Avm2, EventObject,
TObject as Avm2TObject,
},
backend::navigator::NavigatorBackend, backend::navigator::NavigatorBackend,
context::UpdateContext, context::UpdateContext,
}; };
@ -116,7 +122,7 @@ impl<'gc> Sockets<'gc> {
port: u16, port: u16,
) { ) {
let (sender, receiver) = unbounded(); let (sender, receiver) = unbounded();
let xml_socket = match XmlSocket::cast(target.into()) { let xml_socket = match XmlSocket::cast(target.into()) {
Some(xml_socket) => xml_socket, Some(xml_socket) => xml_socket,
None => return, None => return,
@ -187,7 +193,10 @@ impl<'gc> Sockets<'gc> {
); );
} }
SocketKind::Avm1(target) => { 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( let _ = target.call_method(
"onConnect".into(), "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). // 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) => { 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( let _ = target.call_method(
"onConnect".into(), "onConnect".into(),
@ -286,7 +298,10 @@ impl<'gc> Sockets<'gc> {
} }
// TODO: Implement this. // TODO: Implement this.
SocketKind::Avm1(_) => { 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()); Avm2::dispatch_event(&mut activation.context, close_evt, target.into());
} }
SocketKind::Avm1(target) => { 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( let _ = target.call_method(
"onClose".into(), "onClose".into(),