chiark / gitweb /
this jsstring does not call the text*coder machinery
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 11 Oct 2020 22:23:54 +0000 (23:23 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 11 Oct 2020 22:36:18 +0000 (23:36 +0100)
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 <ijackson@chiark.greenend.org.uk>
wasm/wasm.rs

index e6cf20daa4a2a18b402012761193daa7d3b8b281..2540a8033ccdfd5d796fd569e7bf9286c8def71f 100644 (file)
@@ -12,10 +12,16 @@ trait WasmError {
   fn e(self) -> JsValue;
 }
 
+fn mkstr(s: &str) -> JsValue {
+  let s : Vec<u16> = s.encode_utf16().collect();
+  let jss = js_sys::JsString::from_char_code(&s);
+  jss.into()
+}
+
 impl<E> 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]