function startup() {
console.log('STARTUP');
-// let mut = wasm_bindgen.mutable('4200000000');
-// let y = mut.next();
-// console.log('FOO', mut, y);
- let x = wasm_bindgen.jsstring(12);
- console.log(x);
+ console.log(wasm_bindgen.canary("OK"));
var body = document.getElementById("main-body")!;
ctoken = body.dataset.ctoken!;
use wasm_bindgen::prelude::*;
use fehler::throws;
use std::fmt::Display;
+use js_sys::JsString;
use zcoord::ZCoord;
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);
- mkstr(&s)
+ JsValue::from_str(&s)
}
}
ZCoord::check_str(&s).ok_or(zcoord::ParseError).e()?;
}
-#[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)]
impl ZCoordIterator {
pub fn next(&mut self) -> u32 { 42 }
}
+
+#[wasm_bindgen]
+pub fn canary(s: &str) -> JsString {
+ // returning String produces a wasm-opt error, as here
+ // https://github.com/WebAssembly/binaryen/issues/3006
+ format!("WASM {}", s).into()
+}