Fix emscripten table assertion panic

This commit is contained in:
Brandon Fish 2019-08-16 09:12:46 -06:00
parent 6e8baf3c89
commit 03cabce2d5
3 changed files with 10 additions and 11 deletions

View File

@ -436,7 +436,7 @@ pub struct EmscriptenGlobals {
}
impl EmscriptenGlobals {
pub fn new(module: &Module /*, static_bump: u32 */) -> Self {
pub fn new(module: &Module /*, static_bump: u32 */) -> Result<Self, String> {
let mut use_old_abort_on_cannot_grow_memory = false;
for (
index,
@ -458,7 +458,7 @@ impl EmscriptenGlobals {
}
}
let (table_min, table_max) = get_emscripten_table_size(&module);
let (table_min, table_max) = get_emscripten_table_size(&module)?;
let (memory_min, memory_max, shared) = get_emscripten_memory_size(&module);
// Memory initialization
@ -530,14 +530,14 @@ impl EmscriptenGlobals {
}
}
Self {
Ok(Self {
data,
memory,
table,
memory_min,
memory_max,
null_func_names,
}
})
}
}

View File

@ -33,13 +33,12 @@ pub fn is_emscripten_module(module: &Module) -> bool {
false
}
pub fn get_emscripten_table_size(module: &Module) -> (u32, Option<u32>) {
assert!(
module.info().imported_tables.len() > 0,
"Emscripten requires at least one imported table"
);
pub fn get_emscripten_table_size(module: &Module) -> Result<(u32, Option<u32>), String> {
if module.info().imported_tables.len() == 0 {
return Err("Emscripten requires at least one imported table".to_string());
}
let (_, table) = &module.info().imported_tables[ImportedTableIndex::new(0)];
(table.minimum, table.maximum)
Ok((table.minimum, table.maximum))
}
pub fn get_emscripten_memory_size(module: &Module) -> (Pages, Option<Pages>, bool) {

View File

@ -544,7 +544,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
// TODO: refactor this
if wasmer_emscripten::is_emscripten_module(&module) {
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module);
let mut emscripten_globals = wasmer_emscripten::EmscriptenGlobals::new(&module)?;
let import_object = wasmer_emscripten::generate_emscripten_env(&mut emscripten_globals);
let mut instance = module
.instantiate(&import_object)