avm2: Implement XML.prependChild

This commit is contained in:
sleepycatcoding 2023-09-07 01:28:48 +03:00 committed by Adrian Wielgosik
parent 53ba75d587
commit 9c7eb90d69
4 changed files with 21 additions and 2 deletions

View File

@ -72,6 +72,7 @@ package {
AS3 native function attribute(name:*):XMLList; AS3 native function attribute(name:*):XMLList;
AS3 native function nodeKind():String; AS3 native function nodeKind():String;
AS3 native function appendChild(child:Object):XML; AS3 native function appendChild(child:Object):XML;
AS3 native function prependChild(child:Object):XML;
AS3 native function descendants(name:Object = "*"):XMLList; AS3 native function descendants(name:Object = "*"):XMLList;
AS3 native function text():XMLList; AS3 native function text():XMLList;
AS3 native function toString():String; AS3 native function toString():String;
@ -189,6 +190,11 @@ package {
return self.AS3::appendChild(child); return self.AS3::appendChild(child);
}; };
prototype.prependChild = function(child:Object):XML {
var self:XML = this;
return self.AS3::prependChild(child);
};
prototype.descendants = function(name:Object):XMLList { prototype.descendants = function(name:Object):XMLList {
var self:XML = this; var self:XML = this;
return self.AS3::descendants(name); return self.AS3::descendants(name);

View File

@ -386,6 +386,21 @@ pub fn append_child<'gc>(
Ok(this.into()) Ok(this.into())
} }
// ECMA-357 13.4.4.29 XML.prototype.prependChild ( value )
pub fn prepend_child<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let xml = this.as_xml_object().unwrap();
let child = args.get_value(0);
// 1. Call the [[Insert]] method of this object with arguments "0" and value
xml.node().insert(0, child, activation)?;
// 2. Return x
Ok(xml.into())
}
pub fn descendants<'gc>( pub fn descendants<'gc>(
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
this: Object<'gc>, this: Object<'gc>,

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true