mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 05:08:19 +00:00
Update vm::Table to support more than just funcref
This commit is contained in:
12
lib/api/src/externals/table.rs
vendored
12
lib/api/src/externals/table.rs
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user