Update vm::Table to support more than just funcref

This commit is contained in:
Mark McCaskey
2021-01-29 10:19:19 -08:00
parent a0cadcf361
commit e013581fda
6 changed files with 125 additions and 37 deletions

View File

@@ -6,7 +6,7 @@ use crate::RuntimeError;
use crate::TableType;
use std::sync::Arc;
use wasmer_engine::{Export, ExportTable};
use wasmer_vm::{Table as RuntimeTable, VMCallerCheckedAnyfunc, VMExportTable};
use wasmer_vm::{Table as RuntimeTable, TableReference, VMExportTable};
/// A WebAssembly `table` instance.
///
@@ -26,7 +26,7 @@ pub struct Table {
fn set_table_item(
table: &dyn RuntimeTable,
item_index: u32,
item: VMCallerCheckedAnyfunc,
item: TableReference,
) -> Result<(), RuntimeError> {
table.set(item_index, item).map_err(|e| e.into())
}
@@ -39,7 +39,7 @@ impl Table {
/// This function will construct the `Table` using the store
/// [`BaseTunables`][crate::tunables::BaseTunables].
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Self, RuntimeError> {
let item = init.into_checked_anyfunc(store)?;
let item = init.into_table_reference(store)?;
let tunables = store.tunables();
let style = tunables.table_style(&ty);
let table = tunables
@@ -70,12 +70,12 @@ impl Table {
/// Retrieves an element of the table at the provided `index`.
pub fn get(&self, index: u32) -> Option<Val> {
let item = self.table.get(index)?;
Some(ValFuncRef::from_checked_anyfunc(item, &self.store))
Some(ValFuncRef::from_table_reference(item, &self.store))
}
/// Sets an element `val` in the Table at the provided `index`.
pub fn set(&self, index: u32, val: Val) -> Result<(), RuntimeError> {
let item = val.into_checked_anyfunc(&self.store)?;
let item = val.into_table_reference(&self.store)?;
set_table_item(self.table.as_ref(), index, item)
}
@@ -94,7 +94,7 @@ impl Table {
///
/// Returns an error if the `delta` is out of bounds for the table.
pub fn grow(&self, delta: u32, init: Val) -> Result<u32, RuntimeError> {
let item = init.into_checked_anyfunc(&self.store)?;
let item = init.into_table_reference(&self.store)?;
match self.table.grow(delta) {
Some(len) => {
for i in 0..delta {