core: `EditText::html_text` cannot fail

This commit is contained in:
relrelb 2021-11-06 13:15:25 +02:00 committed by relrelb
parent 848b721165
commit cf05137c1f
3 changed files with 7 additions and 13 deletions

View File

@ -334,11 +334,8 @@ pub fn html_text<'gc>(
this: EditText<'gc>,
activation: &mut Activation<'_, 'gc, '_>,
) -> Result<Value<'gc>, Error<'gc>> {
if let Ok(text) = this.html_text(&mut activation.context) {
return Ok(AvmString::new(activation.context.gc_context, text).into());
}
Ok(Value::Undefined)
let html_text = this.html_text(&mut activation.context);
Ok(AvmString::new(activation.context.gc_context, html_text).into())
}
pub fn set_html_text<'gc>(

View File

@ -320,11 +320,8 @@ pub fn html_text<'gc>(
.and_then(|this| this.as_display_object())
.and_then(|this| this.as_edit_text())
{
return Ok(AvmString::new(
activation.context.gc_context,
this.html_text(&mut activation.context)?,
)
.into());
let html_text = this.html_text(&mut activation.context);
return Ok(AvmString::new(activation.context.gc_context, html_text).into());
}
Ok(Value::Undefined)

View File

@ -415,7 +415,7 @@ impl<'gc> EditText<'gc> {
Ok(())
}
pub fn html_text(self, context: &mut UpdateContext<'_, 'gc, '_>) -> Result<String, Error> {
pub fn html_text(self, context: &mut UpdateContext<'_, 'gc, '_>) -> String {
if self.is_html() {
let html_tree = self.html_tree(context).as_node();
let html_string_result = html_tree.into_string(&mut |_node| true);
@ -427,10 +427,10 @@ impl<'gc> EditText<'gc> {
);
}
Ok(html_string_result.unwrap_or_else(|_| "".to_string()))
html_string_result.unwrap_or_default()
} else {
// Non-HTML text fields always return plain text.
Ok(self.text())
self.text()
}
}