(&self)
| 3232 | } |
| 3233 | |
| 3234 | fn validate(&self) -> Result<()> { |
| 3235 | if self |
| 3236 | .ty |
| 3237 | .limits |
| 3238 | .max |
| 3239 | .map_or(false, |max| max < self.ty.limits.min) |
| 3240 | { |
| 3241 | bail!("maximum page size cannot be smaller than the minimum page size"); |
| 3242 | } |
| 3243 | |
| 3244 | match self.ty.page_size_log2 { |
| 3245 | 0 | Memory::DEFAULT_PAGE_SIZE_LOG2 => {} |
| 3246 | x => bail!( |
| 3247 | "page size must be 2**16 or 2**0, but was given 2**{x}; note \ |
| 3248 | that future Wasm extensions might allow any power of two page \ |
| 3249 | size, but only 2**16 and 2**0 are currently valid", |
| 3250 | ), |
| 3251 | } |
| 3252 | |
| 3253 | if self.ty.shared && self.ty.limits.max.is_none() { |
| 3254 | bail!("shared memories must have a maximum size"); |
| 3255 | } |
| 3256 | |
| 3257 | let absolute_max = self.ty.max_size_based_on_index_type(); |
| 3258 | let min = self |
| 3259 | .ty |
| 3260 | .minimum_byte_size() |
| 3261 | .context("memory's minimum byte size must fit in a u64")?; |
| 3262 | if min > absolute_max { |
| 3263 | bail!("minimum size is too large for this memory type's index type"); |
| 3264 | } |
| 3265 | if self |
| 3266 | .ty |
| 3267 | .maximum_byte_size() |
| 3268 | .map_or(false, |max| max > absolute_max) |
| 3269 | { |
| 3270 | bail!("maximum size is too large for this memory type's index type"); |
| 3271 | } |
| 3272 | |
| 3273 | Ok(()) |
| 3274 | } |
| 3275 | |
| 3276 | /// Set the minimum size, in units of pages, for the memory type being |
| 3277 | /// built. |
no test coverage detected