Move around some panics in wasmtime (#804)

In preparation for eventual support for wasm interface types this commit
moves around a few panics internally inside of conversions between the
`wasmtime` crate and the underlying jit support crates. This should have
any immediately-visible user changes, but the goal is that this'll help
support interface types which means `wasmtime` will have types that are
not supported by wasmtime itself and we'll be able to more gracefully
support that with error messages instead of accidental panics.
This commit is contained in:
Alex Crichton
2020-01-10 16:27:52 -06:00
committed by GitHub
parent ef2177ed3a
commit a45b037bfc
6 changed files with 99 additions and 57 deletions

View File

@@ -163,8 +163,12 @@ impl Func {
store: &Store,
instance_handle: InstanceHandle,
) -> Self {
// This is only called with `Export::Function`, and since it's coming
// from wasmtime_runtime itself we should support all the types coming
// out of it, so assert such here.
let ty = if let wasmtime_runtime::Export::Function { signature, .. } = &export {
FuncType::from_wasmtime_signature(signature.clone())
.expect("core wasm signature should be supported")
} else {
panic!("expected function export")
};
@@ -258,9 +262,12 @@ impl Global {
let global = if let wasmtime_runtime::Export::Global { ref global, .. } = export {
global
} else {
panic!("wasmtime export is not memory")
panic!("wasmtime export is not global")
};
let ty = GlobalType::from_wasmtime_global(&global);
// The original export is coming from wasmtime_runtime itself we should
// support all the types coming out of it, so assert such here.
let ty = GlobalType::from_wasmtime_global(&global)
.expect("core wasm global type should be supported");
Global {
inner: Rc::new(GlobalInner {
_store: store.clone(),