From 8ba7a446b9ab59c38baf26ff896423eb32d66ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?James=20=E2=80=98Twey=E2=80=99=20Kay?= Date: Fri, 11 Oct 2024 16:47:45 +0100 Subject: [PATCH] `js::module`: add conversion from `JsValue` for modules --- lib/api/src/js/module.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/api/src/js/module.rs b/lib/api/src/js/module.rs index adc61d6b08b..4ab0dccc7f1 100644 --- a/lib/api/src/js/module.rs +++ b/lib/api/src/js/module.rs @@ -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, @@ -57,6 +57,20 @@ impl From for JsValue { } } +impl TryFrom for Module { + type Error = JsValue; + + fn try_from(value: JsValue) -> Result { + Ok(Self { + module: JsHandle::new(value.dyn_into::()?), + type_hints: None, + name: None, + #[cfg(feature = "js-serializable-module")] + raw_bytes: None, + }) + } +} + impl Module { pub(crate) fn from_binary( _engine: &impl AsEngineRef,