feat(bindings/crypto-js): Redirect Rust panics to JavaScript console.

This commit is contained in:
Ivan Enderlin
2022-07-12 10:15:25 +02:00
parent f87764fabb
commit 8f8bd40e8d
2 changed files with 11 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "2404f83f7
wasm-bindgen = "0.2.80"
wasm-bindgen-futures = "0.4.30"
js-sys = "0.3.49"
console_error_panic_hook = "0.1.7"
serde_json = "1.0.79"
http = "0.2.6"
anyhow = "1.0"

View File

@@ -29,6 +29,16 @@ pub mod sync_events;
use js_sys::{Object, Reflect};
use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*};
/// Run some stuff when the Wasm module is instantiated.
///
/// Right now, it does the following:
///
/// * Redirect Rust panics to JavaScript console.
#[wasm_bindgen(start)]
pub fn start() {
console_error_panic_hook::set_once();
}
/// A really hacky and dirty code to downcast a `JsValue` to `T:
/// RefFromWasmAbi`, inspired by
/// https://github.com/rustwasm/wasm-bindgen/issues/2231#issuecomment-656293288.