core: simple_content_to_string and xml_to_string are now infallible
This commit is contained in:
parent
db7c6dec00
commit
3117469e20
|
@ -632,13 +632,10 @@ impl<'gc> E4XNode<'gc> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn xml_to_string(
|
||||
&self,
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
) -> Result<AvmString<'gc>, Error<'gc>> {
|
||||
pub fn xml_to_string(&self, activation: &mut Activation<'_, 'gc>) -> AvmString<'gc> {
|
||||
match &self.0.read().kind {
|
||||
E4XNodeKind::Text(text) | E4XNodeKind::CData(text) => Ok(*text),
|
||||
E4XNodeKind::Attribute(text) => Ok(*text),
|
||||
E4XNodeKind::Text(text) | E4XNodeKind::CData(text) => *text,
|
||||
E4XNodeKind::Attribute(text) => *text,
|
||||
E4XNodeKind::Element { children, .. } => {
|
||||
if self.has_simple_content() {
|
||||
return simple_content_to_string(
|
||||
|
@ -647,10 +644,10 @@ impl<'gc> E4XNode<'gc> {
|
|||
);
|
||||
}
|
||||
|
||||
return Ok(to_xml_string(E4XOrXml::E4X(*self), activation));
|
||||
return to_xml_string(E4XOrXml::E4X(*self), activation);
|
||||
}
|
||||
E4XNodeKind::Comment(_) | E4XNodeKind::ProcessingInstruction(_) => {
|
||||
return Ok(to_xml_string(E4XOrXml::E4X(*self), activation));
|
||||
return to_xml_string(E4XOrXml::E4X(*self), activation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -675,7 +672,7 @@ impl<'gc> E4XNode<'gc> {
|
|||
pub fn simple_content_to_string<'gc>(
|
||||
children: impl Iterator<Item = E4XOrXml<'gc>>,
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
) -> Result<AvmString<'gc>, Error<'gc>> {
|
||||
) -> AvmString<'gc> {
|
||||
let mut out = AvmString::default();
|
||||
for child in children {
|
||||
if matches!(
|
||||
|
@ -684,10 +681,10 @@ pub fn simple_content_to_string<'gc>(
|
|||
) {
|
||||
continue;
|
||||
}
|
||||
let child_str = child.node().xml_to_string(activation)?;
|
||||
let child_str = child.node().xml_to_string(activation);
|
||||
out = AvmString::concat(activation.context.gc_context, out, child_str);
|
||||
}
|
||||
Ok(out)
|
||||
out
|
||||
}
|
||||
|
||||
// Implementation of `EscapeAttributeValue` from ECMA-357 (10.2.1.2)
|
||||
|
|
|
@ -108,7 +108,7 @@ pub fn to_string<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let xml = this.as_xml_object().unwrap();
|
||||
let node = xml.node();
|
||||
Ok(Value::String(node.xml_to_string(activation)?))
|
||||
Ok(Value::String(node.xml_to_string(activation)))
|
||||
}
|
||||
|
||||
pub fn to_xml_string<'gc>(
|
||||
|
|
|
@ -124,7 +124,7 @@ pub fn to_string<'gc>(
|
|||
let list = this.as_xml_list_object().unwrap();
|
||||
let children = list.children();
|
||||
if has_simple_content_inner(&children) {
|
||||
Ok(simple_content_to_string(children.iter().cloned(), activation)?.into())
|
||||
Ok(simple_content_to_string(children.iter().cloned(), activation).into())
|
||||
} else {
|
||||
to_xml_string(activation, this, args)
|
||||
}
|
||||
|
|
|
@ -122,8 +122,8 @@ impl<'gc> XmlObject<'gc> {
|
|||
E4XNodeKind::Text(_) | E4XNodeKind::CData(_) | E4XNodeKind::Attribute(_)
|
||||
) && self.node().has_simple_content())
|
||||
{
|
||||
return Ok(self.node().xml_to_string(activation)?
|
||||
== xml_obj.node().xml_to_string(activation)?);
|
||||
return Ok(self.node().xml_to_string(activation)
|
||||
== xml_obj.node().xml_to_string(activation));
|
||||
}
|
||||
|
||||
return self.equals(other, activation);
|
||||
|
@ -132,9 +132,7 @@ impl<'gc> XmlObject<'gc> {
|
|||
|
||||
// 4. If (Type(x) is XML) and x.hasSimpleContent() == true)
|
||||
if self.node().has_simple_content() {
|
||||
return Ok(
|
||||
self.node().xml_to_string(activation)? == other.coerce_to_string(activation)?
|
||||
);
|
||||
return Ok(self.node().xml_to_string(activation) == other.coerce_to_string(activation)?);
|
||||
}
|
||||
|
||||
// It seems like everything else will just ultimately fall-through to the last step.
|
||||
|
@ -254,7 +252,7 @@ impl<'gc> TObject<'gc> for XmlObject<'gc> {
|
|||
if let Some(list) = prop.as_object().and_then(|obj| obj.as_xml_list_object()) {
|
||||
if list.length() == 0 && this.node().has_simple_content() {
|
||||
let receiver = PrimitiveObject::from_primitive(
|
||||
this.node().xml_to_string(activation)?.into(),
|
||||
this.node().xml_to_string(activation).into(),
|
||||
activation,
|
||||
)?;
|
||||
return receiver.call_property(multiname, arguments, activation);
|
||||
|
|
Loading…
Reference in New Issue