From 1705870951b55701488770c02ca5092631d67246 Mon Sep 17 00:00:00 2001 From: Lord-McSweeney Date: Wed, 12 Jun 2024 22:22:53 -0700 Subject: [PATCH] avm2: Class initializers will be called twice when constructing two `ClassObject`s for one `Class` --- core/src/avm2/class.rs | 16 ---------------- core/src/avm2/object/class_object.rs | 22 +++++++++------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/core/src/avm2/class.rs b/core/src/avm2/class.rs index c9580e584..d3fc297cf 100644 --- a/core/src/avm2/class.rs +++ b/core/src/avm2/class.rs @@ -151,9 +151,6 @@ pub struct ClassData<'gc> { /// Must be called once and only once prior to any use of this class. class_init: Method<'gc>, - /// Whether or not the class initializer has already been called. - class_initializer_called: bool, - /// The customization point for `Class(args...)` without `new` /// If None, a simple coercion is done. call_handler: Option>, @@ -238,7 +235,6 @@ impl<'gc> Class<'gc> { instance_traits: Vec::new(), instance_vtable: VTable::empty(mc), class_init, - class_initializer_called: false, call_handler: None, class_traits: Vec::new(), traits_loaded: true, @@ -463,7 +459,6 @@ impl<'gc> Class<'gc> { instance_traits: Vec::new(), instance_vtable: VTable::empty(activation.context.gc_context), class_init, - class_initializer_called: false, call_handler: native_call_handler, class_traits: Vec::new(), traits_loaded: false, @@ -718,7 +713,6 @@ impl<'gc> Class<'gc> { "", activation.context.gc_context, ), - class_initializer_called: false, call_handler: None, class_traits: Vec::new(), traits_loaded: true, @@ -1111,16 +1105,6 @@ impl<'gc> Class<'gc> { self.0.read().call_handler } - /// Check if the class has already been initialized. - pub fn is_class_initialized(self) -> bool { - self.0.read().class_initializer_called - } - - /// Mark the class as initialized. - pub fn mark_class_initialized(self, mc: &Mutation<'gc>) { - self.0.write(mc).class_initializer_called = true; - } - pub fn direct_interfaces(&self) -> Ref>> { Ref::map(self.0.read(), |c| &c.direct_interfaces) } diff --git a/core/src/avm2/object/class_object.rs b/core/src/avm2/object/class_object.rs index 7d423e770..78f24d85a 100644 --- a/core/src/avm2/object/class_object.rs +++ b/core/src/avm2/object/class_object.rs @@ -351,20 +351,16 @@ impl<'gc> ClassObject<'gc> { let scope = self.0.read().class_scope; let class = self.0.read().class; - if !class.is_class_initialized() { - let class_initializer = class.class_init(); - let class_init_fn = FunctionObject::from_method( - activation, - class_initializer, - scope, - Some(object), - Some(self), - ); + let class_initializer = class.class_init(); + let class_init_fn = FunctionObject::from_method( + activation, + class_initializer, + scope, + Some(object), + Some(self), + ); - class.mark_class_initialized(activation.context.gc_context); - - class_init_fn.call(object.into(), &[], activation)?; - } + class_init_fn.call(object.into(), &[], activation)?; Ok(()) }