Make too many imports an instantiation error (#1478)
* Make too many imports an instantiation error Previously we'd accidentally only take the head of the list when instantiating, but instead this changes the API to require exactly the right number of imports.
This commit is contained in:
@@ -124,6 +124,14 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if imports.len() != module.imports().len() {
|
||||||
|
bail!(
|
||||||
|
"wrong number of imports provided, {} != {}",
|
||||||
|
imports.len(),
|
||||||
|
module.imports().len()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
module.register_frame_info();
|
module.register_frame_info();
|
||||||
let config = store.engine().config();
|
let config = store.engine().config();
|
||||||
let instance_handle = instantiate(
|
let instance_handle = instantiate(
|
||||||
|
|||||||
13
crates/api/tests/instance.rs
Normal file
13
crates/api/tests/instance.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use wasmtime::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn wrong_import_numbers() -> Result<()> {
|
||||||
|
let store = Store::default();
|
||||||
|
let module = Module::new(&store, r#"(module (import "" "" (func)))"#)?;
|
||||||
|
|
||||||
|
assert!(Instance::new(&module, &[]).is_err());
|
||||||
|
let func = Func::wrap(&store, || {});
|
||||||
|
assert!(Instance::new(&module, &[func.clone().into(), func.into()]).is_err());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user