| 358 | #[wasmtime_test(wasm_features(reference_types))] |
| 359 | #[cfg_attr(miri, ignore)] |
| 360 | fn call_indirect_native_from_exported_global(config: &mut Config) -> Result<()> { |
| 361 | let wasm = wat::parse_str( |
| 362 | r#" |
| 363 | (module |
| 364 | (global (export "global") (mut funcref) (ref.null func)) |
| 365 | (table 1 1 funcref) |
| 366 | (func (export "run") (result i32 i32 i32) |
| 367 | i32.const 0 |
| 368 | global.get 0 |
| 369 | table.set |
| 370 | i32.const 0 |
| 371 | call_indirect (result i32 i32 i32) |
| 372 | ) |
| 373 | ) |
| 374 | "#, |
| 375 | )?; |
| 376 | let engine = Engine::new(&config)?; |
| 377 | let mut store = Store::<()>::new(&engine, ()); |
| 378 | let module = Module::new(store.engine(), &wasm)?; |
| 379 | let func = Func::wrap(&mut store, || -> (i32, i32, i32) { (10, 20, 30) }); |
| 380 | let instance = Instance::new(&mut store, &module, &[])?; |
| 381 | let global = instance.get_global(&mut store, "global").unwrap(); |
| 382 | global.set(&mut store, func.into())?; |
| 383 | let run = instance.get_typed_func::<(), (i32, i32, i32)>(&mut store, "run")?; |
| 384 | let results = run.call(&mut store, ())?; |
| 385 | assert_eq!(results, (10, 20, 30)); |
| 386 | Ok(()) |
| 387 | } |
| 388 | |
| 389 | #[test] |
| 390 | fn func_constructors() { |