Fixed tests added extra native function test

This commit is contained in:
Syrus Akbary
2021-07-13 20:11:49 -07:00
parent bd2cc948a4
commit d5789aae29
5 changed files with 71 additions and 50 deletions

View File

@@ -630,6 +630,19 @@ impl fmt::Debug for Function {
}
}
// This is needed for reference types
impl wasmer_types::WasmValueType for Function {
/// Write the value.
unsafe fn write_value_to(&self, _p: *mut i128) {
unimplemented!();
}
/// Read the value.
unsafe fn read_value_from(_store: &dyn std::any::Any, _p: *const i128) -> Self {
unimplemented!();
}
}
/// This private inner module contains the low-level implementation
/// for `Function` and its siblings.
mod inner {

View File

@@ -251,6 +251,7 @@ mod test {
use crate::ChainableNamedResolver;
use crate::Type;
use crate::{Global, Store, Val};
use wasm_bindgen_test::*;
#[wasm_bindgen_test]
fn chaining_works() {
@@ -287,7 +288,7 @@ mod test {
fn extending_conflict_overwrites() {
let store = Store::default();
let g1 = Global::new(&store, Val::I32(0));
let g2 = Global::new(&store, Val::I64(0));
let g2 = Global::new(&store, Val::F32(0.));
let imports1 = imports! {
"dog" => {
@@ -305,7 +306,7 @@ mod test {
let happy_dog_entry = resolver.resolve_by_name("dog", "happy").unwrap();
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
happy_dog_global.from.ty().ty == Type::I64
happy_dog_global.ty.ty == Type::F32
} else {
false
});
@@ -313,7 +314,7 @@ mod test {
// now test it in reverse
let store = Store::default();
let g1 = Global::new(&store, Val::I32(0));
let g2 = Global::new(&store, Val::I64(0));
let g2 = Global::new(&store, Val::F32(0.));
let imports1 = imports! {
"dog" => {
@@ -331,7 +332,7 @@ mod test {
let happy_dog_entry = resolver.resolve_by_name("dog", "happy").unwrap();
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
happy_dog_global.from.ty().ty == Type::I32
happy_dog_global.ty.ty == Type::I32
} else {
false
});
@@ -351,7 +352,7 @@ mod test {
let happy_dog_entry = imports1.resolve_by_name("dog", "happy").unwrap();
assert!(if let Export::Global(happy_dog_global) = happy_dog_entry {
happy_dog_global.from.ty().ty == Type::I32
happy_dog_global.ty.ty == Type::I32
} else {
false
});

View File

@@ -351,36 +351,25 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
// let store = Store::default();
// let module = Module::new(
// &store,
// br#"
// (module
// (func $imported (import "env" "imported") (param i32) (result i32))
// (func (export "exported") (param i32) (result i32)
// (call $imported (local.get 0))
// )
// )
// "#,
// )
// .unwrap();
// br#"(module
// (func $add (import "env" "sum") (param i32 i32) (result i32))
// (func (export "add_one") (param i32) (result i32)
// (call $imported (local.get 0))
// )
// )"#)
// .unwrap();
// fn imported_fn(arg: u32) -> u32 {
// return arg + 1;
// fn sum(a: i32, b: i32) -> i32 {
// a+b
// }
// let imported = Function::new_native(&store, imported_fn);
// let import_object = imports! {
// "env" => {
// "imported" => imported,
// "sum" => Function::new_native(&store, sum),
// }
// };
// let instance = Instance::new(&module, &import_object).unwrap();
// // let memory = instance.exports.get_memory("mem").unwrap();
// // assert_eq!(memory.size(), Pages(1));
// // assert_eq!(memory.data_size(), 65536);
// let exported = instance.exports.get_function("exported").unwrap();
// let expected = vec![Val::F64(5.0)].into_boxed_slice();
// exported.call(&[Val::I32(4)]) == Ok(expected)
// let add_one: NativeFunc<i32, i32> = instance.exports.get_native_function("add_one").unwrap();
// assert_eq!(add_one(1), 2)
// }

View File

@@ -414,18 +414,6 @@ impl Module {
Ok(())
}
// /// Get the custom sections of the module given a `name`.
// pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Arc<[u8]>> + 'a {
// self.custom_sections
// .iter()
// .filter_map(move |(section_name, section_index)| {
// if name != section_name {
// return None;
// }
// Some(self.custom_sections_data[*section_index].clone())
// })
// }
/// Returns an iterator over the exported types in the Module.
///
/// The order of the exports is guaranteed to be the same as in the
@@ -500,16 +488,17 @@ impl Module {
size: exports.length() as usize,
}
}
/// Get the custom sections of the module given a `name`.
///
/// # Important
///
/// Following the WebAssembly spec, one name can have multiple
/// custom sections. That's why an iterator (rather than one element)
/// is returned.
pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Arc<[u8]>> + 'a {
unimplemented!();
}
// /// Get the custom sections of the module given a `name`.
// ///
// /// # Important
// ///
// /// Following the WebAssembly spec, one name can have multiple
// /// custom sections. That's why an iterator (rather than one element)
// /// is returned.
// pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Arc<[u8]>> + 'a {
// unimplemented!();
// }
/// Returns the [`Store`] where the `Instance` belongs.
pub fn store(&self) -> &Store {