From 72965b3689db59e00613a3d8fc8b8e33379f0da6 Mon Sep 17 00:00:00 2001 From: Tom Schuster Date: Sun, 29 Oct 2023 16:30:14 +0100 Subject: [PATCH] amv2: Implement flash.xml.XMLNode removeNode --- core/src/avm2/globals/flash/xml/XMLNode.as | 27 +++++++- .../swfs/avm2/flash_xml_removeNode/Test.as | 49 ++++++++++++++ .../swfs/avm2/flash_xml_removeNode/output.txt | 60 ++++++++++++++++++ .../swfs/avm2/flash_xml_removeNode/test.swf | Bin 0 -> 1410 bytes .../swfs/avm2/flash_xml_removeNode/test.toml | 1 + 5 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 tests/tests/swfs/avm2/flash_xml_removeNode/Test.as create mode 100644 tests/tests/swfs/avm2/flash_xml_removeNode/output.txt create mode 100644 tests/tests/swfs/avm2/flash_xml_removeNode/test.swf create mode 100644 tests/tests/swfs/avm2/flash_xml_removeNode/test.toml diff --git a/core/src/avm2/globals/flash/xml/XMLNode.as b/core/src/avm2/globals/flash/xml/XMLNode.as index bbf13f474..51a13028d 100644 --- a/core/src/avm2/globals/flash/xml/XMLNode.as +++ b/core/src/avm2/globals/flash/xml/XMLNode.as @@ -60,9 +60,30 @@ package flash.xml return clone; } - public function removeNode() : void - { - stub_method("flash.xml.XMLNode", "removeNode"); + public function removeNode(): void { + if (parentNode) { + if (parentNode.firstChild === this) { + parentNode.firstChild = nextSibling; + } + if (parentNode.lastChild === this) { + parentNode.lastChild = previousSibling; + } + var index = parentNode.childNodes.indexOf(this); + if (index > -1) { + parentNode.childNodes.removeAt(index); + } + } + + if (previousSibling) { + previousSibling.nextSibling = nextSibling; + } + if (nextSibling) { + nextSibling.previousSibling = previousSibling; + } + + parentNode = null; + previousSibling = null; + nextSibling = null; } public function insertBefore(node: XMLNode, before: XMLNode = null): void { diff --git a/tests/tests/swfs/avm2/flash_xml_removeNode/Test.as b/tests/tests/swfs/avm2/flash_xml_removeNode/Test.as new file mode 100644 index 000000000..4af1409f9 --- /dev/null +++ b/tests/tests/swfs/avm2/flash_xml_removeNode/Test.as @@ -0,0 +1,49 @@ +package { + import flash.display.Sprite; + public class Test extends Sprite { } +} + +import flash.xml.XMLDocument; + +trace("///"); +var doc = new XMLDocument('a single child'); +trace("doc: " + doc); +var single = doc.firstChild.firstChild; +trace("single: " + single); +single.removeNode(); +trace("/// After removal"); +trace("doc: " + doc); +trace("single: " + single); +trace("single.parentNode: " + single.parentNode); +trace("single.nextSibling: " + single.nextSibling); +trace("single.previousSibling: " + single.previousSibling); + +function test(index) { + var doc = new XMLDocument('') + trace("///") + trace("doc: " + doc); + var root = doc.firstChild; + var childNodes = root.childNodes; + var child = childNodes[index]; + trace("root.childNodes[" + index + "]: " + child); + child.removeNode(); + trace("/// After removal"); + trace("doc: " + doc); + trace("child: " + child); + trace("child.parentNode: " + child.parentNode); + trace("child.nextSibling: " + child.nextSibling); + trace("child.previousSibling: " + child.previousSibling); + + trace("root.firstChild: " + root.firstChild); + trace("root.lastChild: " + root.lastChild); + + for (var i = 0; i < childNodes.length; i++) { + trace("childNodes[" + i + "]: " + childNodes[i]); + trace("childNodes[" + i + "].previousSibling: " + childNodes[i].previousSibling); + trace("childNodes[" + i + "].nextSibling: " + childNodes[i].nextSibling); + } +} + +test(0); +test(1); +test(2); diff --git a/tests/tests/swfs/avm2/flash_xml_removeNode/output.txt b/tests/tests/swfs/avm2/flash_xml_removeNode/output.txt new file mode 100644 index 000000000..825f7dd74 --- /dev/null +++ b/tests/tests/swfs/avm2/flash_xml_removeNode/output.txt @@ -0,0 +1,60 @@ +/// +doc: a single child +single: a single child +/// After removal +doc: +single: a single child +single.parentNode: null +single.nextSibling: null +single.previousSibling: null +/// +doc: +root.childNodes[0]: +/// After removal +doc: +child: +child.parentNode: null +child.nextSibling: null +child.previousSibling: null +root.firstChild: +root.lastChild: +childNodes[0]: +childNodes[0].previousSibling: null +childNodes[0].nextSibling: +childNodes[1]: +childNodes[1].previousSibling: +childNodes[1].nextSibling: null +/// +doc: +root.childNodes[1]: +/// After removal +doc: +child: +child.parentNode: null +child.nextSibling: null +child.previousSibling: null +root.firstChild: +root.lastChild: +childNodes[0]: +childNodes[0].previousSibling: null +childNodes[0].nextSibling: +childNodes[1]: +childNodes[1].previousSibling: +childNodes[1].nextSibling: null +/// +doc: +root.childNodes[2]: +/// After removal +doc: +child: +child.parentNode: null +child.nextSibling: null +child.previousSibling: null +root.firstChild: +root.lastChild: +childNodes[0]: +childNodes[0].previousSibling: null +childNodes[0].nextSibling: +childNodes[1]: +childNodes[1].previousSibling: +childNodes[1].nextSibling: null diff --git a/tests/tests/swfs/avm2/flash_xml_removeNode/test.swf b/tests/tests/swfs/avm2/flash_xml_removeNode/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..d5dfc5491a382d200cbf2a128bd26ff32958aaa7 GIT binary patch literal 1410 zcmV-|1%3KMS5qeG2mkLt4ZQ19iQy4uMQVvpm10hZViuc5FkZ;nd@N(DaNKUHypUEk_TU zWpzlTKA{~tq_Wf2jV4j{9CEDe4BZ(yVo_4rd(-e%r$gi4y$CuGA zcYc2UWr7Ej2#=6{@!JNB2|_<_&VTbgNWUgNBSDCMnfe;+)WTpI6)343vt5%M^QLDA zzUPGrqiH+l6A$VcVmfEb=@f&ddl zvDzoZLSHus;#F0RLDHI%U>>_PZFW%DW3jY#vp+1l=`~2ffZTTuHq=tFxT!WewiDWJ znjW_>JnnP82Em3IXJ7|q#|nwBFs1HDjI1e>>|KZwqK5;&A;?BnmmG%&HVmPAs3~KY z&`jUkCr7r|2`)IP_NXSq@*5sbQ=*J%J$C77HATLV$5>F-w&&Se;Xk1?B~>e2NW^s$ZAX789<+TsB;tO9&OqveBj{HZOnM0S*iS}W zLbbs-)q_h!%{+3Uin-mnkP|=kD zD(Vo08Othr4W}a>Sv4ga2_sFK>gz@-F*_iRR$o(Q>h(jf9(r|?Shj1^Pg@;wY4dF_ z;O=ko>l-C8^5skS?#K5!E*#Kv<(!;L#?tXjY$>-qyOg`j@fTKcu{{y3_O63vnmOON6i5L%H=y1G zFw=-xQslV+a1LNRg0}$91C%4U1n}Bhi;vK4K-b?|i3qJMq7y?*KSfCHt%5~qh%6hWwPm3UO7|V&o zY4P+Cf*O`U!}A=DpKzx|z&t^<32UNQOIfL6Ep4TXwTzW1)+VjVVr|?SXUj8mjs2QQ z@R%lO8#S{a#UZDt2{Lr12%RzSwzysb)Dxz|MTZ^($>J>@Onfg1rghWlS7#g~)`SUA zM@>kL_@+nb89*g)88l)N@CL>GN@M}wqqyG+wU%8(ds&!~B1o7?>mYF;o&53oqc{w% QoP{O&^VtUBUsGzH%fV8x^Z)<= literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/flash_xml_removeNode/test.toml b/tests/tests/swfs/avm2/flash_xml_removeNode/test.toml new file mode 100644 index 000000000..dbee897f5 --- /dev/null +++ b/tests/tests/swfs/avm2/flash_xml_removeNode/test.toml @@ -0,0 +1 @@ +num_frames = 1