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

Function functions_in_instances

tests/all/component_model/import.rs:172–268  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170
171#[test]
172fn functions_in_instances() -> Result<()> {
173 let component = r#"
174 (component
175 (type $import-type (instance
176 (export "a" (func (param "a" string)))
177 ))
178 (import (interface "test:test/foo") (instance $import (type $import-type)))
179 (alias export $import "a" (func $log))
180
181 (core module $libc
182 (memory (export "memory") 1)
183
184 (func (export "realloc") (param i32 i32 i32 i32) (result i32)
185 unreachable)
186 )
187 (core instance $libc (instantiate $libc))
188 (core func $log_lower
189 (canon lower (func $log) (memory $libc "memory") (realloc (func $libc "realloc")))
190 )
191 (core module $m
192 (import "libc" "memory" (memory 1))
193 (import "host" "log" (func $log (param i32 i32)))
194
195 (func (export "call")
196 i32.const 5
197 i32.const 11
198 call $log)
199
200 (data (i32.const 5) "hello world")
201 )
202 (core instance $i (instantiate $m
203 (with "libc" (instance $libc))
204 (with "host" (instance (export "log" (func $log_lower))))
205 ))
206 (func $call
207 (canon lift (core func $i "call"))
208 )
209 (component $c
210 (import "import-call" (func $f))
211 (export "call" (func $f))
212 )
213 (instance $export (instantiate $c
214 (with "import-call" (func $call))
215 ))
216 (export (interface "test:test/foo") (instance $export))
217 )
218 "#;
219
220 let engine = super::engine();
221 let component = Component::new(&engine, component)?;
222 let instance_index = component.get_export_index(None, "test:test/foo").unwrap();
223 let func_index = component
224 .get_export_index(Some(&instance_index), "call")
225 .unwrap();
226 let mut store = Store::new(&engine, None);
227 assert!(store.data().is_none());
228
229 // First, test the static API

Callers

nothing calls this directly

Calls 14

OkFunction · 0.85
to_strMethod · 0.80
engineFunction · 0.50
newFunction · 0.50
unwrapMethod · 0.45
get_export_indexMethod · 0.45
func_wrapMethod · 0.45
instanceMethod · 0.45
to_stringMethod · 0.45
data_mutMethod · 0.45
instantiateMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected