1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::panic;
use webcore::ffi;
#[inline(never)]
#[cold]
pub fn initialize() {
static mut INITIALIZED: bool = false;
unsafe {
if INITIALIZED {
return;
}
INITIALIZED = true;
}
#[cfg(not(feature = "docs-rs"))]
stdweb_internal_runtime_initialize!( __js_raw_asm );
if cfg!( test ) == false {
panic::set_hook( Box::new( |info| {
__js_raw_asm!( "console.error( 'Encountered a panic!' );" );
if let Some( value ) = info.payload().downcast_ref::< String >() {
__js_raw_asm!( "\
console.error( 'Panic error message:', Module.STDWEB_PRIVATE.to_js_string( $0, $1 ) );\
", value.as_ptr(), value.len() );
}
if let Some( location ) = info.location() {
let file = location.file();
__js_raw_asm!( "\
console.error( 'Panic location:', Module.STDWEB_PRIVATE.to_js_string( $0, $1 ) + ':' + $2 );\
", file.as_ptr(), file.len(), location.line() );
}
}));
}
}
pub fn event_loop() {
ffi::event_loop();
}