avm2: Improve Debug impl for EventObject
This commit is contained in:
parent
3417dceca2
commit
cc9e283191
|
@ -13,6 +13,7 @@ use crate::events::KeyCode;
|
||||||
use crate::string::AvmString;
|
use crate::string::AvmString;
|
||||||
use gc_arena::{Collect, GcCell, MutationContext};
|
use gc_arena::{Collect, GcCell, MutationContext};
|
||||||
use std::cell::{Ref, RefMut};
|
use std::cell::{Ref, RefMut};
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
/// A class instance allocator that allocates Event objects.
|
/// A class instance allocator that allocates Event objects.
|
||||||
pub fn event_allocator<'gc>(
|
pub fn event_allocator<'gc>(
|
||||||
|
@ -31,7 +32,7 @@ pub fn event_allocator<'gc>(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Collect, Debug, Copy)]
|
#[derive(Clone, Collect, Copy)]
|
||||||
#[collect(no_drop)]
|
#[collect(no_drop)]
|
||||||
pub struct EventObject<'gc>(GcCell<'gc, EventObjectData<'gc>>);
|
pub struct EventObject<'gc>(GcCell<'gc, EventObjectData<'gc>>);
|
||||||
|
|
||||||
|
@ -168,3 +169,22 @@ impl<'gc> TObject<'gc> for EventObject<'gc> {
|
||||||
Some(RefMut::map(self.0.write(mc), |d| &mut d.event))
|
Some(RefMut::map(self.0.write(mc), |d| &mut d.event))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'gc> Debug for EventObject<'gc> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||||
|
match self.0.try_read() {
|
||||||
|
Ok(obj) => f
|
||||||
|
.debug_struct("EventObject")
|
||||||
|
.field("type", &obj.event.event_type())
|
||||||
|
.field("class", &obj.base.debug_class_name())
|
||||||
|
.field("ptr", &self.0.as_ptr())
|
||||||
|
.finish(),
|
||||||
|
Err(err) => f
|
||||||
|
.debug_struct("EventObject")
|
||||||
|
.field("type", &err)
|
||||||
|
.field("class", &err)
|
||||||
|
.field("ptr", &self.0.as_ptr())
|
||||||
|
.finish(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue