diff --git a/core/src/avm2/class.rs b/core/src/avm2/class.rs index a339b1c0d1333..21dc4b702c650 100644 --- a/core/src/avm2/class.rs +++ b/core/src/avm2/class.rs @@ -1162,15 +1162,23 @@ impl<'gc> Class<'gc> { &'static str, Option, Option, + Multiname<'gc>, )], ) { - for &(name, getter, setter) in items { + for (name, getter, setter, prop_type) in items { if let Some(getter) = getter { self.define_instance_trait( mc, Trait::from_getter( - QName::new(namespace, name), - Method::from_builtin(getter, name, mc), + QName::new(namespace, *name), + Method::from_builtin_and_params( + *getter, + name, + vec![], + prop_type.clone(), + false, + mc, + ), ), ); } @@ -1178,8 +1186,15 @@ impl<'gc> Class<'gc> { self.define_instance_trait( mc, Trait::from_setter( - QName::new(namespace, name), - Method::from_builtin(setter, name, mc), + QName::new(namespace, *name), + Method::from_builtin_and_params( + *setter, + name, + vec![ParamConfig::of_type("val", prop_type.clone())], + QName::new(namespace, "void").into(), + false, + mc, + ), ), ); } diff --git a/core/src/avm2/globals/array.rs b/core/src/avm2/globals/array.rs index d7dfc76a91540..9e248960a6428 100644 --- a/core/src/avm2/globals/array.rs +++ b/core/src/avm2/globals/array.rs @@ -7,8 +7,8 @@ use crate::avm2::error::range_error; use crate::avm2::method::{Method, NativeMethodImpl}; use crate::avm2::object::{array_allocator, ArrayObject, FunctionObject, Object, TObject}; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; use crate::string::AvmString; use bitflags::bitflags; use std::cmp::{min, Ordering}; @@ -1259,15 +1259,16 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> Class<'gc> { Method::from_builtin(class_call, "", mc), ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[("length", Some(length), Some(set_length))]; + let public_instance_properties = &[( + "length", + Some(length as _), + Some(set_length as _), + Multiname::new(activation.avm2().public_namespace_base_version, "uint"), + )]; class.define_builtin_instance_properties( mc, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); class.define_builtin_instance_methods( diff --git a/core/src/avm2/globals/class.rs b/core/src/avm2/globals/class.rs index b9bfcac912c44..b6bbaa510f1eb 100644 --- a/core/src/avm2/globals/class.rs +++ b/core/src/avm2/globals/class.rs @@ -2,11 +2,11 @@ use crate::avm2::activation::Activation; use crate::avm2::class::{Class, ClassAttributes}; -use crate::avm2::method::{Method, NativeMethodImpl}; +use crate::avm2::method::Method; use crate::avm2::object::{Object, TObject}; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; /// Implements `Class`'s instance initializer. /// @@ -54,15 +54,16 @@ pub fn create_i_class<'gc>( gc_context, ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[("prototype", Some(prototype), None)]; + let public_instance_properties = &[( + "prototype", + Some(prototype as _), + None, + Multiname::any(activation.context.gc_context), + )]; class_i_class.define_builtin_instance_properties( gc_context, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); class_i_class.mark_traits_loaded(activation.context.gc_context); diff --git a/core/src/avm2/globals/date.rs b/core/src/avm2/globals/date.rs index d32293a0dbee5..f843c49365b84 100644 --- a/core/src/avm2/globals/date.rs +++ b/core/src/avm2/globals/date.rs @@ -5,8 +5,8 @@ use crate::avm2::class::Class; use crate::avm2::method::{Method, NativeMethodImpl}; use crate::avm2::object::{date_allocator, DateObject, FunctionObject, Object, TObject}; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; use crate::locale::{get_current_date_time, get_timezone}; use crate::string::{utils as string_utils, AvmString, WStr}; use chrono::{DateTime, Datelike, Duration, FixedOffset, LocalResult, TimeZone, Timelike, Utc}; @@ -1338,38 +1338,108 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> Class<'gc> { Method::from_builtin(call_handler, "", mc), ); - const PUBLIC_INSTANCE_PROPERTIES: &[( + let number_multiname = + Multiname::new(activation.avm2().public_namespace_base_version, "Number"); + + let public_instance_properties: &[( &str, Option, Option, + Multiname<'gc>, )] = &[ - ("time", Some(time), Some(set_time)), - ("milliseconds", Some(milliseconds), Some(set_milliseconds)), - ("seconds", Some(seconds), Some(set_seconds)), - ("minutes", Some(minutes), Some(set_minutes)), - ("hours", Some(hours), Some(set_hours)), - ("date", Some(date), Some(set_date)), - ("month", Some(month), Some(set_month)), - ("fullYear", Some(full_year), Some(set_full_year)), + ("time", Some(time), Some(set_time), number_multiname.clone()), + ( + "milliseconds", + Some(milliseconds), + Some(set_milliseconds), + number_multiname.clone(), + ), + ( + "seconds", + Some(seconds), + Some(set_seconds), + number_multiname.clone(), + ), + ( + "minutes", + Some(minutes), + Some(set_minutes), + number_multiname.clone(), + ), + ( + "hours", + Some(hours), + Some(set_hours), + number_multiname.clone(), + ), + ("date", Some(date), Some(set_date), number_multiname.clone()), + ( + "month", + Some(month), + Some(set_month), + number_multiname.clone(), + ), + ( + "fullYear", + Some(full_year), + Some(set_full_year), + number_multiname.clone(), + ), ( "millisecondsUTC", Some(milliseconds_utc), Some(set_milliseconds_utc), + number_multiname.clone(), + ), + ("day", Some(day), None, number_multiname.clone()), + ( + "secondsUTC", + Some(seconds_utc), + Some(set_seconds_utc), + number_multiname.clone(), + ), + ( + "minutesUTC", + Some(minutes_utc), + Some(set_minutes_utc), + number_multiname.clone(), + ), + ( + "hoursUTC", + Some(hours_utc), + Some(set_hours_utc), + number_multiname.clone(), + ), + ( + "dateUTC", + Some(date_utc), + Some(set_date_utc), + number_multiname.clone(), + ), + ( + "monthUTC", + Some(month_utc), + Some(set_month_utc), + number_multiname.clone(), + ), + ( + "fullYearUTC", + Some(full_year_utc), + Some(set_full_year_utc), + number_multiname.clone(), + ), + ("dayUTC", Some(day_utc), None, number_multiname.clone()), + ( + "timezoneOffset", + Some(timezone_offset), + None, + number_multiname.clone(), ), - ("day", Some(day), None), - ("secondsUTC", Some(seconds_utc), Some(set_seconds_utc)), - ("minutesUTC", Some(minutes_utc), Some(set_minutes_utc)), - ("hoursUTC", Some(hours_utc), Some(set_hours_utc)), - ("dateUTC", Some(date_utc), Some(set_date_utc)), - ("monthUTC", Some(month_utc), Some(set_month_utc)), - ("fullYearUTC", Some(full_year_utc), Some(set_full_year_utc)), - ("dayUTC", Some(day_utc), None), - ("timezoneOffset", Some(timezone_offset), None), ]; class.define_builtin_instance_properties( mc, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); class.define_builtin_instance_methods( mc, diff --git a/core/src/avm2/globals/function.rs b/core/src/avm2/globals/function.rs index b75ce24f2462d..c6d03210632bd 100644 --- a/core/src/avm2/globals/function.rs +++ b/core/src/avm2/globals/function.rs @@ -7,8 +7,8 @@ use crate::avm2::globals::array::resolve_array_hole; use crate::avm2::method::{Method, NativeMethodImpl}; use crate::avm2::object::{function_allocator, FunctionObject, Object, TObject}; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; /// Implements `Function`'s instance initializer. pub fn instance_init<'gc>( @@ -252,18 +252,24 @@ pub fn create_class<'gc>( AS3_INSTANCE_METHODS, ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[ - ("prototype", Some(prototype), Some(set_prototype)), - ("length", Some(length), None), + let public_instance_properties = &[ + ( + "prototype", + Some(prototype as _), + Some(set_prototype as _), + Multiname::any(activation.context.gc_context), + ), + ( + "length", + Some(length as _), + None, + Multiname::new(activation.avm2().public_namespace_base_version, "int"), + ), ]; function_i_class.define_builtin_instance_properties( gc_context, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); const CONSTANTS_INT: &[(&str, i32)] = &[("length", 1)]; diff --git a/core/src/avm2/globals/namespace.rs b/core/src/avm2/globals/namespace.rs index dff720bc0f160..59d185908ddaf 100644 --- a/core/src/avm2/globals/namespace.rs +++ b/core/src/avm2/globals/namespace.rs @@ -7,9 +7,9 @@ use crate::avm2::error::make_error_1098; use crate::avm2::method::{Method, NativeMethodImpl}; use crate::avm2::object::{namespace_allocator, FunctionObject, Object, TObject}; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::Namespace; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; use crate::string::AvmString; // All of these methods will be defined as both @@ -194,15 +194,24 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> Class<'gc> { Method::from_builtin(class_call, "", mc), ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[("prefix", Some(prefix), None), ("uri", Some(uri), None)]; + let public_instance_properties = &[ + ( + "prefix", + Some(prefix as _), + None, + Multiname::any(activation.context.gc_context), + ), + ( + "uri", + Some(uri as _), + None, + Multiname::new(activation.avm2().public_namespace_base_version, "String"), + ), + ]; class.define_builtin_instance_properties( mc, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); const CONSTANTS_INT: &[(&str, i32)] = &[("length", 2)]; diff --git a/core/src/avm2/globals/string.rs b/core/src/avm2/globals/string.rs index e975ef23995e5..4c98ef49d3c32 100644 --- a/core/src/avm2/globals/string.rs +++ b/core/src/avm2/globals/string.rs @@ -7,9 +7,9 @@ use crate::avm2::method::{Method, NativeMethodImpl}; use crate::avm2::object::{primitive_allocator, FunctionObject, Object, TObject}; use crate::avm2::regexp::RegExpFlags; use crate::avm2::value::Value; -use crate::avm2::Error; use crate::avm2::QName; use crate::avm2::{ArrayObject, ArrayStorage}; +use crate::avm2::{Error, Multiname}; use crate::string::{AvmString, WString}; // All of these methods will be defined as both @@ -702,15 +702,16 @@ pub fn create_class<'gc>(activation: &mut Activation<'_, 'gc>) -> Class<'gc> { Method::from_builtin(call_handler, "", mc), ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[("length", Some(length), None)]; + let public_instance_properties = &[( + "length", + Some(length as _), + None, + Multiname::new(activation.avm2().public_namespace_base_version, "int"), + )]; class.define_builtin_instance_properties( mc, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); class.define_builtin_instance_methods( mc, diff --git a/core/src/avm2/globals/vector.rs b/core/src/avm2/globals/vector.rs index e6164b3a6c14c..f3dba296a2643 100644 --- a/core/src/avm2/globals/vector.rs +++ b/core/src/avm2/globals/vector.rs @@ -13,8 +13,8 @@ use crate::avm2::object::{ }; use crate::avm2::value::Value; use crate::avm2::vector::VectorStorage; -use crate::avm2::Error; use crate::avm2::QName; +use crate::avm2::{Error, Multiname}; use crate::string::AvmString; use std::cmp::{max, min, Ordering}; @@ -964,18 +964,24 @@ pub fn create_builtin_class<'gc>( Method::from_builtin(class_call, " call handler>", mc), ); - const PUBLIC_INSTANCE_PROPERTIES: &[( - &str, - Option, - Option, - )] = &[ - ("length", Some(length), Some(set_length)), - ("fixed", Some(fixed), Some(set_fixed)), + let public_instance_properties = &[ + ( + "length", + Some(length as _), + Some(set_length as _), + Multiname::new(activation.avm2().public_namespace_base_version, "uint"), + ), + ( + "fixed", + Some(fixed as _), + Some(set_fixed as _), + Multiname::new(activation.avm2().public_namespace_base_version, "Boolean"), + ), ]; class.define_builtin_instance_properties( mc, activation.avm2().public_namespace_base_version, - PUBLIC_INSTANCE_PROPERTIES, + public_instance_properties, ); const AS3_INSTANCE_METHODS: &[(&str, NativeMethodImpl)] = &[