MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / call_indirect_native_from_exported_table

Function call_indirect_native_from_exported_table

tests/all/func.rs:332–355  ·  view source on GitHub ↗
(config: &mut Config)

Source from the content-addressed store, hash-verified

330#[wasmtime_test]
331#[cfg_attr(miri, ignore)]
332fn call_indirect_native_from_exported_table(config: &mut Config) -> Result<()> {
333 let wasm = wat::parse_str(
334 r#"
335 (module
336 (table (export "table") 1 1 funcref)
337 (func (export "run") (result i32 i32 i32)
338 i32.const 0
339 call_indirect (result i32 i32 i32)
340 )
341 )
342 "#,
343 )?;
344 let engine = Engine::new(&config)?;
345 let mut store = Store::<()>::new(&engine, ());
346 let module = Module::new(store.engine(), &wasm)?;
347 let func = Func::wrap(&mut store, || -> (i32, i32, i32) { (10, 20, 30) });
348 let instance = Instance::new(&mut store, &module, &[])?;
349 let table = instance.get_table(&mut store, "table").unwrap();
350 table.set(&mut store, 0, func.into())?;
351 let run = instance.get_typed_func::<(), (i32, i32, i32)>(&mut store, "run")?;
352 let results = run.call(&mut store, ())?;
353 assert_eq!(results, (10, 20, 30));
354 Ok(())
355}
356
357// wasm exports global, host puts native-call funcref in global, wasm calls funcref
358#[wasmtime_test(wasm_features(reference_types))]

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
newFunction · 0.50
engineMethod · 0.45
unwrapMethod · 0.45
get_tableMethod · 0.45
setMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected