Return a WasmResult from ModuleEnvironment methods (#886)

* [wasm] return a WasmResult from `declare_table_elements`

This method in particular needs to accommodate failure because any table index other than zero is
currently invalid.

* [wasm] additional failure handling improvements

- Adds `WasmResult<()>` as the return type for most of the `ModuleEnvironment` methods that
previously returned nothing.

- Replaces some panics with `WasmError::Unsupported` now that the methods can return a result.

- Adds a `wasm_unsupported!()` macro for early returns with a formatted unsupported message.
This commit is contained in:
Adam C. Foltzer
2019-08-07 13:23:32 -07:00
committed by GitHub
parent 00b8d019c9
commit 73670aab43
7 changed files with 204 additions and 91 deletions

View File

@@ -23,12 +23,13 @@
//! That is why `translate_function_body` takes an object having the `WasmRuntime` trait as
//! argument.
use super::{hash_map, HashMap};
use crate::environ::{FuncEnvironment, GlobalVariable, ReturnMode, WasmError, WasmResult};
use crate::environ::{FuncEnvironment, GlobalVariable, ReturnMode, WasmResult};
use crate::state::{ControlStackFrame, TranslationState};
use crate::translation_utils::{
blocktype_to_type, f32_translation, f64_translation, num_return_values,
};
use crate::translation_utils::{FuncIndex, MemoryIndex, SignatureIndex, TableIndex};
use crate::wasm_unsupported;
use core::{i32, u32};
use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
use cranelift_codegen::ir::types::*;
@@ -899,10 +900,10 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::I64AtomicRmw8UCmpxchg { .. }
| Operator::I64AtomicRmw16UCmpxchg { .. }
| Operator::I64AtomicRmw32UCmpxchg { .. } => {
return Err(WasmError::Unsupported("proposed thread operators"));
wasm_unsupported!("proposed thread operator {:?}", op);
}
Operator::RefNull | Operator::RefIsNull { .. } => {
return Err(WasmError::Unsupported("proposed reference-type operators"));
wasm_unsupported!("proposed reference-type operator {:?}", op);
}
Operator::MemoryInit { .. }
| Operator::DataDrop { .. }
@@ -915,7 +916,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::TableSet { .. }
| Operator::TableGrow { .. }
| Operator::TableSize { .. } => {
return Err(WasmError::Unsupported("proposed bulk memory operators"));
wasm_unsupported!("proposed bulk memory operator {:?}", op);
}
Operator::V128Load { .. }
| Operator::V128Store { .. }
@@ -1059,7 +1060,7 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
| Operator::F64x2ConvertUI64x2
| Operator::V8x16Shuffle1
| Operator::V8x16Shuffle2Imm { .. } => {
return Err(WasmError::Unsupported("proposed SIMD operators"));
wasm_unsupported!("proposed SIMD operator {:?}", op);
}
};
Ok(())