From: Ian Jackson Date: Sun, 11 Oct 2020 22:23:54 +0000 (+0100) Subject: this jsstring does not call the text*coder machinery X-Git-Tag: otter-0.2.0~673 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=33bf18ce79c5e3b99a3058248102e63306a8759a;p=otter.git 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 --- 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]