()
| 626 | #[test] |
| 627 | #[cfg_attr(miri, ignore)] |
| 628 | fn 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| { |
nothing calls this directly
no test coverage detected