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

Function call_indirect_native_from_exported_global

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

Source from the content-addressed store, hash-verified

358#[wasmtime_test(wasm_features(reference_types))]
359#[cfg_attr(miri, ignore)]
360fn 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]
390fn func_constructors() {

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected