Fail with Trap in Instance::new() instead of Error (#683)

This commit is contained in:
Yury Delendik
2019-12-30 16:25:16 -06:00
committed by GitHub
parent 51f3ac0c45
commit 681445b18b
18 changed files with 172 additions and 86 deletions

View File

@@ -10,7 +10,7 @@ use wasmtime::{
pub fn dummy_imports(
store: &HostRef<Store>,
import_tys: &[ImportType],
) -> Result<Vec<Extern>, HostRef<Trap>> {
) -> Result<Vec<Extern>, Trap> {
let mut imports = Vec::with_capacity(import_tys.len());
for imp in import_tys {
imports.push(match imp.ty() {
@@ -45,7 +45,7 @@ impl DummyFunc {
}
impl Callable for DummyFunc {
fn call(&self, _params: &[Val], results: &mut [Val]) -> Result<(), HostRef<Trap>> {
fn call(&self, _params: &[Val], results: &mut [Val]) -> Result<(), Trap> {
for (ret_ty, result) in self.0.results().iter().zip(results) {
*result = dummy_value(ret_ty)?;
}
@@ -55,38 +55,38 @@ impl Callable for DummyFunc {
}
/// Construct a dummy value for the given value type.
pub fn dummy_value(val_ty: &ValType) -> Result<Val, HostRef<Trap>> {
pub fn dummy_value(val_ty: &ValType) -> Result<Val, Trap> {
Ok(match val_ty {
ValType::I32 => Val::I32(0),
ValType::I64 => Val::I64(0),
ValType::F32 => Val::F32(0),
ValType::F64 => Val::F64(0),
ValType::V128 => {
return Err(HostRef::new(Trap::new(
return Err(Trap::new(
"dummy_value: unsupported function return type: v128".to_string(),
)))
))
}
ValType::AnyRef => {
return Err(HostRef::new(Trap::new(
return Err(Trap::new(
"dummy_value: unsupported function return type: anyref".to_string(),
)))
))
}
ValType::FuncRef => {
return Err(HostRef::new(Trap::new(
return Err(Trap::new(
"dummy_value: unsupported function return type: funcref".to_string(),
)))
))
}
})
}
/// Construct a dummy global for the given global type.
pub fn dummy_global(store: &HostRef<Store>, ty: GlobalType) -> Result<Global, HostRef<Trap>> {
pub fn dummy_global(store: &HostRef<Store>, ty: GlobalType) -> Result<Global, Trap> {
let val = dummy_value(ty.content())?;
Ok(Global::new(store, ty, val))
}
/// Construct a dummy table for the given table type.
pub fn dummy_table(store: &HostRef<Store>, ty: TableType) -> Result<Table, HostRef<Trap>> {
pub fn dummy_table(store: &HostRef<Store>, ty: TableType) -> Result<Table, Trap> {
let init_val = dummy_value(&ty.element())?;
Ok(Table::new(store, ty, init_val))
}