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

Function get_set_funcref_globals_via_api

tests/all/externals.rs:210–242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

208
209#[test]
210fn get_set_funcref_globals_via_api() -> wasmtime::Result<()> {
211 let mut cfg = Config::new();
212 cfg.wasm_reference_types(true);
213 let engine = Engine::new(&cfg)?;
214 let mut store = Store::new(&engine, ());
215
216 let f = Func::wrap(&mut store, || {});
217
218 // Initialize with a null funcref.
219
220 let global = Global::new(
221 &mut store,
222 GlobalType::new(ValType::FUNCREF, Mutability::Var),
223 Val::FuncRef(None),
224 )?;
225 assert!(global.get(&mut store).unwrap_funcref().is_none());
226
227 global.set(&mut store, Val::FuncRef(Some(f)))?;
228 let f2 = global.get(&mut store).unwrap_funcref().cloned().unwrap();
229 assert!(FuncType::eq(&f.ty(&store), &f2.ty(&store)));
230
231 // Initialize with a non-null funcref.
232
233 let global = Global::new(
234 &mut store,
235 GlobalType::new(ValType::FUNCREF, Mutability::Var),
236 Val::FuncRef(Some(f)),
237 )?;
238 let f2 = global.get(&mut store).unwrap_funcref().cloned().unwrap();
239 assert!(FuncType::eq(&f.ty(&store), &f2.ty(&store)));
240
241 Ok(())
242}
243
244#[test]
245fn create_get_set_funcref_tables_via_api() -> wasmtime::Result<()> {

Callers

nothing calls this directly

Calls 8

FuncRefClass · 0.85
OkFunction · 0.85
unwrap_funcrefMethod · 0.80
newFunction · 0.50
wasm_reference_typesMethod · 0.45
setMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected