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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
#![no_std] use js::*; pub fn clear() { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(){ console.clear(); }", ) }) .invoke_0(); } pub fn log(msg: &str) { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(strPtr,strLen){ console.log(this.readUtf8FromMemory(strPtr,strLen)); }", ) }) .invoke_2(msg.as_ptr() as u32, msg.len() as u32); } pub fn warning(msg: &str) { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(strPtr,strLen){ console.warn(this.readUtf8FromMemory(strPtr,strLen)); }", ) }) .invoke_2(msg.as_ptr() as u32, msg.len() as u32); } pub fn error(msg: &str) { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(strPtr,strLen){ console.error(this.readUtf8FromMemory(strPtr,strLen)); }", ) }) .invoke_2(msg.as_ptr() as u32, msg.len() as u32); } pub fn time(msg: &str) { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(strPtr,strLen){ console.time(this.readUtf8FromMemory(strPtr,strLen)); }", ) }) .invoke_2(msg.as_ptr() as u32, msg.len() as u32); } pub fn time_end(msg: &str) { static FN: once_cell::sync::OnceCell<JSFunction> = once_cell::sync::OnceCell::new(); FN.get_or_init(|| { register_function( "function(strPtr,strLen){ console.timeEnd(this.readUtf8FromMemory(strPtr,strLen)); }", ) }) .invoke_2(msg.as_ptr() as u32, msg.len() as u32); }