diff --git a/core/src/avm2/globals/flash/display/displayobject.rs b/core/src/avm2/globals/flash/display/displayobject.rs index a01ee2406..1630b0e8f 100644 --- a/core/src/avm2/globals/flash/display/displayobject.rs +++ b/core/src/avm2/globals/flash/display/displayobject.rs @@ -16,6 +16,15 @@ use swf::Twips; /// Implements `flash.display.DisplayObject`'s instance constructor. pub fn instance_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Err("You cannot construct DisplayObject directly.".into()) +} + +/// Implements `flash.display.DisplayObject`'s native instance constructor. +pub fn native_instance_init<'gc>( activation: &mut Activation<'_, 'gc, '_>, this: Option>, _args: &[Value<'gc>], @@ -603,6 +612,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> let mut write = class.write(mc); write.set_instance_deriver(stage_deriver); + write.set_native_instance_init(Method::from_builtin(native_instance_init)); const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option, Option)] = &[ ("alpha", Some(alpha), Some(set_alpha)), diff --git a/core/src/avm2/globals/flash/display/displayobjectcontainer.rs b/core/src/avm2/globals/flash/display/displayobjectcontainer.rs index 871a60c4e..219d9e319 100644 --- a/core/src/avm2/globals/flash/display/displayobjectcontainer.rs +++ b/core/src/avm2/globals/flash/display/displayobjectcontainer.rs @@ -14,6 +14,15 @@ use std::cmp::min; /// Implements `flash.display.DisplayObjectContainer`'s instance constructor. pub fn instance_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Err("You cannot construct DisplayObjectContainer directly.".into()) +} + +/// Implements `flash.display.DisplayObjectContainer`'s native instance constructor. +pub fn native_instance_init<'gc>( activation: &mut Activation<'_, 'gc, '_>, this: Option>, _args: &[Value<'gc>], @@ -585,6 +594,8 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> let mut write = class.write(mc); + write.set_native_instance_init(Method::from_builtin(native_instance_init)); + const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option, Option)] = &[("numChildren", Some(num_children), None)]; write.define_public_builtin_instance_properties(PUBLIC_INSTANCE_PROPERTIES); diff --git a/core/src/avm2/globals/flash/display/graphics.rs b/core/src/avm2/globals/flash/display/graphics.rs index 1b02605c2..3ae45140a 100644 --- a/core/src/avm2/globals/flash/display/graphics.rs +++ b/core/src/avm2/globals/flash/display/graphics.rs @@ -21,6 +21,19 @@ pub fn instance_init<'gc>( Err("Graphics cannot be constructed directly.".into()) } +/// Implements `flash.display.Graphics`'s native instance constructor. +pub fn native_instance_init<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(this) = this { + activation.super_init(this, &[])?; + } + + Ok(Value::Undefined) +} + /// Implements `flash.display.Graphics`'s class constructor. pub fn class_init<'gc>( _activation: &mut Activation<'_, 'gc, '_>, @@ -365,6 +378,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> write.set_attributes(ClassAttributes::SEALED); write.set_instance_deriver(stage_deriver); + write.set_native_instance_init(Method::from_builtin(native_instance_init)); const PUBLIC_INSTANCE_METHODS: &[(&str, NativeMethod)] = &[ ("beginFill", begin_fill), diff --git a/core/src/avm2/globals/flash/display/interactiveobject.rs b/core/src/avm2/globals/flash/display/interactiveobject.rs index c7af85298..335158a7a 100644 --- a/core/src/avm2/globals/flash/display/interactiveobject.rs +++ b/core/src/avm2/globals/flash/display/interactiveobject.rs @@ -11,6 +11,15 @@ use gc_arena::{GcCell, MutationContext}; /// Implements `flash.display.InteractiveObject`'s instance constructor. pub fn instance_init<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Err("You cannot directly construct InteractiveObject.".into()) +} + +/// Implements `flash.display.InteractiveObject`'s native instance constructor. +pub fn native_instance_init<'gc>( activation: &mut Activation<'_, 'gc, '_>, this: Option>, _args: &[Value<'gc>], @@ -33,11 +42,17 @@ pub fn class_init<'gc>( /// Construct `InteractiveObject`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { - Class::new( + let class = Class::new( QName::new(Namespace::package("flash.display"), "InteractiveObject"), Some(QName::new(Namespace::package("flash.display"), "DisplayObject").into()), Method::from_builtin(instance_init), Method::from_builtin(class_init), mc, - ) + ); + + let mut write = class.write(mc); + + write.set_native_instance_init(Method::from_builtin(native_instance_init)); + + class } diff --git a/core/src/avm2/globals/flash/display/loaderinfo.rs b/core/src/avm2/globals/flash/display/loaderinfo.rs index 57494b56a..ce04e606f 100644 --- a/core/src/avm2/globals/flash/display/loaderinfo.rs +++ b/core/src/avm2/globals/flash/display/loaderinfo.rs @@ -23,6 +23,19 @@ pub fn instance_init<'gc>( Err("LoaderInfo cannot be constructed".into()) } +/// Implements `flash.display.LoaderInfo`'s native instance constructor. +pub fn native_instance_init<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + if let Some(this) = this { + activation.super_init(this, &[])?; + } + + Ok(Value::Undefined) +} + /// Implements `flash.display.LoaderInfo`'s class constructor. pub fn class_init<'gc>( _activation: &mut Activation<'_, 'gc, '_>, @@ -419,6 +432,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> write.set_attributes(ClassAttributes::SEALED); write.set_instance_deriver(loaderinfo_deriver); + write.set_native_instance_init(Method::from_builtin(native_instance_init)); const PUBLIC_INSTANCE_PROPERTIES: &[(&str, Option, Option)] = &[ ("actionScriptVersion", Some(action_script_version), None), diff --git a/core/src/avm2/globals/flash/display/stage.rs b/core/src/avm2/globals/flash/display/stage.rs index e9131039e..70cb02ba4 100644 --- a/core/src/avm2/globals/flash/display/stage.rs +++ b/core/src/avm2/globals/flash/display/stage.rs @@ -15,12 +15,21 @@ use swf::Color; /// Implements `flash.display.Stage`'s instance constructor. pub fn instance_init<'gc>( - activation: &mut Activation<'_, 'gc, '_>, - this: Option>, + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, _args: &[Value<'gc>], +) -> Result, Error> { + Err("You cannot construct new instances of the Stage.".into()) +} + +/// Implements `flash.display.Stage`'s native instance constructor. +pub fn native_instance_init<'gc>( + activation: &mut Activation<'_, 'gc, '_>, + this: Option>, + args: &[Value<'gc>], ) -> Result, Error> { if let Some(this) = this { - activation.super_init(this, &[])?; + activation.super_init(this, args)?; } Ok(Value::Undefined) @@ -630,6 +639,7 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> let mut write = class.write(mc); write.set_attributes(ClassAttributes::SEALED); + write.set_native_instance_init(Method::from_builtin(native_instance_init)); const PUBLIC_OVERRIDE_INSTANCE_PROPERTIES: &[( &str, diff --git a/core/src/avm2/globals/flash/system/system.rs b/core/src/avm2/globals/flash/system/system.rs index b9e0c877c..6dd91c5c9 100644 --- a/core/src/avm2/globals/flash/system/system.rs +++ b/core/src/avm2/globals/flash/system/system.rs @@ -11,15 +11,11 @@ use gc_arena::{GcCell, MutationContext}; /// Implements `flash.system.System`'s instance constructor. pub fn instance_init<'gc>( - activation: &mut Activation<'_, 'gc, '_>, - this: Option>, + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, _args: &[Value<'gc>], ) -> Result, Error> { - if let Some(this) = this { - activation.super_init(this, &[])?; - } - - Ok(Value::Undefined) + Err("The System class cannot be constructed.".into()) } /// Implements `flash.system.System`'s class constructor. diff --git a/core/src/display_object/stage.rs b/core/src/display_object/stage.rs index 996dc29c1..c73b7d975 100644 --- a/core/src/display_object/stage.rs +++ b/core/src/display_object/stage.rs @@ -531,7 +531,7 @@ impl<'gc> TDisplayObject<'gc> for Stage<'gc> { // TODO: We should only do this if the movie is actually an AVM2 movie. // This is necessary for EventDispatcher super-constructor to run. let mut activation = Avm2Activation::from_nothing(context.reborrow()); - if let Err(e) = stage_constr.call( + if let Err(e) = stage_constr.call_native_initializer( Some(avm2_stage.into()), &[], &mut activation,