mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Trying to fix lint issues
This commit is contained in:
@@ -155,7 +155,6 @@ impl From<(JsValue, ExternType)> for Export {
|
||||
panic!("Extern type doesn't match js value type");
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
4
lib/js-api/src/externals/function.rs
vendored
4
lib/js-api/src/externals/function.rs
vendored
@@ -180,7 +180,7 @@ impl Function {
|
||||
.enumerate()
|
||||
.map(|(i, param)| param_from_js(param, &args.get(i as u32)))
|
||||
.collect::<Vec<_>>();
|
||||
let results = func(&wasm_arguments)?;
|
||||
let _results = func(&wasm_arguments)?;
|
||||
Ok(())
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<(), JsValue>>)
|
||||
@@ -209,7 +209,6 @@ impl Function {
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<Array, JsValue>>)
|
||||
.into_js_value(),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
let dyn_func =
|
||||
@@ -322,7 +321,6 @@ impl Function {
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<Array, JsValue>>)
|
||||
.into_js_value(),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
|
||||
let dyn_func =
|
||||
|
||||
34
lib/js-api/src/externals/memory.rs
vendored
34
lib/js-api/src/externals/memory.rs
vendored
@@ -140,8 +140,7 @@ impl Memory {
|
||||
/// modify the memory contents in any way including by calling a wasm
|
||||
/// function that writes to the memory or by resizing the memory.
|
||||
pub unsafe fn data_unchecked(&self) -> &[u8] {
|
||||
unimplemented!();
|
||||
// self.data_unchecked_mut()
|
||||
unimplemented!("direct data pointer access is not possible in js");
|
||||
}
|
||||
|
||||
/// Retrieve a mutable slice of the memory contents.
|
||||
@@ -155,18 +154,12 @@ impl Memory {
|
||||
/// by resizing this Memory.
|
||||
#[allow(clippy::mut_from_ref)]
|
||||
pub unsafe fn data_unchecked_mut(&self) -> &mut [u8] {
|
||||
unimplemented!();
|
||||
// let definition = self.vm_memory.from.vmmemory();
|
||||
// let def = definition.as_ref();
|
||||
// slice::from_raw_parts_mut(def.base, def.current_length.try_into().unwrap())
|
||||
unimplemented!("direct data pointer access is not possible in js");
|
||||
}
|
||||
|
||||
/// Returns the pointer to the raw bytes of the `Memory`.
|
||||
pub fn data_ptr(&self) -> *mut u8 {
|
||||
unimplemented!();
|
||||
// let definition = self.vm_memory.from.vmmemory();
|
||||
// let def = unsafe { definition.as_ref() };
|
||||
// def.base
|
||||
unimplemented!("direct data pointer access is not possible in js");
|
||||
}
|
||||
|
||||
/// Returns the size (in bytes) of the `Memory`.
|
||||
@@ -176,8 +169,6 @@ impl Memory {
|
||||
.as_f64()
|
||||
.unwrap() as u64;
|
||||
return bytes;
|
||||
// let def = unsafe { definition.as_ref() };
|
||||
// def.current_length.into()
|
||||
}
|
||||
|
||||
/// Returns the size (in [`Pages`]) of the `Memory`.
|
||||
@@ -198,7 +189,6 @@ impl Memory {
|
||||
.as_f64()
|
||||
.unwrap() as u64;
|
||||
Bytes(bytes as usize).try_into().unwrap()
|
||||
// self.vm_memory.from.size()
|
||||
}
|
||||
|
||||
/// Grow memory by the specified amount of WebAssembly [`Pages`] and return
|
||||
@@ -283,11 +273,6 @@ impl Memory {
|
||||
/// ```
|
||||
pub fn view<T: ValueType>(&self) -> MemoryView<T> {
|
||||
unimplemented!();
|
||||
// let base = self.data_ptr();
|
||||
|
||||
// let length = self.size().bytes().0 / std::mem::size_of::<T>();
|
||||
|
||||
// unsafe { MemoryView::new(base as _, length as u32) }
|
||||
}
|
||||
|
||||
/// example view
|
||||
@@ -319,19 +304,6 @@ impl Memory {
|
||||
}
|
||||
}
|
||||
|
||||
// impl Clone for Memory {
|
||||
// fn clone(&self) -> Self {
|
||||
// unimplemented!();
|
||||
// // let mut vm_memory = self.vm_memory.clone();
|
||||
// // vm_memory.upgrade_instance_ref().unwrap();
|
||||
|
||||
// // Self {
|
||||
// // store: self.store.clone(),
|
||||
// // vm_memory,
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
impl<'a> Exportable<'a> for Memory {
|
||||
fn to_export(&self) -> Export {
|
||||
Export::Memory(self.vm_memory.clone())
|
||||
|
||||
@@ -133,7 +133,7 @@ impl Module {
|
||||
}
|
||||
|
||||
/// Creates a new WebAssembly module from a file path.
|
||||
pub fn from_file(store: &Store, _file: impl AsRef<Path>) -> Result<Self, IoCompileError> {
|
||||
pub fn from_file(_store: &Store, _file: impl AsRef<Path>) -> Result<Self, IoCompileError> {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ impl Module {
|
||||
/// This validation is normally pretty fast and checks the enabled
|
||||
/// WebAssembly features in the Store Engine to assure deterministic
|
||||
/// validation of the Module.
|
||||
pub fn validate(store: &Store, binary: &[u8]) -> Result<(), CompileError> {
|
||||
pub fn validate(_store: &Store, binary: &[u8]) -> Result<(), CompileError> {
|
||||
let js_bytes = unsafe { Uint8Array::view(binary) };
|
||||
match WebAssembly::validate(&js_bytes.into()) {
|
||||
Ok(true) => Ok(()),
|
||||
|
||||
@@ -69,7 +69,6 @@ fn test_exported_function() {
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
#[ignore] // We ignore because in old versions of Node, only single return values are supported
|
||||
fn test_imported_function_dynamic() {
|
||||
let store = Store::default();
|
||||
let mut module = Module::new(
|
||||
@@ -77,32 +76,22 @@ fn test_imported_function_dynamic() {
|
||||
br#"
|
||||
(module
|
||||
(func $imported (import "env" "imported") (param i32) (result i32))
|
||||
(func $imported_multivalue (import "env" "imported_multivalue") (param i32 i32) (result i32 i32))
|
||||
(func (export "exported") (param i32) (result i32)
|
||||
(call $imported (local.get 0))
|
||||
)
|
||||
(func (export "exported_multivalue") (param i32 i32) (result i32 i32)
|
||||
(call $imported_multivalue (local.get 0) (local.get 1))
|
||||
)
|
||||
)
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
module.set_type_hints(ModuleTypeHints {
|
||||
imports: vec![
|
||||
ExternType::Function(FunctionType::new(vec![Type::I32], vec![Type::I32])),
|
||||
ExternType::Function(FunctionType::new(
|
||||
vec![Type::I32, Type::I32],
|
||||
vec![Type::I32, Type::I32],
|
||||
)),
|
||||
],
|
||||
exports: vec![
|
||||
ExternType::Function(FunctionType::new(vec![Type::I32], vec![Type::I32])),
|
||||
ExternType::Function(FunctionType::new(
|
||||
vec![Type::I32, Type::I32],
|
||||
vec![Type::I32, Type::I32],
|
||||
)),
|
||||
],
|
||||
imports: vec![ExternType::Function(FunctionType::new(
|
||||
vec![Type::I32],
|
||||
vec![Type::I32],
|
||||
))],
|
||||
exports: vec![ExternType::Function(FunctionType::new(
|
||||
vec![Type::I32],
|
||||
vec![Type::I32],
|
||||
))],
|
||||
});
|
||||
|
||||
let imported_signature = FunctionType::new(vec![Type::I32], vec![Type::I32]);
|
||||
@@ -125,7 +114,6 @@ fn test_imported_function_dynamic() {
|
||||
let import_object = imports! {
|
||||
"env" => {
|
||||
"imported" => imported,
|
||||
"imported_multivalue" => imported_multivalue,
|
||||
}
|
||||
};
|
||||
let instance = Instance::new(&module, &import_object).unwrap();
|
||||
@@ -134,19 +122,68 @@ fn test_imported_function_dynamic() {
|
||||
|
||||
let expected = vec![Val::I32(6)].into_boxed_slice();
|
||||
assert_eq!(exported.call(&[Val::I32(3)]), Ok(expected));
|
||||
|
||||
let exported_multivalue = instance
|
||||
.exports
|
||||
.get_function("exported_multivalue")
|
||||
.unwrap();
|
||||
|
||||
let expected = vec![Val::I32(2), Val::I32(3)].into_boxed_slice();
|
||||
assert_eq!(
|
||||
exported_multivalue.call(&[Val::I32(3), Val::I32(2)]),
|
||||
Ok(expected)
|
||||
);
|
||||
}
|
||||
|
||||
// We comment it for now because in old versions of Node, only single return values are supported
|
||||
|
||||
// #[wasm_bindgen_test]
|
||||
// fn test_imported_function_dynamic_multivalue() {
|
||||
// let store = Store::default();
|
||||
// let mut module = Module::new(
|
||||
// &store,
|
||||
// br#"
|
||||
// (module
|
||||
// (func $multivalue (import "env" "multivalue") (param i32 i32) (result i32 i32))
|
||||
// (func (export "multivalue") (param i32 i32) (result i32 i32)
|
||||
// (call $multivalue (local.get 0) (local.get 1))
|
||||
// )
|
||||
// )
|
||||
// "#,
|
||||
// )
|
||||
// .unwrap();
|
||||
// module.set_type_hints(ModuleTypeHints {
|
||||
// imports: vec![
|
||||
// ExternType::Function(FunctionType::new(
|
||||
// vec![Type::I32, Type::I32],
|
||||
// vec![Type::I32, Type::I32],
|
||||
// )),
|
||||
// ],
|
||||
// exports: vec![
|
||||
// ExternType::Function(FunctionType::new(
|
||||
// vec![Type::I32, Type::I32],
|
||||
// vec![Type::I32, Type::I32],
|
||||
// )),
|
||||
// ],
|
||||
// });
|
||||
|
||||
// let multivalue_signature =
|
||||
// FunctionType::new(vec![Type::I32, Type::I32], vec![Type::I32, Type::I32]);
|
||||
// let multivalue = Function::new(&store, &multivalue_signature, |args| {
|
||||
// println!("Calling `imported`...");
|
||||
// // let result = args[0].unwrap_i32() * ;
|
||||
// // println!("Result of `imported`: {:?}", result);
|
||||
// Ok(vec![args[1].clone(), args[0].clone()])
|
||||
// });
|
||||
|
||||
// let import_object = imports! {
|
||||
// "env" => {
|
||||
// "multivalue" => multivalue,
|
||||
// }
|
||||
// };
|
||||
// let instance = Instance::new(&module, &import_object).unwrap();
|
||||
|
||||
// let exported_multivalue = instance
|
||||
// .exports
|
||||
// .get_function("multivalue")
|
||||
// .unwrap();
|
||||
|
||||
// let expected = vec![Val::I32(2), Val::I32(3)].into_boxed_slice();
|
||||
// assert_eq!(
|
||||
// exported_multivalue.call(&[Val::I32(3), Val::I32(2)]),
|
||||
// Ok(expected)
|
||||
// );
|
||||
// }
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test_imported_function_dynamic_with_env() {
|
||||
let store = Store::default();
|
||||
|
||||
Reference in New Issue
Block a user