mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
This patch takes the entire `wasmer-js` crate and merges it into the `wasmer` crate. Inside the `lib/api/src/` directory, there are 2 new directories: 1. a new `sys` directory, which contains the usual `wasmer` crate implementation, 2. a new directory `js`, which contains the implementation of `wasmer-js`. The `Cargo.toml` file is still compatible. The `default` feature fallbacks to `sys-default`, which enables the `sys` feature. All features related to compilers or engines or anything else prior this patch, activates the `sys` feature. Parallel to that, there is a `js-default` and `js` features. The `Cargo.toml` file is extensively documented to explain what are dependencies, dev-dependencies, features and other sections related to `sys` or to `js`. There is a bug with `wasm_bindgen_test` where it doesn't compile or look for tests in `tests/*/<test>.rs`. The hack is to name files `tests/js_<test>.rs`. Ugly, but it works.
43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
#[cfg(feature = "sys")]
|
|
mod sys {
|
|
use anyhow::Result;
|
|
use wasmer::*;
|
|
|
|
#[test]
|
|
fn exports_work_after_multiple_instances_have_been_freed() -> Result<()> {
|
|
let store = Store::default();
|
|
let module = Module::new(
|
|
&store,
|
|
"
|
|
(module
|
|
(type $sum_t (func (param i32 i32) (result i32)))
|
|
(func $sum_f (type $sum_t) (param $x i32) (param $y i32) (result i32)
|
|
local.get $x
|
|
local.get $y
|
|
i32.add)
|
|
(export \"sum\" (func $sum_f)))
|
|
",
|
|
)?;
|
|
|
|
let import_object = ImportObject::new();
|
|
let instance = Instance::new(&module, &import_object)?;
|
|
let instance2 = instance.clone();
|
|
let instance3 = instance.clone();
|
|
|
|
// The function is cloned to “break” the connection with `instance`.
|
|
let sum = instance.exports.get_function("sum")?.clone();
|
|
|
|
drop(instance);
|
|
drop(instance2);
|
|
drop(instance3);
|
|
|
|
// All instances have been dropped, but `sum` continues to work!
|
|
assert_eq!(
|
|
sum.call(&[Value::I32(1), Value::I32(2)])?.into_vec(),
|
|
vec![Value::I32(3)],
|
|
);
|
|
|
|
Ok(())
|
|
}
|
|
}
|