Coverage Report

Created: 2024-11-19 11:03

/build/source/src/execution/function_ref.rs
Line
Count
Source (jump to first uncovered line)
1
use alloc::string::String;
2
use alloc::vec::Vec;
3
4
use crate::execution::{hooks::HookSet, value::InteropValueList, RuntimeInstance};
5
use crate::{RuntimeError, ValType, Value};
6
7
pub struct FunctionRef {
8
    pub(crate) module_name: String,
9
    pub(crate) function_name: String,
10
    pub(crate) module_index: usize,
11
    pub(crate) function_index: usize,
12
    /// If the function is exported from the module or not. This is used to determine if the function name - index
13
    /// mapping should be verified. The module name - index mapping is always verified.
14
    ///
15
    /// If this is set to false then the user must make sure that the function reference will still be valid when the
16
    /// function is called. This means that the module must not be unloaded.
17
    pub(crate) exported: bool,
18
}
19
20
impl FunctionRef {
21
0
    pub fn invoke<H: HookSet, Param: InteropValueList, Returns: InteropValueList>(
22
0
        &self,
23
0
        runtime: &mut RuntimeInstance<H>,
24
0
        params: Param,
25
0
    ) -> Result<Returns, RuntimeError> {
26
0
        runtime.invoke(self, params)
27
0
    }
28
29
1
    pub fn invoke_dynamic<H: HookSet>(
30
1
        &self,
31
1
        runtime: &mut RuntimeInstance<H>,
32
1
        params: Vec<Value>,
33
1
        ret_types: &[ValType],
34
1
    ) -> Result<Vec<Value>, RuntimeError> {
35
1
        runtime.invoke_dynamic(self, params, ret_types)
36
1
    }
37
}