Removed from_vm_export in favor of from_vm_extern

This commit is contained in:
ptitSeb
2022-08-19 12:15:55 +02:00
parent 85a697f7cc
commit 6cf99a63f6
4 changed files with 10 additions and 14 deletions

View File

@@ -97,7 +97,8 @@ impl Memory {
.map_err(|_e| MemoryError::Generic("Error while creating the memory".to_owned()))?;
let vm_memory = VMMemory::new(js_memory, ty);
Ok(Self::from_vm_export(store, vm_memory))
let handle = StoreHandle::new(store.objects_mut(), vm_memory);
Ok(Self::from_vm_extern(store, handle.internal_handle()))
}
/// Creates a new host `Memory` from provided JavaScript memory.
@@ -107,12 +108,14 @@ impl Memory {
ty: MemoryType,
) -> Result<Self, MemoryError> {
let vm_memory = VMMemory::new(js_memory, ty);
Ok(Self::from_vm_export(store, vm_memory))
let handle = StoreHandle::new(store.objects_mut(), vm_memory);
Ok(Self::from_vm_extern(store, handle.internal_handle()))
}
/// Create a memory object from an existing memory and attaches it to the store
pub fn new_from_existing(new_store: &mut impl AsStoreMut, memory: VMMemory) -> Self {
Self::from_vm_export(new_store, memory)
let handle = StoreHandle::new(new_store.objects_mut(), memory);
Self::from_vm_extern(new_store, handle.internal_handle())
}
/// Returns the [`MemoryType`] of the `Memory`.
@@ -192,12 +195,6 @@ impl Memory {
Ok(Pages(new_pages))
}
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_memory: VMMemory) -> Self {
Self {
handle: StoreHandle::new(store.objects_mut(), vm_memory),
}
}
pub(crate) fn from_vm_extern(
store: &mut impl AsStoreMut,
internal: InternalStoreHandle<VMMemory>,

View File

@@ -46,7 +46,7 @@ impl Extern {
}
/// Create an `Extern` from an `wasmer_compiler::Export`.
pub fn from_vm_export(store: &mut impl AsStoreMut, export: Export) -> Self {
pub fn from_vm_extern(store: &mut impl AsStoreMut, export: Export) -> Self {
match export {
Export::Function(f) => Self::Function(Function::from_vm_extern(store, f)),
Export::Memory(m) => Self::Memory(Memory::from_vm_extern(store, m)),

View File

@@ -105,7 +105,7 @@ impl Instance {
})?;
let export: Export =
Export::from_js_value(js_export, &mut store, extern_type)?.into();
let extern_ = Extern::from_vm_export(&mut store, export);
let extern_ = Extern::from_vm_extern(&mut store, export);
Ok((name.to_string(), extern_))
})
.collect::<Result<Exports, InstantiationError>>()?;