web: Destroy shouldn't be able to throw exceptions

This commit is contained in:
Nathan Adams 2020-09-12 21:10:46 +02:00 committed by Mike Welsh
parent 58cd1abcf2
commit 69d1e903fb
2 changed files with 4 additions and 16 deletions

View File

@ -126,11 +126,7 @@ exports.RufflePlayer = class RufflePlayer extends HTMLElement {
*/
async ensure_fresh_instance() {
if (this.instance) {
try {
this.instance.destroy();
} catch (e) {
console.warn("Error destroying old ruffle player:", e);
}
this.instance.destroy();
this.instance = null;
console.log("Ruffle instance destroyed.");
}
@ -313,14 +309,7 @@ exports.RufflePlayer = class RufflePlayer extends HTMLElement {
*/
panic() {
if (this.instance) {
try {
this.instance.destroy();
} catch (e) {
console.error(
"Whilst panicking ruffle, an additional error was encountered during destruction:",
e
);
}
this.instance.destroy();
this.instance = null;
}
// Clears out any existing content (ie play button or canvas) and replaces it with the error screen

View File

@ -152,7 +152,7 @@ impl Ruffle {
});
}
pub fn destroy(&mut self) -> Result<(), JsValue> {
pub fn destroy(&mut self) {
// Remove instance from the active list.
if let Some(instance) = INSTANCES.with(|instances| {
let mut instances = instances.borrow_mut();
@ -175,13 +175,12 @@ impl Ruffle {
// Cancel the animation handler, if it's still active.
if let Some(id) = instance.animation_handler_id {
if let Some(window) = web_sys::window() {
return window.cancel_animation_frame(id.into());
let _ = window.cancel_animation_frame(id.into());
}
}
}
// Player is dropped at this point.
Ok(())
}
#[allow(clippy::boxed_local)] // for js_bind