mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-21 02:31:51 +00:00
Add table validation.
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
use elements::{Module, ResizableLimits, MemoryType};
|
use elements::{Module, ResizableLimits, MemoryType, TableType};
|
||||||
|
|
||||||
pub struct Error(pub String);
|
pub struct Error(pub String);
|
||||||
|
|
||||||
@ -11,6 +11,14 @@ pub fn validate_module(module: &Module) -> Result<(), Error> {
|
|||||||
.collect::<Result<_, _>>()?
|
.collect::<Result<_, _>>()?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(table_section) = module.table_section() {
|
||||||
|
table_section
|
||||||
|
.entries()
|
||||||
|
.iter()
|
||||||
|
.map(TableType::validate)
|
||||||
|
.collect::<Result<_, _>>()?
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,6 +43,12 @@ impl MemoryType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TableType {
|
||||||
|
fn validate(&self) -> Result<(), Error> {
|
||||||
|
self.limits().validate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::validate_module;
|
use super::validate_module;
|
||||||
@ -69,7 +83,7 @@ mod tests {
|
|||||||
.build();
|
.build();
|
||||||
assert!(validate_module(&m).is_ok());
|
assert!(validate_module(&m).is_ok());
|
||||||
|
|
||||||
// mod is always valid without max.
|
// mem is always valid without max.
|
||||||
let m = module()
|
let m = module()
|
||||||
.memory()
|
.memory()
|
||||||
.with_min(10)
|
.with_min(10)
|
||||||
@ -77,4 +91,33 @@ mod tests {
|
|||||||
.build();
|
.build();
|
||||||
assert!(validate_module(&m).is_ok());
|
assert!(validate_module(&m).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_limits() {
|
||||||
|
// min > max
|
||||||
|
let m = module()
|
||||||
|
.table()
|
||||||
|
.with_min(10)
|
||||||
|
.with_max(Some(9))
|
||||||
|
.build()
|
||||||
|
.build();
|
||||||
|
assert!(validate_module(&m).is_err());
|
||||||
|
|
||||||
|
// min = max
|
||||||
|
let m = module()
|
||||||
|
.table()
|
||||||
|
.with_min(10)
|
||||||
|
.with_max(Some(10))
|
||||||
|
.build()
|
||||||
|
.build();
|
||||||
|
assert!(validate_module(&m).is_ok());
|
||||||
|
|
||||||
|
// table is always valid without max.
|
||||||
|
let m = module()
|
||||||
|
.table()
|
||||||
|
.with_min(10)
|
||||||
|
.build()
|
||||||
|
.build();
|
||||||
|
assert!(validate_module(&m).is_ok());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user