Skip to content

Commit

Permalink
js::module: add conversion from JsValue for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Twey committed Oct 11, 2024
1 parent c8d056f commit 8ba7a44
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/api/src/js/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use bytes::Bytes;
use js_sys::{Reflect, Uint8Array, WebAssembly};
use std::path::Path;
use tracing::{debug, warn};
use wasm_bindgen::JsValue;
use wasm_bindgen::{JsCast as _, JsValue};
use wasmer_types::{
CompileError, DeserializeError, ExportsIterator, ExternType, FunctionType, GlobalType,
ImportsIterator, MemoryType, ModuleInfo, Mutability, Pages, SerializeError, TableType, Type,
Expand Down Expand Up @@ -57,6 +57,20 @@ impl From<Module> for JsValue {
}
}

impl TryFrom<JsValue> for Module {
type Error = JsValue;

fn try_from(value: JsValue) -> Result<Self, Self::Error> {
Ok(Self {
module: JsHandle::new(value.dyn_into::<WebAssembly::Module>()?),
type_hints: None,
name: None,
#[cfg(feature = "js-serializable-module")]
raw_bytes: None,
})
}
}

impl Module {
pub(crate) fn from_binary(
_engine: &impl AsEngineRef,
Expand Down

0 comments on commit 8ba7a44

Please sign in to comment.