| 183 | |
| 184 | #[test] |
| 185 | fn test_limits_memory_only() -> Result<()> { |
| 186 | let engine = Engine::default(); |
| 187 | let module = Module::new( |
| 188 | &engine, |
| 189 | r#"(module (memory (export "m") 0) (table (export "t") 0 funcref))"#, |
| 190 | )?; |
| 191 | |
| 192 | let mut store = Store::new( |
| 193 | &engine, |
| 194 | StoreLimitsBuilder::new() |
| 195 | .memory_size(10 * WASM_PAGE_SIZE) |
| 196 | .build(), |
| 197 | ); |
| 198 | store.limiter(|s| s as &mut dyn ResourceLimiter); |
| 199 | |
| 200 | let instance = Instance::new(&mut store, &module, &[])?; |
| 201 | |
| 202 | // Test instance exports and host objects hitting the limit |
| 203 | for memory in IntoIterator::into_iter([ |
| 204 | instance.get_memory(&mut store, "m").unwrap(), |
| 205 | Memory::new(&mut store, MemoryType::new(0, None))?, |
| 206 | ]) { |
| 207 | memory.grow(&mut store, 3)?; |
| 208 | memory.grow(&mut store, 5)?; |
| 209 | memory.grow(&mut store, 2)?; |
| 210 | |
| 211 | assert_eq!( |
| 212 | memory |
| 213 | .grow(&mut store, 1) |
| 214 | .map_err(|e| e.to_string()) |
| 215 | .unwrap_err(), |
| 216 | "failed to grow memory by `1`" |
| 217 | ); |
| 218 | } |
| 219 | |
| 220 | // Test instance exports and host objects *not* hitting the limit |
| 221 | for table in IntoIterator::into_iter([ |
| 222 | instance.get_table(&mut store, "t").unwrap(), |
| 223 | Table::new( |
| 224 | &mut store, |
| 225 | TableType::new(RefType::FUNCREF, 0, None), |
| 226 | Ref::Func(None), |
| 227 | )?, |
| 228 | ]) { |
| 229 | table.grow(&mut store, 2, Ref::Func(None))?; |
| 230 | table.grow(&mut store, 1, Ref::Func(None))?; |
| 231 | table.grow(&mut store, 2, Ref::Func(None))?; |
| 232 | table.grow(&mut store, 1, Ref::Func(None))?; |
| 233 | } |
| 234 | |
| 235 | Ok(()) |
| 236 | } |
| 237 | |
| 238 | #[test] |
| 239 | fn test_initial_memory_limits_exceeded() -> Result<()> { |