diff --git a/core/src/avm1/globals/xml_node.rs b/core/src/avm1/globals/xml_node.rs index 97ae7f9ea..d25be7dbf 100644 --- a/core/src/avm1/globals/xml_node.rs +++ b/core/src/avm1/globals/xml_node.rs @@ -5,7 +5,6 @@ use crate::avm1::error::Error; use crate::avm1::object::xml_node_object::XmlNodeObject; use crate::avm1::property_decl::{define_properties_on, Declaration}; use crate::avm1::{ArrayObject, Object, TObject, Value}; -use crate::avm_warn; use crate::string::AvmString; use crate::xml; use crate::xml::XmlNode; @@ -76,15 +75,7 @@ fn append_child<'gc>( ) { if !xmlnode.has_child(child_xmlnode) { let position = xmlnode.children_len(); - if let Err(e) = - xmlnode.insert_child(activation.context.gc_context, position, child_xmlnode) - { - avm_warn!( - activation, - "Couldn't insert_child inside of XMLNode.appendChild: {}", - e - ); - } + xmlnode.insert_child(activation.context.gc_context, position, child_xmlnode); } } @@ -105,15 +96,7 @@ fn insert_before<'gc>( ) { if !xmlnode.has_child(child_xmlnode) { if let Some(position) = xmlnode.child_position(insertpoint_xmlnode) { - if let Err(e) = - xmlnode.insert_child(activation.context.gc_context, position, child_xmlnode) - { - avm_warn!( - activation, - "Couldn't insert_child inside of XMLNode.insertBefore: {}", - e - ); - } + xmlnode.insert_child(activation.context.gc_context, position, child_xmlnode); } } } diff --git a/core/src/avm1/object/xml_object.rs b/core/src/avm1/object/xml_object.rs index 87032ef1c..cd98bcd96 100644 --- a/core/src/avm1/object/xml_object.rs +++ b/core/src/avm1/object/xml_object.rs @@ -174,7 +174,7 @@ impl<'gc> XmlObject<'gc> { open_tags .last_mut() .unwrap() - .append_child(activation.context.gc_context, child)?; + .append_child(activation.context.gc_context, child); open_tags.push(child); } Event::Empty(bs) => { @@ -187,7 +187,7 @@ impl<'gc> XmlObject<'gc> { open_tags .last_mut() .unwrap() - .append_child(activation.context.gc_context, child)?; + .append_child(activation.context.gc_context, child); } Event::End(_) => { open_tags.pop(); @@ -204,7 +204,7 @@ impl<'gc> XmlObject<'gc> { open_tags .last_mut() .unwrap() - .append_child(activation.context.gc_context, child)?; + .append_child(activation.context.gc_context, child); } } Event::DocType(bt) => { diff --git a/core/src/xml/error.rs b/core/src/xml/error.rs index 4a7804abd..413cf5f94 100644 --- a/core/src/xml/error.rs +++ b/core/src/xml/error.rs @@ -14,15 +14,6 @@ use thiserror::Error; pub enum Error { #[error("Invalid XML")] InvalidXml(#[from] ParseError), - - #[error("Cannot adopt other document roots")] - CannotAdoptRoot, - - #[error("Cannot adopt children into non-child-bearing node")] - CannotAdoptHere, - - #[error("Cannot insert child into itself")] - CannotInsertIntoSelf, } impl From for Error { diff --git a/core/src/xml/tree.rs b/core/src/xml/tree.rs index 342a0fe3c..e4b638a0d 100644 --- a/core/src/xml/tree.rs +++ b/core/src/xml/tree.rs @@ -336,9 +336,6 @@ impl<'gc> XmlNode<'gc> { /// position in the tree. This may remove it from any existing trees or /// documents. /// - /// This function yields an error if appending to a Node that cannot accept - /// children. In that case, no modification will be made to the node. - /// /// The `position` parameter is the position of the new child in /// this node's children list. This is used to find and link the child's /// siblings to each other. @@ -347,18 +344,21 @@ impl<'gc> XmlNode<'gc> { mc: MutationContext<'gc, '_>, position: usize, mut child: XmlNode<'gc>, - ) -> Result<(), Error> { + ) { let is_cyclic = self .ancestors() .any(|ancestor| GcCell::ptr_eq(ancestor.0, child.0)); if is_cyclic { - return Err(Error::CannotInsertIntoSelf); + return; } match &mut *self.0.write(mc) { XmlNodeData::DocumentRoot { children, .. } | XmlNodeData::Element { children, .. } => { let old_parent = match *child.0.read() { - XmlNodeData::DocumentRoot { .. } => return Err(Error::CannotAdoptRoot), + XmlNodeData::DocumentRoot { .. } => { + log::warn!("Cannot adopt other document roots"); + return; + } XmlNodeData::Element { parent, .. } | XmlNodeData::Text { parent, .. } => { parent } @@ -390,20 +390,16 @@ impl<'gc> XmlNode<'gc> { .and_then(|p| children.get(p).cloned()); child.adopt_siblings(mc, new_prev, new_next); } - _ => return Err(Error::CannotAdoptHere), + XmlNodeData::Text { .. } => { + log::warn!("Text nodes cannot have children"); + } } - - Ok(()) } /// Append a child element into the end of the child list of an Element /// node. - pub fn append_child( - &mut self, - mc: MutationContext<'gc, '_>, - child: XmlNode<'gc>, - ) -> Result<(), Error> { - self.insert_child(mc, self.children_len(), child) + pub fn append_child(&mut self, mc: MutationContext<'gc, '_>, child: XmlNode<'gc>) { + self.insert_child(mc, self.children_len(), child); } /// Remove this node from its parent. @@ -661,9 +657,7 @@ impl<'gc> XmlNode<'gc> { if deep { for (position, child) in self.children().enumerate() { - clone - .insert_child(gc_context, position, child.duplicate(gc_context, deep)) - .expect("If I can see my children then my clone should accept children"); + clone.insert_child(gc_context, position, child.duplicate(gc_context, deep)); } }