Skip to content

Commit

Permalink
avm2: Implement XML.contains (#16206)
Browse files Browse the repository at this point in the history
* avm2: XML.contains() implemented

* tests: XMLList known_failure removed

* avm2: XML manual checks removed

* avm2: XMLList.contains() behavior fixed

* avm2: XML contains method moved to xml.rs

* avm2: Empty line removed in xml.rs

* avm2: XML contains args name renamed to value
  • Loading branch information
cy-polo authored May 6, 2024
1 parent 37cc66f commit 0910df8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions core/src/avm2/globals/XML.as
Original file line number Diff line number Diff line change
Expand Up @@ -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(value:*):Boolean;
AS3 native function copy():XML;
AS3 native function parent():*;
AS3 native function elements(name:* = "*"):XMLList;
Expand Down Expand Up @@ -171,6 +172,11 @@ package {
return self.AS3::children();
};

prototype.contains = function(value:*):Boolean {
var self:XML = this;
return self.AS3::contains(value);
};

prototype.copy = function():XML {
var self:XML = this;
return self.AS3::copy();
Expand Down
15 changes: 15 additions & 0 deletions core/src/avm2/globals/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,21 @@ pub fn children<'gc>(
.into())
}

pub fn contains<'gc>(
_activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let xml = this.as_xml_object().unwrap();
let value = args.get_value(0);

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>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
num_ticks = 1
known_failure = true

0 comments on commit 0910df8

Please sign in to comment.