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

Function table_init

tests/all/pooling_allocator.rs:319–367  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

317#[test]
318#[cfg_attr(miri, ignore)]
319fn table_init() -> Result<()> {
320 let mut pool = crate::small_pool_config();
321 pool.max_memory_size(0).table_elements(6);
322 let mut config = Config::new();
323 config.allocation_strategy(pool);
324
325 let engine = Engine::new(&config)?;
326
327 let module = Module::new(
328 &engine,
329 r#"
330 (module
331 (table (export "t") 6 funcref)
332 (elem (i32.const 1) 1 2 3 4)
333 (elem (i32.const 0) 0)
334 (func)
335 (func (param i32))
336 (func (param i32 i32))
337 (func (param i32 i32 i32))
338 (func (param i32 i32 i32 i32))
339 )
340 "#,
341 )?;
342
343 let mut store = Store::new(&engine, ());
344 let instance = Instance::new(&mut store, &module, &[])?;
345 let table = instance.get_table(&mut store, "t").unwrap();
346
347 for i in 0..5 {
348 let v = table.get(&mut store, i).expect("table should have entry");
349 let f = v
350 .as_func()
351 .expect("expected funcref")
352 .expect("expected non-null value");
353 assert_eq!(f.ty(&store).params().len(), i as usize);
354 }
355
356 assert!(
357 table
358 .get(&mut store, 5)
359 .expect("table should have entry")
360 .as_func()
361 .expect("expected funcref")
362 .is_none(),
363 "funcref should be null"
364 );
365
366 Ok(())
367}
368
369#[test]
370fn table_zeroed() -> Result<()> {

Callers

nothing calls this directly

Calls 11

OkFunction · 0.85
allocation_strategyMethod · 0.80
small_pool_configFunction · 0.70
newFunction · 0.50
table_elementsMethod · 0.45
max_memory_sizeMethod · 0.45
unwrapMethod · 0.45
get_tableMethod · 0.45
expectMethod · 0.45
getMethod · 0.45
as_funcMethod · 0.45

Tested by

no test coverage detected