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
use webcore::value::Reference;
extern fn funcall_adapter< F: FnOnce() >( callback: *mut F ) {
let callback = unsafe {
Box::from_raw( callback )
};
callback();
}
pub trait IWindowOrWorker: AsRef< Reference > {
fn set_timeout< F: FnOnce() >( &self, callback: F, timeout: u32 ) {
let callback = Box::into_raw( Box::new( callback ) );
em_asm_int!( "\
Module.STDWEB.acquire_js_reference( $0 ).setTimeout( function() {\
Runtime.dynCall( 'vi', $1, [$2] );\
}, $3 );\
", self.as_ref().as_raw(), funcall_adapter::< F > as extern fn( *mut F ), callback, timeout );
}
}