From a7e1775255d43100a95590e28ca07cf1104d8228 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 21:05:26 -0800 Subject: [PATCH] Added mocking back into instance --- src/webassembly/instance.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 3901988aa..243037f4b 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -121,9 +121,9 @@ pub struct InstanceOptions { pub isa: Box, } -// extern fn mock_fn() -> i32 { -// return 0; -// } +extern fn mock_fn() -> i32 { + return 0; +} impl Instance { pub const TABLES_OFFSET: usize = 0; // 0 on 64-bit | 0 on 32-bit @@ -165,19 +165,19 @@ impl Instance { for (module, field) in module.info.imported_funcs.iter() { let imported = import_object .get(&module.as_str(), &field.as_str()); - let function = match imported { + let function: &*const u8 = match imported { Some(ImportValue::Func(f)) => f, None => { - // if options.mock_missing_imports { - // debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); - // mock_fn as *const u8 - // } - // else { - return Err(ErrorKind::LinkError(format!( - "Imported function {}.{} was not provided in the import_functions", - module, field - ))); - // } + if options.mock_missing_imports { + debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); + &(mock_fn as *const u8) + } + else { + return Err(ErrorKind::LinkError(format!( + "Imported function {}.{} was not provided in the import_functions", + module, field + ))); + } }, other => panic!("Expected function import, received {:?}", other) };