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

Function import_works

tests/all/func.rs:628–760  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

626#[test]
627#[cfg_attr(miri, ignore)]
628fn import_works() -> Result<()> {
629 let _ = env_logger::try_init();
630
631 static HITS: AtomicUsize = AtomicUsize::new(0);
632
633 let wasm = wat::parse_str(
634 r#"
635 (import "" "" (func))
636 (import "" "" (func (param i32) (result i32)))
637 (import "" "" (func (param i32) (param i64)))
638 (import "" "" (func (param i32 i64 i32 f32 f64 externref externref funcref anyref anyref i31ref)))
639
640 (func (export "run") (param externref externref funcref)
641 call 0
642 i32.const 0
643 call 1
644 i32.const 1
645 i32.add
646 i64.const 3
647 call 2
648
649 i32.const 100
650 i64.const 200
651 i32.const 300
652 f32.const 400
653 f64.const 500
654 local.get 0
655 local.get 1
656 local.get 2
657 (ref.i31 (i32.const 36))
658 (ref.i31 (i32.const 42))
659 (ref.i31 (i32.const 0x1234))
660 call 3
661 )
662 "#,
663 )?;
664
665 let mut config = Config::new();
666 config.wasm_reference_types(true);
667 config.wasm_function_references(true);
668 config.wasm_gc(true);
669
670 let engine = Engine::new(&config)?;
671 let mut store = Store::new(&engine, ());
672 let module = Module::new(&engine, &wasm)?;
673
674 let imports = [
675 Func::wrap(&mut store, || {
676 assert_eq!(HITS.fetch_add(1, SeqCst), 0);
677 })
678 .into(),
679 Func::wrap(&mut store, |x: i32| -> i32 {
680 assert_eq!(x, 0);
681 assert_eq!(HITS.fetch_add(1, SeqCst), 1);
682 1
683 })
684 .into(),
685 Func::wrap(&mut store, |x: i32, y: i64| {

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
FuncRefClass · 0.85
newFunction · 0.50
ExternRefClass · 0.50
wasm_reference_typesMethod · 0.45
wasm_gcMethod · 0.45
unwrapMethod · 0.45
callMethod · 0.45
as_refMethod · 0.45
get_funcMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected