From 8403cc3411477eabfed49a5701e824eb4528d101 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 28 Feb 2019 18:19:04 +0200 Subject: [PATCH] Add a check if NotStartedModuleRef has a start function (#173) * Add a check if NotStartedModuleRef has a start function * Removed redundant doc comment Co-Authored-By: elichai --- src/module.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/module.rs b/src/module.rs index eff2151..8222e42 100644 --- a/src/module.rs +++ b/src/module.rs @@ -714,6 +714,13 @@ impl<'a> NotStartedModuleRef<'a> { } self.instance } + + /// Whether or not the module has a `start` function. + /// + /// Returns `true` if it has a `start` function. + pub fn has_start(&self) -> bool { + self.loaded_module.module().start_section().is_some() + } } fn eval_init_expr(init_expr: &InitExpr, module: &ModuleInstance) -> RuntimeValue { @@ -793,9 +800,9 @@ mod tests { (start $f)) "#, ); - ModuleInstance::new(&module_with_start, &ImportsBuilder::default()) - .unwrap() - .assert_no_start(); + let module = ModuleInstance::new(&module_with_start, &ImportsBuilder::default()).unwrap(); + assert!(!module.has_start()); + module.assert_no_start(); } #[test]