()
| 95 | #[test] |
| 96 | #[cfg_attr(miri, ignore)] |
| 97 | fn function_interposition() -> Result<()> { |
| 98 | let mut store = Store::<()>::default(); |
| 99 | let mut linker = Linker::new(store.engine()); |
| 100 | linker.allow_shadowing(true); |
| 101 | let mut module = Module::new( |
| 102 | store.engine(), |
| 103 | r#"(module (func (export "green") (result i32) (i32.const 7)))"#, |
| 104 | )?; |
| 105 | for _ in 0..4 { |
| 106 | let instance = linker.instantiate(&mut store, &module)?; |
| 107 | let green = instance.get_export(&mut store, "green").unwrap().clone(); |
| 108 | linker.define(&mut store, "red", "green", green)?; |
| 109 | module = Module::new( |
| 110 | store.engine(), |
| 111 | r#"(module |
| 112 | (import "red" "green" (func (result i32))) |
| 113 | (func (export "green") (result i32) (i32.mul (call 0) (i32.const 2))) |
| 114 | )"#, |
| 115 | )?; |
| 116 | } |
| 117 | let instance = linker.instantiate(&mut store, &module)?; |
| 118 | let func = instance |
| 119 | .get_export(&mut store, "green") |
| 120 | .unwrap() |
| 121 | .into_func() |
| 122 | .unwrap(); |
| 123 | let func = func.typed::<(), i32>(&store)?; |
| 124 | assert_eq!(func.call(&mut store, ())?, 112); |
| 125 | Ok(()) |
| 126 | } |
| 127 | |
| 128 | // Same as `function_interposition`, but the linker's name for the function |
| 129 | // differs from the module's name. |
nothing calls this directly
no test coverage detected