mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-25 19:43:00 +03:00
29771b574c
This commit migrates from `wasm_bindgen!`-the-macro to `#[wasm_bindgen]`-the-attribute. The actual mechanics of the macro are relatively simple in just generating some shims here and there, but wrapping everything in one huge macro invocation can often seem intimidating as it gives off this feeling of "oh dear anything can happen here!" Using an attribute should curb expectations much more greatly of "oh there's just some extra stuff happening behind the scenes". The usage is otherwise relatively straightforward and close to what it was before, but check out the DESIGN.md/README.md changes for more info!
44 lines
1018 B
Rust
44 lines
1018 B
Rust
extern crate test_support;
|
|
|
|
#[test]
|
|
fn works() {
|
|
test_support::project()
|
|
.debug(false)
|
|
.file("src/lib.rs", r#"
|
|
#![feature(proc_macro)]
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
#[wasm_bindgen]
|
|
pub struct A {}
|
|
|
|
#[wasm_bindgen]
|
|
impl A {
|
|
pub fn new() -> A {
|
|
A {}
|
|
}
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
#[no_mangle]
|
|
pub extern fn clone(a: &JsValue) -> JsValue {
|
|
drop(a.clone());
|
|
a.clone()
|
|
}
|
|
"#)
|
|
.file("test.ts", r#"
|
|
import * as assert from "assert";
|
|
import * as wasm from "./out";
|
|
|
|
export function test() {
|
|
let sym = (Symbol as any)('a');
|
|
assert.strictEqual(wasm.clone(sym), sym);
|
|
let a = wasm.A.new();
|
|
a.free();
|
|
}
|
|
"#)
|
|
.test();
|
|
}
|