Make FuncRef nullable at the API level

This commit is contained in:
Mark McCaskey
2021-02-01 09:41:18 -08:00
parent e013581fda
commit 63f277bce4
6 changed files with 54 additions and 22 deletions

View File

@@ -67,7 +67,7 @@ fn table_new() -> Result<()> {
maximum: None,
};
let f = Function::new_native(&store, || {});
let table = Table::new(&store, table_type, Value::FuncRef(f))?;
let table = Table::new(&store, table_type, Value::FuncRef(Some(f)))?;
assert_eq!(*table.ty(), table_type);
// Anyrefs not yet supported
@@ -92,7 +92,7 @@ fn table_get() -> Result<()> {
maximum: Some(1),
};
let f = Function::new_native(&store, |num: i32| num + 1);
let table = Table::new(&store, table_type, Value::FuncRef(f.clone()))?;
let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?;
assert_eq!(*table.ty(), table_type);
let _elem = table.get(0).unwrap();
// assert_eq!(elem.funcref().unwrap(), f);
@@ -115,13 +115,13 @@ fn table_grow() -> Result<()> {
maximum: Some(10),
};
let f = Function::new_native(&store, |num: i32| num + 1);
let table = Table::new(&store, table_type, Value::FuncRef(f.clone()))?;
let table = Table::new(&store, table_type, Value::FuncRef(Some(f.clone())))?;
// Growing to a bigger maximum should return None
let old_len = table.grow(12, Value::FuncRef(f.clone()));
let old_len = table.grow(12, Value::FuncRef(Some(f.clone())));
assert!(old_len.is_err());
// Growing to a bigger maximum should return None
let old_len = table.grow(5, Value::FuncRef(f.clone()))?;
let old_len = table.grow(5, Value::FuncRef(Some(f.clone())))?;
assert_eq!(old_len, 0);
Ok(())