avm2: Add custom implementations for get_enumerant_name and property_is_enumerable for VectorObject

This commit is contained in:
EmperorBale 2021-10-09 23:57:56 -07:00 committed by Mike Welsh
parent 9bca63375f
commit 34ecb32b85
1 changed files with 15 additions and 0 deletions

View File

@ -223,6 +223,21 @@ impl<'gc> TObject<'gc> for VectorObject<'gc> {
self.0.read().base.resolve_any(local_name) self.0.read().base.resolve_any(local_name)
} }
fn get_enumerant_name(&self, index: u32) -> Option<Value<'gc>> {
if self.0.read().vector.length() as u32 >= index {
index.checked_sub(1).map(|index| index.into())
} else {
None
}
}
fn property_is_enumerable(&self, name: &QName<'gc>) -> bool {
name.local_name()
.parse::<u32>()
.map(|index| self.0.read().vector.length() as u32 >= index)
.unwrap_or(false)
}
fn to_string(&self, _mc: MutationContext<'gc, '_>) -> Result<Value<'gc>, Error> { fn to_string(&self, _mc: MutationContext<'gc, '_>) -> Result<Value<'gc>, Error> {
Ok(Value::Object(Object::from(*self))) Ok(Value::Object(Object::from(*self)))
} }