| 1089 | |
| 1090 | #[test] |
| 1091 | fn no_actual_wasm_code() -> Result<()> { |
| 1092 | let component = r#" |
| 1093 | (component |
| 1094 | (import "f" (func $f)) |
| 1095 | |
| 1096 | (core func $f_lower |
| 1097 | (canon lower (func $f)) |
| 1098 | ) |
| 1099 | (core module $m |
| 1100 | (import "" "" (func $f)) |
| 1101 | (export "f" (func $f)) |
| 1102 | ) |
| 1103 | (core instance $i (instantiate $m |
| 1104 | (with "" (instance |
| 1105 | (export "" (func $f_lower)) |
| 1106 | )) |
| 1107 | )) |
| 1108 | (func (export "thunk") |
| 1109 | (canon lift |
| 1110 | (core func $i "f") |
| 1111 | ) |
| 1112 | ) |
| 1113 | ) |
| 1114 | "#; |
| 1115 | |
| 1116 | let engine = super::engine(); |
| 1117 | let component = Component::new(&engine, component)?; |
| 1118 | let mut store = Store::new(&engine, 0); |
| 1119 | |
| 1120 | // First, test the static API |
| 1121 | |
| 1122 | let mut linker = Linker::new(&engine); |
| 1123 | linker.root().func_wrap( |
| 1124 | "f", |
| 1125 | |mut store: StoreContextMut<'_, u32>, _: ()| -> Result<()> { |
| 1126 | *store.data_mut() += 1; |
| 1127 | Ok(()) |
| 1128 | }, |
| 1129 | )?; |
| 1130 | |
| 1131 | let instance = linker.instantiate(&mut store, &component)?; |
| 1132 | let thunk = instance.get_typed_func::<(), ()>(&mut store, "thunk")?; |
| 1133 | |
| 1134 | assert_eq!(*store.data(), 0); |
| 1135 | thunk.call(&mut store, ())?; |
| 1136 | assert_eq!(*store.data(), 1); |
| 1137 | |
| 1138 | // Next, test the dynamic API |
| 1139 | |
| 1140 | *store.data_mut() = 0; |
| 1141 | let mut linker = Linker::new(&engine); |
| 1142 | linker |
| 1143 | .root() |
| 1144 | .func_new("f", |mut store: StoreContextMut<'_, u32>, _, _, _| { |
| 1145 | *store.data_mut() += 1; |
| 1146 | Ok(()) |
| 1147 | })?; |
| 1148 | |