mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-20 18:26:54 +00:00
func index in mapped error
This commit is contained in:
@ -312,9 +312,23 @@ impl ModuleInstanceInterface for ModuleInstance {
|
|||||||
let function_body = code_section.bodies().get(index as usize).ok_or(Error::Validation(format!("Missing body for function {}", index)))?;
|
let function_body = code_section.bodies().get(index as usize).ok_or(Error::Validation(format!("Missing body for function {}", index)))?;
|
||||||
let mut locals = function_type.params().to_vec();
|
let mut locals = function_type.params().to_vec();
|
||||||
locals.extend(function_body.locals().iter().flat_map(|l| repeat(l.value_type()).take(l.count() as usize)));
|
locals.extend(function_body.locals().iter().flat_map(|l| repeat(l.value_type()).take(l.count() as usize)));
|
||||||
let mut context = FunctionValidationContext::new(&self.module, &self.imports, &locals, DEFAULT_VALUE_STACK_LIMIT, DEFAULT_FRAME_STACK_LIMIT, &function_type);
|
let mut context = FunctionValidationContext::new(
|
||||||
|
&self.module,
|
||||||
|
&self.imports,
|
||||||
|
&locals,
|
||||||
|
DEFAULT_VALUE_STACK_LIMIT,
|
||||||
|
DEFAULT_FRAME_STACK_LIMIT,
|
||||||
|
&function_type);
|
||||||
|
|
||||||
let block_type = function_type.return_type().map(BlockType::Value).unwrap_or(BlockType::NoResult);
|
let block_type = function_type.return_type().map(BlockType::Value).unwrap_or(BlockType::NoResult);
|
||||||
Validator::validate_block(&mut context, false, block_type, function_body.code().elements(), Opcode::End)?;
|
Validator::validate_block(&mut context, false, block_type, function_body.code().elements(), Opcode::End)
|
||||||
|
.map_err(|e| {
|
||||||
|
if let Error::Validation(msg) = e {
|
||||||
|
Error::Validation(format!("Function #{} validation error: {}", index, msg))
|
||||||
|
} else {
|
||||||
|
e
|
||||||
|
}
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +495,14 @@ impl Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FunctionValidationContext<'a> {
|
impl<'a> FunctionValidationContext<'a> {
|
||||||
pub fn new(module: &'a Module, imports: &'a ModuleImports, locals: &'a [ValueType], value_stack_limit: usize, frame_stack_limit: usize, function: &FunctionType) -> Self {
|
pub fn new(
|
||||||
|
module: &'a Module,
|
||||||
|
imports: &'a ModuleImports,
|
||||||
|
locals: &'a [ValueType],
|
||||||
|
value_stack_limit: usize,
|
||||||
|
frame_stack_limit: usize,
|
||||||
|
function: &FunctionType,
|
||||||
|
) -> Self {
|
||||||
FunctionValidationContext {
|
FunctionValidationContext {
|
||||||
module: module,
|
module: module,
|
||||||
imports: imports,
|
imports: imports,
|
||||||
|
Reference in New Issue
Block a user