Fix running enter/exit hooks on start functions (#3001)
This commit fixes running the store's enter/exit hooks into wasm which accidentally weren't run for an instance's `start` function. The fix here was mostly to just sink the enter/exit hook much lower in the code to `invoke_wasm_and_catch_traps`, which is the common entry point for all wasm calls. This did involve propagating the `StoreContext<T>` generic rather than using `StoreOpaque` unfortunately, but it is overally not too too much code and we generally wanted most of it inlined anyway.
This commit is contained in:
@@ -200,6 +200,43 @@ async fn call_linked_func_async() -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instantiate() -> Result<(), Error> {
|
||||
let mut store = Store::<State>::default();
|
||||
store.entering_native_code_hook(State::entering_native);
|
||||
store.exiting_native_code_hook(State::exiting_native);
|
||||
|
||||
let m = Module::new(store.engine(), "(module)")?;
|
||||
Instance::new(&mut store, &m, &[])?;
|
||||
assert_eq!(store.data().switches_into_native, 0);
|
||||
|
||||
let m = Module::new(store.engine(), "(module (func) (start 0))")?;
|
||||
Instance::new(&mut store, &m, &[])?;
|
||||
assert_eq!(store.data().switches_into_native, 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn instantiate_async() -> Result<(), Error> {
|
||||
let mut config = Config::new();
|
||||
config.async_support(true);
|
||||
let engine = Engine::new(&config)?;
|
||||
let mut store = Store::new(&engine, State::default());
|
||||
store.entering_native_code_hook(State::entering_native);
|
||||
store.exiting_native_code_hook(State::exiting_native);
|
||||
|
||||
let m = Module::new(store.engine(), "(module)")?;
|
||||
Instance::new_async(&mut store, &m, &[]).await?;
|
||||
assert_eq!(store.data().switches_into_native, 0);
|
||||
|
||||
let m = Module::new(store.engine(), "(module (func) (start 0))")?;
|
||||
Instance::new_async(&mut store, &m, &[]).await?;
|
||||
assert_eq!(store.data().switches_into_native, 1);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
enum Context {
|
||||
Native,
|
||||
Vm,
|
||||
|
||||
Reference in New Issue
Block a user