From 9c7eb90d69fc228b631fccee50045365313f1f9f Mon Sep 17 00:00:00 2001 From: sleepycatcoding <131554884+sleepycatcoding@users.noreply.github.com> Date: Thu, 7 Sep 2023 01:28:48 +0300 Subject: [PATCH] avm2: Implement XML.prependChild --- core/src/avm2/globals/XML.as | 6 ++++++ core/src/avm2/globals/xml.rs | 15 +++++++++++++++ .../swfs/from_avmplus/e4x/XML/e13_4_2/test.toml | 1 - .../from_avmplus/e4x/XML/e13_4_4_29/v10/test.toml | 1 - 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/core/src/avm2/globals/XML.as b/core/src/avm2/globals/XML.as index 5afc3ca4a..2092c9b15 100644 --- a/core/src/avm2/globals/XML.as +++ b/core/src/avm2/globals/XML.as @@ -72,6 +72,7 @@ package { AS3 native function attribute(name:*):XMLList; AS3 native function nodeKind():String; AS3 native function appendChild(child:Object):XML; + AS3 native function prependChild(child:Object):XML; AS3 native function descendants(name:Object = "*"):XMLList; AS3 native function text():XMLList; AS3 native function toString():String; @@ -189,6 +190,11 @@ package { 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 { var self:XML = this; return self.AS3::descendants(name); diff --git a/core/src/avm2/globals/xml.rs b/core/src/avm2/globals/xml.rs index 79c5b374b..6792d85eb 100644 --- a/core/src/avm2/globals/xml.rs +++ b/core/src/avm2/globals/xml.rs @@ -386,6 +386,21 @@ pub fn append_child<'gc>( 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, 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>( activation: &mut Activation<'_, 'gc>, this: Object<'gc>, diff --git a/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_2/test.toml b/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_2/test.toml index 29f3cef79..cf6123969 100644 --- a/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_2/test.toml +++ b/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_2/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true diff --git a/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_4_29/v10/test.toml b/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_4_29/v10/test.toml index 29f3cef79..cf6123969 100644 --- a/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_4_29/v10/test.toml +++ b/tests/tests/swfs/from_avmplus/e4x/XML/e13_4_4_29/v10/test.toml @@ -1,2 +1 @@ num_ticks = 1 -known_failure = true