mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 22:58:18 +00:00
Improved naming
This commit is contained in:
@@ -1,38 +1,26 @@
|
|||||||
use crate::js::{Export, ExternType, Module, NamedResolver};
|
use crate::js::{Export, ExternType, Module, NamedResolver};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// All of the import data used when instantiating.
|
/// This struct is used in case you want to create an `Instance`
|
||||||
///
|
/// of a `Module` with imports that are provided directly from
|
||||||
/// It's suggested that you use the [`imports!`] macro
|
/// Javascript with a JS Object.
|
||||||
/// instead of creating an `ImportObject` by hand.
|
|
||||||
///
|
|
||||||
/// [`imports!`]: macro.imports.html
|
|
||||||
///
|
|
||||||
/// # Usage:
|
|
||||||
/// ```ignore
|
|
||||||
/// use wasmer::{Exports, ImportObject, Function};
|
|
||||||
///
|
|
||||||
/// let mut import_object = ImportObject::new();
|
|
||||||
/// let mut env = Exports::new();
|
|
||||||
///
|
|
||||||
/// env.insert("foo", Function::new_native(foo));
|
|
||||||
/// import_object.register("env", env);
|
|
||||||
///
|
|
||||||
/// fn foo(n: i32) -> i32 {
|
|
||||||
/// n
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct JSObjectResolver {
|
pub struct JsImportObject {
|
||||||
module_imports: HashMap<(String, String), ExternType>,
|
module_imports: HashMap<(String, String), ExternType>,
|
||||||
object: js_sys::Object,
|
object: js_sys::Object,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for JSObjectResolver {}
|
unsafe impl Send for JsImportObject {}
|
||||||
unsafe impl Sync for JSObjectResolver {}
|
unsafe impl Sync for JsImportObject {}
|
||||||
|
|
||||||
impl JSObjectResolver {
|
impl JsImportObject {
|
||||||
/// Create a new `ImportObject`.
|
/// Create a new `JsImportObject`.
|
||||||
|
///
|
||||||
|
/// # Usage
|
||||||
|
/// ```ignore
|
||||||
|
/// # use wasmer::JsImportObject;
|
||||||
|
/// let import_object = JsImportObject::new(&module, js_object);
|
||||||
|
/// ```
|
||||||
pub fn new(module: &Module, object: js_sys::Object) -> Self {
|
pub fn new(module: &Module, object: js_sys::Object) -> Self {
|
||||||
let module_imports = module
|
let module_imports = module
|
||||||
.imports()
|
.imports()
|
||||||
@@ -53,8 +41,8 @@ impl JSObjectResolver {
|
|||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// # use wasmer::{ImportObject, Instance, Namespace};
|
/// # use wasmer::JsImportObject;
|
||||||
/// let mut import_object = ImportObject::new();
|
/// let import_object = JsImportObject::new(&module, js_object);
|
||||||
/// import_object.get_export("module", "name");
|
/// import_object.get_export("module", "name");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get_export(&self, module: &str, name: &str) -> Option<Export> {
|
pub fn get_export(&self, module: &str, name: &str) -> Option<Export> {
|
||||||
@@ -70,13 +58,13 @@ impl JSObjectResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Into<js_sys::Object> for JSObjectResolver {
|
impl Into<js_sys::Object> for JsImportObject {
|
||||||
fn into(self) -> js_sys::Object {
|
fn into(self) -> js_sys::Object {
|
||||||
self.object
|
self.object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NamedResolver for JSObjectResolver {
|
impl NamedResolver for JsImportObject {
|
||||||
fn resolve_by_name(&self, module: &str, name: &str) -> Option<Export> {
|
fn resolve_by_name(&self, module: &str, name: &str) -> Option<Export> {
|
||||||
self.get_export(module, name)
|
self.get_export(module, name)
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ mod exports;
|
|||||||
mod externals;
|
mod externals;
|
||||||
mod import_object;
|
mod import_object;
|
||||||
mod instance;
|
mod instance;
|
||||||
mod jsobjectresolver;
|
mod js_import_object;
|
||||||
mod module;
|
mod module;
|
||||||
#[cfg(feature = "wasm-types-polyfill")]
|
#[cfg(feature = "wasm-types-polyfill")]
|
||||||
mod module_info_polyfill;
|
mod module_info_polyfill;
|
||||||
@@ -59,7 +59,7 @@ pub use crate::js::externals::{
|
|||||||
};
|
};
|
||||||
pub use crate::js::import_object::{ImportObject, ImportObjectIterator, LikeNamespace};
|
pub use crate::js::import_object::{ImportObject, ImportObjectIterator, LikeNamespace};
|
||||||
pub use crate::js::instance::{Instance, InstantiationError};
|
pub use crate::js::instance::{Instance, InstantiationError};
|
||||||
pub use crate::js::jsobjectresolver::JSObjectResolver;
|
pub use crate::js::js_import_object::JsImportObject;
|
||||||
pub use crate::js::module::{Module, ModuleTypeHints};
|
pub use crate::js::module::{Module, ModuleTypeHints};
|
||||||
pub use crate::js::native::NativeFunc;
|
pub use crate::js::native::NativeFunc;
|
||||||
pub use crate::js::ptr::{Array, Item, WasmPtr};
|
pub use crate::js::ptr::{Array, Item, WasmPtr};
|
||||||
|
|||||||
Reference in New Issue
Block a user