xml: Silently fail in `insert_child`
Instead of returning a `Result` which is anyway always handled with a `log::warn!()`, simply `log::warn!()` in place of errors. This removes the last 3 remaining `Error` enum members besides `InvalidXml`.
This commit is contained in:
parent
48d0737cd9
commit
e901999b4c
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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<FromUtf8Error> for Error {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue