mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 23:41:45 +03:00
54 lines
662 B
Rust
54 lines
662 B
Rust
#![feature(use_extern_macros)]
|
|
|
|
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]
|
|
extern {
|
|
fn some_import();
|
|
static A: JsValue;
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn bar(_: &str) -> JsValue {
|
|
some_import();
|
|
A.clone()
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn baz(_: JsValue) {
|
|
}
|
|
|
|
#[test]
|
|
fn test_foo() {
|
|
foo(false);
|
|
A::new().foo();
|
|
}
|