diff --git a/core/src/avm1/activation.rs b/core/src/avm1/activation.rs index 3b6c06391..9a3cca52e 100644 --- a/core/src/avm1/activation.rs +++ b/core/src/avm1/activation.rs @@ -171,15 +171,6 @@ impl<'a> ActivationIdentifier<'a> { } } -unsafe impl<'gc> gc_arena::Collect for ActivationIdentifier<'gc> { - fn needs_trace() -> bool { - false - } - - #[inline] - fn trace(&self, _cc: gc_arena::CollectionContext) {} -} - pub struct Activation<'a, 'gc: 'a, 'gc_context: 'a> { /// Represents the SWF version of a given function. /// diff --git a/core/src/avm1/function.rs b/core/src/avm1/function.rs index 32f50f074..1e2e0a54d 100644 --- a/core/src/avm1/function.rs +++ b/core/src/avm1/function.rs @@ -10,7 +10,7 @@ use crate::avm1::{ArrayObject, Object, ObjectPtr, ScriptObject, TObject}; use crate::display_object::{DisplayObject, TDisplayObject}; use crate::string::AvmString; use crate::tag_utils::SwfSlice; -use gc_arena::{Collect, CollectionContext, Gc, GcCell, MutationContext}; +use gc_arena::{Collect, Gc, GcCell, MutationContext}; use std::{borrow::Cow, fmt, num::NonZeroU8}; use swf::{avm1::types::FunctionFlags, SwfStr}; @@ -290,25 +290,17 @@ struct Param<'gc> { /// Represents a function that can be defined in the Ruffle runtime or by the /// AVM1 bytecode itself. -#[derive(Clone)] +#[derive(Clone, Collect)] +#[collect(no_drop)] pub enum Executable<'gc> { /// A function provided by the Ruffle runtime and implemented in Rust. - Native(NativeFunction), + Native(#[collect(require_static)] NativeFunction), /// ActionScript data defined by a previous `DefineFunction` or /// `DefineFunction2` action. Action(Gc<'gc, Avm1Function<'gc>>), } -unsafe impl<'gc> Collect for Executable<'gc> { - fn trace(&self, cc: CollectionContext) { - match self { - Self::Native(_) => {} - Self::Action(af) => af.trace(cc), - } - } -} - impl fmt::Debug for Executable<'_> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/core/src/avm1/object/stage_object.rs b/core/src/avm1/object/stage_object.rs index 87c74664d..d83b1c55a 100644 --- a/core/src/avm1/object/stage_object.rs +++ b/core/src/avm1/object/stage_object.rs @@ -345,18 +345,22 @@ impl<'gc> TObject<'gc> for StageObject<'gc> { /// "special" properties stored in a separate map that display objects look at in addition /// to normal property lookup. /// The map of property names to display object getts/setters. -#[derive(Copy, Clone)] -pub struct DisplayProperty<'gc> { - get: DisplayGetter<'gc>, - set: Option>, +#[derive(Copy, Clone, Collect)] +#[collect(require_static)] +pub struct DisplayProperty { + get: DisplayGetter, + set: Option, } -pub type DisplayGetter<'gc> = fn(&mut Activation<'_, 'gc, '_>, DisplayObject<'gc>) -> Value<'gc>; +pub type DisplayGetter = + for<'gc> fn(&mut Activation<'_, 'gc, '_>, DisplayObject<'gc>) -> Value<'gc>; +pub type DisplaySetter = for<'gc> fn( + &mut Activation<'_, 'gc, '_>, + DisplayObject<'gc>, + Value<'gc>, +) -> Result<(), Error<'gc>>; -pub type DisplaySetter<'gc> = - fn(&mut Activation<'_, 'gc, '_>, DisplayObject<'gc>, Value<'gc>) -> Result<(), Error<'gc>>; - -impl<'gc> DisplayProperty<'gc> { +impl<'gc> DisplayProperty { pub fn get( &self, activation: &mut Activation<'_, 'gc, '_>, @@ -378,16 +382,10 @@ impl<'gc> DisplayProperty<'gc> { } } -unsafe impl<'gc> Collect for DisplayProperty<'gc> { - fn needs_trace() -> bool { - false - } -} - /// The map from key/index to function pointers for special display object properties. #[derive(Collect)] #[collect(no_drop)] -pub struct DisplayPropertyMap<'gc>(PropertyMap<'gc, DisplayProperty<'gc>>); +pub struct DisplayPropertyMap<'gc>(PropertyMap<'gc, DisplayProperty>); impl<'gc> DisplayPropertyMap<'gc> { /// Creates the display property map. @@ -428,7 +426,7 @@ impl<'gc> DisplayPropertyMap<'gc> { /// Gets a property slot by name. /// Used by `GetMember`, `GetVariable`, `SetMember`, and `SetVariable`. - pub fn get_by_name(&self, name: AvmString<'gc>) -> Option<&DisplayProperty<'gc>> { + pub fn get_by_name(&self, name: AvmString<'gc>) -> Option<&DisplayProperty> { // Display object properties are case insensitive, regardless of SWF version!? // TODO: Another string alloc; optimize this eventually. self.0.get(name, false) @@ -438,15 +436,15 @@ impl<'gc> DisplayPropertyMap<'gc> { /// The order is defined by the SWF specs. /// Used by `GetProperty`/`SetProperty`. /// SWF19 pp. 85-86 - pub fn get_by_index(&self, index: usize) -> Option<&DisplayProperty<'gc>> { + pub fn get_by_index(&self, index: usize) -> Option<&DisplayProperty> { self.0.get_index(index) } fn add_property( &mut self, name: AvmString<'gc>, - get: DisplayGetter<'gc>, - set: Option>, + get: DisplayGetter, + set: Option, ) { let prop = DisplayProperty { get, set }; self.0.insert(name, prop, false); diff --git a/core/src/avm2/method.rs b/core/src/avm2/method.rs index ce8e5b2c3..e355d49f6 100644 --- a/core/src/avm2/method.rs +++ b/core/src/avm2/method.rs @@ -7,7 +7,7 @@ use crate::avm2::value::{abc_default_value, Value}; use crate::avm2::Error; use crate::avm2::Multiname; use crate::string::AvmString; -use gc_arena::{Collect, CollectionContext, Gc, MutationContext}; +use gc_arena::{Collect, Gc, MutationContext}; use std::fmt; use std::ops::Deref; use std::rc::Rc; @@ -256,9 +256,11 @@ impl<'gc> BytecodeMethod<'gc> { } /// An uninstantiated method -#[derive(Clone)] +#[derive(Clone, Collect)] +#[collect(no_drop)] pub struct NativeMethod<'gc> { /// The function to call to execute the method. + #[collect(require_static)] pub method: NativeMethodImpl, /// The name of the method. @@ -272,12 +274,6 @@ pub struct NativeMethod<'gc> { pub is_variadic: bool, } -unsafe impl<'gc> Collect for NativeMethod<'gc> { - fn trace(&self, cc: CollectionContext) { - self.signature.trace(cc); - } -} - impl<'gc> fmt::Debug for NativeMethod<'gc> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("NativeMethod")