2018-08-06 19:55:20 +03:00
|
|
|
extern crate wasm_bindgen;
|
|
|
|
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub struct A {
|
|
|
|
x: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
impl A {
|
|
|
|
pub fn new() -> A {
|
|
|
|
A { x: 3 }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn foo(&self) {
|
|
|
|
drop(self.x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn foo(x: bool) {
|
|
|
|
A::new().foo();
|
|
|
|
|
|
|
|
if x {
|
|
|
|
bar("test");
|
|
|
|
baz(JsValue::from(3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-09-26 18:26:00 +03:00
|
|
|
extern "C" {
|
2018-08-06 19:55:20 +03:00
|
|
|
fn some_import();
|
|
|
|
static A: JsValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn bar(_: &str) -> JsValue {
|
|
|
|
some_import();
|
|
|
|
A.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
2018-09-26 18:26:00 +03:00
|
|
|
pub fn baz(_: JsValue) {}
|
2018-08-06 19:55:20 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_foo() {
|
|
|
|
foo(false);
|
|
|
|
A::new().foo();
|
|
|
|
}
|