//! Support for a calling of an imported function. use crate::data_structures::wasm::DefinedFuncIndex; use crate::data_structures::PrimaryMap; use crate::runtime::Store; use anyhow::Result; use std::any::Any; use std::cell::{RefCell, RefMut}; use std::collections::{HashMap, HashSet}; use std::rc::Rc; use wasmtime_environ::Module; use wasmtime_runtime::{Imports, InstanceHandle, VMFunctionBody}; pub(crate) fn create_handle( module: Module, signature_registry: Option>, finished_functions: PrimaryMap, state: Box, ) -> Result { let global_exports: Rc>>> = Rc::new(RefCell::new(HashMap::new())); let imports = Imports::new( HashSet::new(), PrimaryMap::new(), PrimaryMap::new(), PrimaryMap::new(), PrimaryMap::new(), ); let data_initializers = Vec::new(); // Compute indices into the shared signature table. let signatures = signature_registry .and_then(|mut signature_registry| { Some( module .signatures .values() .map(|sig| signature_registry.register_wasmtime_signature(sig)) .collect::>(), ) }) .unwrap_or_else(|| PrimaryMap::new()); Ok(InstanceHandle::new( Rc::new(module), global_exports, finished_functions.into_boxed_slice(), imports, &data_initializers, signatures.into_boxed_slice(), None, state, ) .expect("instance")) }