Skip to content

Commit

Permalink
Fix all errors up to the last one
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Aug 26, 2022
1 parent 42cbe14 commit 14ddcfd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
4 changes: 4 additions & 0 deletions lib/api/src/js/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ pub enum InstantiationError {
/// A generic error occured while invoking API functions
#[cfg_attr(feature = "std", error(transparent))]
Wasm(WasmError),

/// Insufficient resources available for execution.
#[cfg_attr(feature = "std", error("Can't get {0} from the instance exports"))]
NotInExports(String),
}

impl From<WasmError> for InstantiationError {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/js/imports.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! The import module contains the implementation data structures and helper functions used to
//! manipulate and access a wasm module's imports including memories, tables, globals, and
//! functions.
use crate::js::error::{InstantiationError, LinkError};
use crate::js::error::LinkError;
use crate::js::exports::Exports;
use crate::js::module::Module;
use crate::js::store::AsStoreRef;
Expand Down
29 changes: 6 additions & 23 deletions lib/api/src/js/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,11 @@ impl Instance {
module: &Module,
externs: &[Extern],
) -> Result<Self, InstantiationError> {
let imports = externs.to_vec();
let mut handle = module.instantiate(store, &imports)?;
let exports = module
.exports()
.map(|export| {
let name = export.name().to_string();
let export = handle.lookup(&name).expect("export");
let extern_ = Extern::from_vm_extern(store, export);
(name, extern_)
})
.collect::<Exports>();

let instance = Self {
_handle: StoreHandle::new(store.objects_mut(), handle),
module: module.clone(),
exports,
};

Ok(instance)
let mut imports = Imports::new();
for (import_ty, extern_ty) in module.imports().zip(externs.iter()) {
imports.define(import_ty.module(), import_ty.name(), extern_ty.clone());
}
Self::new(store, module, &imports)
}

/// Creates a Wasmer `Instance` from a Wasmer `Module` and a WebAssembly Instance
Expand All @@ -134,10 +120,7 @@ impl Instance {
let extern_type = export_type.ty().clone();
let js_export =
js_sys::Reflect::get(&instance_exports, &name.into()).map_err(|_e| {
InstantiationError::Link(format!(
"Can't get {} from the instance exports",
&name
))
InstantiationError::NotInExports(name.to_string())
})?;
let export: Export =
Export::from_js_value(js_export, &mut store, extern_type)?.into();
Expand Down

0 comments on commit 14ddcfd

Please sign in to comment.