appendChild also refuses to orphan nodes already part of another XML tree.

This commit is contained in:
David Wendt 2019-12-28 13:41:38 -07:00
parent bff851e6a4
commit c76e5ce447
5 changed files with 25 additions and 2 deletions

View File

@ -53,8 +53,10 @@ pub fn xmlnode_append_child<'gc>(
this.as_xml_node(),
args.get(0).map(|n| n.as_object().map(|n| n.as_xml_node())),
) {
let position = xmlnode.children_len();
xmlnode.insert_child(ac.gc_context, position, child_xmlnode)?;
if let Ok(None) = child_xmlnode.parent() {
let position = xmlnode.children_len();
xmlnode.insert_child(ac.gc_context, position, child_xmlnode)?;
}
}
Ok(Value::Undefined.into())

View File

@ -114,6 +114,7 @@ swf_tests! {
(xml_siblings, "avm1/xml_siblings", 1),
(xml_attributes_read, "avm1/xml_attributes_read", 1),
(xml_append_child, "avm1/xml_append_child", 1),
(xml_append_child_with_parent, "avm1/xml_append_child_with_parent", 1),
(xml_remove_node, "avm1/xml_remove_node", 1),
(xml_insert_before, "avm1/xml_insert_before", 1),
}

View File

@ -0,0 +1,20 @@
true
null
true
true
null
true
Swapping nodes...
true
null
true
true
null
true
Failing to swap nodes...
true
null
true
true
null
true