From 6ebd2a83baef2bd206e7ceb01c26df3db346165e Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Fri, 3 May 2024 22:44:18 +0200 Subject: [PATCH 1/7] avm2: XML.contains() implemented --- core/src/avm2/globals/XML.as | 6 +++++ core/src/avm2/globals/xml.rs | 12 +++++++++ core/src/avm2/object/xml_object.rs | 40 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/core/src/avm2/globals/XML.as b/core/src/avm2/globals/XML.as index 942fe1bcc328..4a1fd53965d1 100644 --- a/core/src/avm2/globals/XML.as +++ b/core/src/avm2/globals/XML.as @@ -68,6 +68,7 @@ package { AS3 native function child(name:*):XMLList; AS3 native function childIndex():int; AS3 native function children():XMLList; + AS3 native function contains(name:*):Boolean; AS3 native function copy():XML; AS3 native function parent():*; AS3 native function elements(name:* = "*"):XMLList; @@ -171,6 +172,11 @@ package { return self.AS3::children(); }; + prototype.contains = function(name:*):Boolean { + var self:XML = this; + return self.AS3::contains(name); + }; + prototype.copy = function():XML { var self:XML = this; return self.AS3::copy(); diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index 90cfd29a27dd..f5f3a63c51dc 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -336,6 +336,18 @@ pub fn children<'gc>( .into()) } +pub fn contains<'gc>( + activation: &mut Activation<'_, 'gc>, + this: Object<'gc>, + args: &[Value<'gc>], +) -> Result, Error<'gc>> { + let xml = this.as_xml_object().unwrap(); + let value = args.get_value(0); + + let contains = xml.contains(&value, activation); + Ok(contains.into()) +} + pub fn copy<'gc>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, diff --git a/core/src/avm2/object/xml_object.rs b/core/src/avm2/object/xml_object.rs index 470c23af0b1f..b04c0470b109 100644 --- a/core/src/avm2/object/xml_object.rs +++ b/core/src/avm2/object/xml_object.rs @@ -177,6 +177,46 @@ impl<'gc> XmlObject<'gc> { Ref::map(self.0.read(), |data| &data.node) } + pub fn contains(&self, value: &Value<'gc>, activation: &mut Activation<'_, 'gc>) -> bool { + let node = self.node(); + + if let Some(xml) = value.as_object().and_then(|obj| obj.as_xml_object()) { + let other = xml.node(); + + if node.is_text() || node.is_attribute() { + return node.xml_to_string(activation) == other.xml_to_string(activation); + } + + if other.is_text() || other.is_attribute() { + return false; + } + + return node.equals(&other); + } + + if let Some(list) = value.as_object().and_then(|obj| obj.as_xml_list_object()) { + if list.length() == 1 { + let xml = list + .xml_object_child(0, activation) + .expect("List length was just verified"); + + if node.is_text() || node.is_attribute() { + return node.xml_to_string(activation) == xml.node().xml_to_string(activation); + } + + if xml.node().is_text() || xml.node().is_attribute() { + return false; + } + + return node.equals(&xml.node()); + } + + return false; + } + + false + } + pub fn deep_copy(&self, activation: &mut Activation<'_, 'gc>) -> XmlObject<'gc> { let node = self.node(); XmlObject::new(node.deep_copy(activation.gc()), activation) From e0bf4a8e6d558796e711d1cd04ec06c0aedaf716 Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Fri, 3 May 2024 23:11:05 +0200 Subject: [PATCH 2/7] tests: XMLList known_failure removed --- tests/tests/swfs/from_avmplus/e4x/XMLList/e13_5_1/test.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tests/swfs/from_avmplus/e4x/XMLList/e13_5_1/test.toml b/tests/tests/swfs/from_avmplus/e4x/XMLList/e13_5_1/test.toml index 29f3cef79022..cf6123969a1d 100644 --- a/tests/tests/swfs/from_avmplus/e4x/XMLList/e13_5_1/test.toml +++ b/tests/tests/swfs/from_avmplus/e4x/XMLList/e13_5_1/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true From fb9652186d8e05a88d2be84e3d17e3808240638b Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Sat, 4 May 2024 11:01:54 +0200 Subject: [PATCH 3/7] avm2: XML manual checks removed --- core/src/avm2/object/xml_object.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/src/avm2/object/xml_object.rs b/core/src/avm2/object/xml_object.rs index b04c0470b109..88e4a83f6fc2 100644 --- a/core/src/avm2/object/xml_object.rs +++ b/core/src/avm2/object/xml_object.rs @@ -183,14 +183,6 @@ impl<'gc> XmlObject<'gc> { if let Some(xml) = value.as_object().and_then(|obj| obj.as_xml_object()) { let other = xml.node(); - if node.is_text() || node.is_attribute() { - return node.xml_to_string(activation) == other.xml_to_string(activation); - } - - if other.is_text() || other.is_attribute() { - return false; - } - return node.equals(&other); } From ef6c9f6be1e270edd097e6a531b225bbadad34ec Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Sat, 4 May 2024 18:24:21 +0200 Subject: [PATCH 4/7] avm2: XMLList.contains() behavior fixed --- core/src/avm2/globals/xml.rs | 4 ++-- core/src/avm2/object/xml_object.rs | 22 +--------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index f5f3a63c51dc..656b8e1e793f 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -337,14 +337,14 @@ pub fn children<'gc>( } pub fn contains<'gc>( - activation: &mut Activation<'_, 'gc>, + _activation: &mut Activation<'_, 'gc>, this: Object<'gc>, args: &[Value<'gc>], ) -> Result, Error<'gc>> { let xml = this.as_xml_object().unwrap(); let value = args.get_value(0); - let contains = xml.contains(&value, activation); + let contains = xml.contains(&value); Ok(contains.into()) } diff --git a/core/src/avm2/object/xml_object.rs b/core/src/avm2/object/xml_object.rs index 88e4a83f6fc2..868c9a6412d2 100644 --- a/core/src/avm2/object/xml_object.rs +++ b/core/src/avm2/object/xml_object.rs @@ -177,7 +177,7 @@ impl<'gc> XmlObject<'gc> { Ref::map(self.0.read(), |data| &data.node) } - pub fn contains(&self, value: &Value<'gc>, activation: &mut Activation<'_, 'gc>) -> bool { + pub fn contains(&self, value: &Value<'gc>) -> bool { let node = self.node(); if let Some(xml) = value.as_object().and_then(|obj| obj.as_xml_object()) { @@ -186,26 +186,6 @@ impl<'gc> XmlObject<'gc> { return node.equals(&other); } - if let Some(list) = value.as_object().and_then(|obj| obj.as_xml_list_object()) { - if list.length() == 1 { - let xml = list - .xml_object_child(0, activation) - .expect("List length was just verified"); - - if node.is_text() || node.is_attribute() { - return node.xml_to_string(activation) == xml.node().xml_to_string(activation); - } - - if xml.node().is_text() || xml.node().is_attribute() { - return false; - } - - return node.equals(&xml.node()); - } - - return false; - } - false } From 22f2472b1dc70536930f9344c92f32e7559f45e9 Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Sat, 4 May 2024 22:41:07 +0200 Subject: [PATCH 5/7] avm2: XML contains method moved to xml.rs --- core/src/avm2/globals/xml.rs | 8 ++++++-- core/src/avm2/object/xml_object.rs | 12 ------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index 656b8e1e793f..3ffac3607908 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -344,8 +344,12 @@ pub fn contains<'gc>( let xml = this.as_xml_object().unwrap(); let value = args.get_value(0); - let contains = xml.contains(&value); - Ok(contains.into()) + if let Some(other) = value.as_object().and_then(|obj| obj.as_xml_object()) { + let result = xml.node().equals(&other.node()); + return Ok(result.into()); + } + + Ok(false.into()) } pub fn copy<'gc>( diff --git a/core/src/avm2/object/xml_object.rs b/core/src/avm2/object/xml_object.rs index 868c9a6412d2..470c23af0b1f 100644 --- a/core/src/avm2/object/xml_object.rs +++ b/core/src/avm2/object/xml_object.rs @@ -177,18 +177,6 @@ impl<'gc> XmlObject<'gc> { Ref::map(self.0.read(), |data| &data.node) } - pub fn contains(&self, value: &Value<'gc>) -> bool { - let node = self.node(); - - if let Some(xml) = value.as_object().and_then(|obj| obj.as_xml_object()) { - let other = xml.node(); - - return node.equals(&other); - } - - false - } - pub fn deep_copy(&self, activation: &mut Activation<'_, 'gc>) -> XmlObject<'gc> { let node = self.node(); XmlObject::new(node.deep_copy(activation.gc()), activation) From 36ab8b513019dbf4507489ecf1634e2ed24ecaa0 Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Sat, 4 May 2024 22:46:03 +0200 Subject: [PATCH 6/7] avm2: Empty line removed in xml.rs --- core/src/avm2/globals/xml.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index 3ffac3607908..c6c2b286c4c6 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -348,7 +348,6 @@ pub fn contains<'gc>( let result = xml.node().equals(&other.node()); return Ok(result.into()); } - Ok(false.into()) } From 219354a292060452dedbaf8237c58ed428f8602b Mon Sep 17 00:00:00 2001 From: Polo <50364607+cy-polo@users.noreply.github.com> Date: Sun, 5 May 2024 09:41:14 +0200 Subject: [PATCH 7/7] avm2: XML contains args name renamed to value --- core/src/avm2/globals/XML.as | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/avm2/globals/XML.as b/core/src/avm2/globals/XML.as index 4a1fd53965d1..53b2a233c8b0 100644 --- a/core/src/avm2/globals/XML.as +++ b/core/src/avm2/globals/XML.as @@ -68,7 +68,7 @@ package { AS3 native function child(name:*):XMLList; AS3 native function childIndex():int; AS3 native function children():XMLList; - AS3 native function contains(name:*):Boolean; + AS3 native function contains(value:*):Boolean; AS3 native function copy():XML; AS3 native function parent():*; AS3 native function elements(name:* = "*"):XMLList; @@ -172,9 +172,9 @@ package { return self.AS3::children(); }; - prototype.contains = function(name:*):Boolean { + prototype.contains = function(value:*):Boolean { var self:XML = this; - return self.AS3::contains(name); + return self.AS3::contains(value); }; prototype.copy = function():XML {