Remove unused format convertion in check_function_args
This commit is contained in:
parent
2c8783ad8b
commit
611cddc97b
|
@ -1,7 +1,7 @@
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use parity_wasm::elements::Local;
|
use parity_wasm::elements::Local;
|
||||||
use {Trap, TrapKind, Signature};
|
use {Trap, Signature};
|
||||||
use host::Externals;
|
use host::Externals;
|
||||||
use runner::{check_function_args, Interpreter, InterpreterState};
|
use runner::{check_function_args, Interpreter, InterpreterState};
|
||||||
use value::RuntimeValue;
|
use value::RuntimeValue;
|
||||||
|
@ -142,7 +142,7 @@ impl FuncInstance {
|
||||||
args: &[RuntimeValue],
|
args: &[RuntimeValue],
|
||||||
externals: &mut E,
|
externals: &mut E,
|
||||||
) -> Result<Option<RuntimeValue>, Trap> {
|
) -> Result<Option<RuntimeValue>, Trap> {
|
||||||
check_function_args(func.signature(), &args).map_err(|_| TrapKind::UnexpectedSignature)?;
|
check_function_args(func.signature(), &args)?;
|
||||||
match *func.as_internal() {
|
match *func.as_internal() {
|
||||||
FuncInstanceInternal::Internal { .. } => {
|
FuncInstanceInternal::Internal { .. } => {
|
||||||
let mut interpreter = Interpreter::new(func, args)?;
|
let mut interpreter = Interpreter::new(func, args)?;
|
||||||
|
@ -173,7 +173,7 @@ impl FuncInstance {
|
||||||
func: &FuncRef,
|
func: &FuncRef,
|
||||||
args: &'args [RuntimeValue],
|
args: &'args [RuntimeValue],
|
||||||
) -> Result<FuncInvocation<'args>, Trap> {
|
) -> Result<FuncInvocation<'args>, Trap> {
|
||||||
check_function_args(func.signature(), &args).map_err(|_| TrapKind::UnexpectedSignature)?;
|
check_function_args(func.signature(), &args)?;
|
||||||
match *func.as_internal() {
|
match *func.as_internal() {
|
||||||
FuncInstanceInternal::Internal { .. } => {
|
FuncInstanceInternal::Internal { .. } => {
|
||||||
let interpreter = Interpreter::new(func, args)?;
|
let interpreter = Interpreter::new(func, args)?;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use runner::check_function_args;
|
|
||||||
use Trap;
|
use Trap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{u32, usize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::repeat;
|
use std::iter::repeat;
|
||||||
use parity_wasm::elements::Local;
|
use parity_wasm::elements::Local;
|
||||||
use {Error, Trap, TrapKind, Signature};
|
use {Trap, TrapKind, Signature};
|
||||||
use module::ModuleRef;
|
use module::ModuleRef;
|
||||||
use memory::MemoryRef;
|
use memory::MemoryRef;
|
||||||
use func::{FuncRef, FuncInstance, FuncInstanceInternal};
|
use func::{FuncRef, FuncInstance, FuncInstanceInternal};
|
||||||
|
@ -1158,26 +1158,20 @@ fn prepare_function_args(
|
||||||
args
|
args
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_function_args(signature: &Signature, args: &[RuntimeValue]) -> Result<(), Error> {
|
pub fn check_function_args(signature: &Signature, args: &[RuntimeValue]) -> Result<(), Trap> {
|
||||||
if signature.params().len() != args.len() {
|
if signature.params().len() != args.len() {
|
||||||
return Err(
|
return Err(
|
||||||
Error::Function(
|
TrapKind::UnexpectedSignature.into()
|
||||||
format!(
|
|
||||||
"not enough arguments, given {} but expected: {}",
|
|
||||||
args.len(),
|
|
||||||
signature.params().len(),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
signature.params().iter().cloned().zip(args).map(|(expected_type, param_value)| {
|
signature.params().iter().cloned().zip(args).map(|(expected_type, param_value)| {
|
||||||
let actual_type = param_value.value_type();
|
let actual_type = param_value.value_type();
|
||||||
if actual_type != expected_type {
|
if actual_type != expected_type {
|
||||||
return Err(Error::Function(format!("invalid parameter type {:?} when expected {:?}", actual_type, expected_type)));
|
return Err(TrapKind::UnexpectedSignature.into());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}).collect::<Result<Vec<_>, _>>()?;
|
}).collect::<Result<Vec<_>, Trap>>()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue