avm2: Add deep_copy method to XmlListObject

Also changes existing AS3 copy method to use that instead.
Moved as other code needs to do the same operation.
This commit is contained in:
sleepycatcoding 2023-08-27 00:56:53 +03:00 committed by Nathan Adams
parent fbaa02e295
commit b3af4320e7
2 changed files with 10 additions and 6 deletions

View File

@ -201,12 +201,7 @@ pub fn copy<'gc>(
_args: &[Value<'gc>], _args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
let list = this.as_xml_list_object().unwrap(); let list = this.as_xml_list_object().unwrap();
let children = list Ok(list.deep_copy(activation).into())
.children()
.iter()
.map(|child| E4XOrXml::E4X(child.node().deep_copy(activation.context.gc_context)))
.collect();
Ok(XmlListObject::new(activation, children, list.target()).into())
} }
pub fn attribute<'gc>( pub fn attribute<'gc>(

View File

@ -97,6 +97,15 @@ impl<'gc> XmlListObject<'gc> {
self.0.read().target self.0.read().target
} }
pub fn deep_copy(&self, activation: &mut Activation<'_, 'gc>) -> XmlListObject<'gc> {
let children = self
.children()
.iter()
.map(|child| E4XOrXml::E4X(child.node().deep_copy(activation.context.gc_context)))
.collect();
XmlListObject::new(activation, children, self.target())
}
pub fn equals( pub fn equals(
&self, &self,
other: &Value<'gc>, other: &Value<'gc>,