Skip to content

Commit

Permalink
Make too many imports an instantiation error (#1478)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
alexcrichton authored Apr 7, 2020
1 parent 6a68130 commit 1a2eccc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
let config = store.engine().config();
let instance_handle = instantiate(
Expand Down
13 changes: 13 additions & 0 deletions crates/api/tests/instance.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 1a2eccc

Please sign in to comment.