mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-15 21:02:10 +03:00
68537b9649
This commit adds an optimization to `wasm-bindgen` to directly import and invoke other modules' functions from the wasm module, rather than going through a shim in the imported bindings. This will be an important optimization in the future for the host bindings proposal, but for now it's largely just a proof-of-concept to show that we can do it and is unlikely to bring about many performance benefits. The implementation in this commit is largely refactoring to reorganize a bit how functions are imported, but the implementation happens in `generate_import_function`. With this commit, 71/287 imports in the `tests/wasm/main.rs` suite get hooked up directly to the ES modules, no shims needed!
41 lines
1022 B
Rust
41 lines
1022 B
Rust
use wasm_bindgen::prelude::*;
|
|
use wasm_bindgen_test::*;
|
|
|
|
#[wasm_bindgen(module = "tests/wasm/vendor_prefix.js")]
|
|
extern "C" {
|
|
fn import_me(x: &str);
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
extern "C" {
|
|
#[wasm_bindgen(vendor_prefix = webkit)]
|
|
type MySpecialApi;
|
|
#[wasm_bindgen(constructor)]
|
|
fn new() -> MySpecialApi;
|
|
#[wasm_bindgen(method)]
|
|
fn foo(this: &MySpecialApi) -> u32;
|
|
|
|
#[wasm_bindgen(vendor_prefix = webkit)]
|
|
type MySpecialApi2;
|
|
#[wasm_bindgen(constructor)]
|
|
fn new() -> MySpecialApi2;
|
|
#[wasm_bindgen(method)]
|
|
fn foo(this: &MySpecialApi2) -> u32;
|
|
|
|
#[wasm_bindgen(vendor_prefix = a, vendor_prefix = b)]
|
|
type MySpecialApi3;
|
|
#[wasm_bindgen(constructor)]
|
|
fn new() -> MySpecialApi3;
|
|
#[wasm_bindgen(method)]
|
|
fn foo(this: &MySpecialApi3) -> u32;
|
|
}
|
|
|
|
#[wasm_bindgen_test]
|
|
pub fn polyfill_works() {
|
|
import_me("foo");
|
|
|
|
assert_eq!(MySpecialApi::new().foo(), 123);
|
|
assert_eq!(MySpecialApi2::new().foo(), 124);
|
|
assert_eq!(MySpecialApi3::new().foo(), 125);
|
|
}
|