Skip to content

Commit

Permalink
fix: make function Plugin::function_extists check the type of the fun…
Browse files Browse the repository at this point in the history
…ctions. (#664)

This PR addresses #654
It checks the parameters and results of the function as described in the
mentioned issue.
  • Loading branch information
OLUWAMUYIWA authored and zshipko committed Jan 22, 2024
1 parent 8c8e4a6 commit fbae853
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion runtime/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,18 @@ impl Plugin {
pub fn function_exists(&mut self, function: impl AsRef<str>) -> bool {
self.modules[MAIN_KEY]
.get_export(function.as_ref())
.map(|x| x.func().is_some())
.map(|x| {
if let Some(f) = x.func() {
let (params, mut results) = (f.params(), f.results());
match (params.len(), results.len()) {
(0, 1) => results.next() == Some(wasmtime::ValType::I32),
(0, 0) => true,
_ => false,
}
} else {
false
}
})
.unwrap_or(false)
}

Expand Down

0 comments on commit fbae853

Please sign in to comment.