namui_panic_hook/lib.rs
1use std::panic;
2use wasm_bindgen::prelude::*;
3
4#[wasm_bindgen]
5extern "C" {
6 #[wasm_bindgen(js_namespace = globalThis)]
7 fn panic(msg: String);
8}
9
10pub fn hook(info: &panic::PanicInfo) {
11 let msg = info.to_string();
12 panic(msg.clone());
13}
14
15#[inline]
16pub fn set_once() {
17 use std::sync::Once;
18 static SET_HOOK: Once = Once::new();
19 SET_HOOK.call_once(|| {
20 panic::set_hook(Box::new(hook));
21 });
22}