Coverage Report

Created: 2026-07-29 12:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/source/src/execution/runtime_structure/table_instances.rs
Line
Count
Source
1
use alloc::{vec, vec::Vec};
2
3
use crate::{core::utils::ToUsizeExt, Limits, Ref, RuntimeError, TableType};
4
5
#[derive(Debug)]
6
pub struct TableInst {
7
    pub ty: TableType,
8
    pub elem: Vec<Ref>,
9
}
10
11
impl TableInst {
12
444
    pub fn len(&self) -> usize {
13
444
        self.elem.len()
14
444
    }
15
16
    /// <https://webassembly.github.io/spec/core/exec/modules.html#growing-tables>
17
72
    pub fn grow(&mut self, n: u32, reff: Ref) -> Result<(), RuntimeError> {
18
72
        let 
len69
= n
19
72
            .checked_add(self.elem.len() as u32)
20
72
            .ok_or(RuntimeError::TableGrowOverflowed)
?3
;
21
22
        // roughly matches step 4,5,6
23
        // checks limits_prime.valid() for limits_prime := { min: len, max: self.ty.lim.max }
24
        // https://webassembly.github.io/spec/core/valid/types.html#limits
25
69
        if self.ty.lim.max.is_some_and(|max| 
len39
>
max39
) {
26
11
            return Err(RuntimeError::TableGrowExceededLimit);
27
58
        }
28
29
58
        let limits_prime = Limits {
30
58
            min: len,
31
58
            max: self.ty.lim.max,
32
58
        };
33
34
58
        self.elem.extend(vec![reff; n.into_usize()]);
35
36
58
        self.ty.lim = limits_prime;
37
58
        Ok(())
38
72
    }
39
}