From 716d492006a3d96903c7218969b812cd92809be1 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Sat, 17 Apr 2021 17:43:31 -0400 Subject: [PATCH] avm2: The stage's name should be `null`, not an empty string; and setting it should except. --- core/src/avm2/globals/flash/display/stage.rs | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/avm2/globals/flash/display/stage.rs b/core/src/avm2/globals/flash/display/stage.rs index 57272dad1..6b8749b5b 100644 --- a/core/src/avm2/globals/flash/display/stage.rs +++ b/core/src/avm2/globals/flash/display/stage.rs @@ -5,6 +5,7 @@ use crate::avm2::class::{Class, ClassAttributes}; use crate::avm2::method::Method; use crate::avm2::names::{Namespace, QName}; use crate::avm2::object::Object; +use crate::avm2::traits::Trait; use crate::avm2::value::Value; use crate::avm2::Error; use gc_arena::{GcCell, MutationContext}; @@ -31,6 +32,24 @@ pub fn class_init<'gc>( Ok(Value::Undefined) } +/// Overrides `name`'s getter. +pub fn name<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Ok(Value::Null) +} + +/// Overrides `name`'s setter. +pub fn set_name<'gc>( + _activation: &mut Activation<'_, 'gc, '_>, + _this: Option>, + _args: &[Value<'gc>], +) -> Result, Error> { + Err("Error: You cannot set the name of the stage.".into()) +} + /// Construct `Stage`'s class. pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc>> { let class = Class::new( @@ -51,5 +70,20 @@ pub fn create_class<'gc>(mc: MutationContext<'gc, '_>) -> GcCell<'gc, Class<'gc> write.set_attributes(ClassAttributes::SEALED); + write.define_instance_trait( + Trait::from_getter( + QName::new(Namespace::public(), "name"), + Method::from_builtin(name), + ) + .with_override(), + ); + write.define_instance_trait( + Trait::from_setter( + QName::new(Namespace::public(), "name"), + Method::from_builtin(set_name), + ) + .with_override(), + ); + class }