From 33bf18ce79c5e3b99a3058248102e63306a8759a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 11 Oct 2020 23:23:54 +0100 Subject: [PATCH] this jsstring does not call the text*coder machinery later note: but actually I'm not going to bother about this. TextEncoder and TextDecoder are supported in everything other than earlier versions of Edge which probably don't work anyway Signed-off-by: Ian Jackson --- wasm/wasm.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/wasm/wasm.rs b/wasm/wasm.rs index e6cf20da..2540a803 100644 --- a/wasm/wasm.rs +++ b/wasm/wasm.rs @@ -12,10 +12,16 @@ trait WasmError { fn e(self) -> JsValue; } +fn mkstr(s: &str) -> JsValue { + let s : Vec = s.encode_utf16().collect(); + let jss = js_sys::JsString::from_char_code(&s); + jss.into() +} + impl WasmError for E where E: Display { fn e(self) -> JsValue { let s = format!("{}", self); - JsValue::from_str(&s) + mkstr(&s) } } @@ -36,7 +42,14 @@ pub fn check(packed: &JsValue) { ZCoord::check_str(&s).ok_or(zcoord::ParseError).e()?; } -const X : &'static str = "invalid value passed to wasm"; +#[wasm_bindgen] +pub fn jsstring(x: u32) -> JsValue { + let s = format!("hi!{:?}",x); + // JsValue::from_str(&s); + mkstr(&s) +} + +//const X : &'static str = "invalid value passed to wasm"; /* #[throws(JsValue)] #[wasm_bindgen] -- 2.30.2