avm2: Implement XMLList.child
This commit is contained in:
parent
35f3a21110
commit
aca4329dbf
|
@ -10,6 +10,7 @@ package {
|
|||
|
||||
AS3 native function hasSimpleContent():Boolean;
|
||||
AS3 native function length():int;
|
||||
AS3 native function child(name:Object):XMLList;
|
||||
AS3 native function children():XMLList;
|
||||
AS3 native function copy():XMLList;
|
||||
AS3 native function attribute(name:*):XMLList;
|
||||
|
@ -37,6 +38,11 @@ package {
|
|||
return self.AS3::length();
|
||||
}
|
||||
|
||||
prototype.child = function(name:Object):XMLList {
|
||||
var self:XML = this;
|
||||
return self.AS3::child(name);
|
||||
};
|
||||
|
||||
prototype.children = function():XMLList {
|
||||
var self:XMLList = this;
|
||||
return self.AS3::children();
|
||||
|
|
|
@ -99,6 +99,28 @@ pub fn length<'gc>(
|
|||
Ok(children.len().into())
|
||||
}
|
||||
|
||||
pub fn child<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Option<Object<'gc>>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let list = this.unwrap().as_xml_list_object().unwrap();
|
||||
let multiname = name_to_multiname(activation, &args[0])?;
|
||||
let children = list.children();
|
||||
let mut sub_children = Vec::new();
|
||||
for child in &*children {
|
||||
if let E4XNodeKind::Element { ref children, .. } = &*child.node().kind() {
|
||||
sub_children.extend(
|
||||
children
|
||||
.iter()
|
||||
.filter(|node| node.matches_name(&multiname))
|
||||
.map(|node| E4XOrXml::E4X(*node)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(XmlListObject::new(activation, sub_children, Some(list.into())).into())
|
||||
}
|
||||
|
||||
pub fn children<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Option<Object<'gc>>,
|
||||
|
|
Loading…
Reference in New Issue