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

Function i31ref_table_grow

tests/all/table.rs:207–248  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

205
206#[test]
207fn i31ref_table_grow() -> Result<()> {
208 let mut config = Config::new();
209 config.wasm_function_references(true);
210 config.wasm_gc(true);
211
212 let engine = Engine::new(&config)?;
213 let mut store = Store::new(&engine, ());
214
215 for (elem_ty, init) in [
216 (RefType::I31REF, Ref::Any(None)),
217 (
218 RefType::new(false, HeapType::I31),
219 AnyRef::from_i31(&mut store, I31::default()).into(),
220 ),
221 ] {
222 let table_ty = TableType::new(elem_ty, 10, None);
223 let table = Table::new(&mut store, table_ty, init)?;
224 assert_eq!(table.size(&store), 10);
225 for i in 10..20 {
226 assert!(table.get(&mut store, i).is_none());
227 }
228 let expected = I31::wrapping_u32(42);
229 let grow_val = AnyRef::from_i31(&mut store, expected);
230 table.grow(&mut store, 10, grow_val.into())?;
231 for i in 10..20 {
232 let actual = table.get(&mut store, i).unwrap();
233 assert_eq!(
234 actual
235 .as_any()
236 .expect("is anyref")
237 .expect("is non null")
238 .as_i31(&store)
239 .expect("is in scope")
240 .expect("is i31"),
241 expected,
242 );
243 }
244 assert!(table.get(&mut store, 20).is_none());
245 }
246
247 Ok(())
248}
249
250#[test]
251fn i31ref_table_fill() -> Result<()> {

Callers

nothing calls this directly

Calls 7

OkFunction · 0.85
newFunction · 0.50
wasm_gcMethod · 0.45
growMethod · 0.45
unwrapMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected