Browse Source

[lightbeam] replace asserts by Errors in module.rs / translate_only (#713)

* replace assert by Errors

* add better errors message module.rs
pull/730/head
Patrick Ventuzelo 5 years ago
committed by Dan Gohman
parent
commit
d1866f0e09
  1. 24
      crates/lightbeam/src/module.rs

24
crates/lightbeam/src/module.rs

@ -7,7 +7,7 @@ use cranelift_codegen::{
isa,
};
use memoffset::offset_of;
use more_asserts::assert_le;
use std::{convert::TryInto, mem};
use thiserror::Error;
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
@ -563,15 +563,19 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
let memories = section.get_memory_section_reader()?;
let mem = translate_sections::memory(memories)?;
assert_le!(
mem.len(),
1,
"Multiple memory sections not yet unimplemented"
);
if mem.len() > 1 {
return Err(Error::Input(
"Multiple memory sections not yet implemented".to_string(),
));
}
if !mem.is_empty() {
let mem = mem[0];
assert_eq!(Some(mem.limits.initial), mem.limits.maximum);
if Some(mem.limits.initial) != mem.limits.maximum {
return Err(Error::Input(
"Custom memory limits not supported in lightbeam".to_string(),
));
}
output.memory = Some(mem);
}
@ -642,7 +646,11 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
translate_sections::data(data)?;
}
assert!(reader.eof());
if !reader.eof() {
return Err(Error::Input(
"Unexpected data found after the end of the module".to_string(),
));
}
Ok(output)
}

Loading…
Cancel
Save