wasmtime: Implement table.fill

Part of #929
This commit is contained in:
Nick Fitzgerald
2020-07-02 16:56:02 -07:00
parent d87ada209c
commit 3555f97906
5 changed files with 97 additions and 13 deletions

View File

@@ -67,6 +67,26 @@ impl Table {
}
}
/// Fill `table[dst..dst + len]` with `val`.
///
/// Returns a trap error on out-of-bounds accesses.
pub fn fill(&self, dst: u32, val: TableElement, len: u32) -> Result<(), Trap> {
let start = dst;
let end = start
.checked_add(len)
.ok_or_else(|| Trap::wasm(ir::TrapCode::TableOutOfBounds))?;
if end > self.size() {
return Err(Trap::wasm(ir::TrapCode::TableOutOfBounds));
}
for i in start..end {
self.set(i, val.clone()).unwrap();
}
Ok(())
}
/// Grow table by the specified amount of elements.
///
/// Returns the previous size of the table if growth is successful.