mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-23 05:31:32 +00:00
Implement Instance::call
in terms of the exports API
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
backend::RunnableModule,
|
backend::RunnableModule,
|
||||||
backing::{ImportBacking, LocalBacking},
|
backing::{ImportBacking, LocalBacking},
|
||||||
error::{CallError, CallResult, ResolveError, ResolveResult, Result, RuntimeError},
|
error::{CallResult, ResolveError, ResolveResult, Result, RuntimeError},
|
||||||
export::{Context, Export, ExportIter, Exportable, FuncPointer},
|
export::{Context, Export, ExportIter, Exportable, FuncPointer},
|
||||||
global::Global,
|
global::Global,
|
||||||
import::{ImportObject, LikeNamespace},
|
import::{ImportObject, LikeNamespace},
|
||||||
@ -247,37 +247,8 @@ impl Instance {
|
|||||||
note = "Please use `let f: DynFunc = instance.exports.get(name)?; f.call(params)?;` instead"
|
note = "Please use `let f: DynFunc = instance.exports.get(name)?; f.call(params)?;` instead"
|
||||||
)]
|
)]
|
||||||
pub fn call(&self, name: &str, params: &[Value]) -> CallResult<Vec<Value>> {
|
pub fn call(&self, name: &str, params: &[Value]) -> CallResult<Vec<Value>> {
|
||||||
let export_index =
|
let func: DynFunc = self.exports.get(name)?;
|
||||||
self.module
|
func.call(params)
|
||||||
.info
|
|
||||||
.exports
|
|
||||||
.get(name)
|
|
||||||
.ok_or_else(|| ResolveError::ExportNotFound {
|
|
||||||
name: name.to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let func_index = if let ExportIndex::Func(func_index) = export_index {
|
|
||||||
*func_index
|
|
||||||
} else {
|
|
||||||
return Err(CallError::Resolve(ResolveError::ExportWrongType {
|
|
||||||
name: name.to_string(),
|
|
||||||
})
|
|
||||||
.into());
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut results = Vec::new();
|
|
||||||
|
|
||||||
call_func_with_index(
|
|
||||||
&self.module.info,
|
|
||||||
&**self.module.runnable_module,
|
|
||||||
&self.inner.import_backing,
|
|
||||||
self.inner.vmctx,
|
|
||||||
func_index,
|
|
||||||
params,
|
|
||||||
&mut results,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
Ok(results)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an immutable reference to the
|
/// Returns an immutable reference to the
|
||||||
|
Reference in New Issue
Block a user