Add Module::custom_sections and FromToNativeWasmType::is_from_store

This commit is contained in:
Felix Schütt
2022-08-24 11:12:37 +02:00
parent cd342453db
commit 4540e3ba8f
3 changed files with 29 additions and 12 deletions

View File

@@ -599,7 +599,7 @@ mod inner {
use super::RuntimeError; use super::RuntimeError;
use super::VMFunctionBody; use super::VMFunctionBody;
use crate::js::function_env::{FunctionEnvMut, VMFunctionEnvironment}; use crate::js::function_env::{FunctionEnvMut, VMFunctionEnvironment};
use crate::js::store::{AsStoreMut, InternalStoreHandle, StoreHandle, StoreMut}; use crate::js::store::{AsStoreMut, AsStoreRef, InternalStoreHandle, StoreHandle, StoreMut};
use crate::js::FunctionEnv; use crate::js::FunctionEnv;
use crate::js::NativeWasmTypeInto; use crate::js::NativeWasmTypeInto;
use std::array::TryFromSliceError; use std::array::TryFromSliceError;
@@ -640,6 +640,9 @@ mod inner {
/// This method panics if `self` cannot fit in the /// This method panics if `self` cannot fit in the
/// `Self::Native` type. /// `Self::Native` type.
fn to_native(self) -> Self::Native; fn to_native(self) -> Self::Native;
/// Returns whether this native type belongs to the given store
fn is_from_store(&self, _store: &impl AsStoreRef) -> bool;
} }
macro_rules! from_to_native_wasm_type { macro_rules! from_to_native_wasm_type {
@@ -658,6 +661,11 @@ mod inner {
fn to_native(self) -> Self::Native { fn to_native(self) -> Self::Native {
self as Self::Native self as Self::Native
} }
#[inline]
fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
self.handle.store_id() == store.as_store_ref().objects().id()
}
} }
)* )*
}; };
@@ -679,6 +687,11 @@ mod inner {
fn to_native(self) -> Self::Native { fn to_native(self) -> Self::Native {
Self::Native::from_ne_bytes(Self::to_ne_bytes(self)) Self::Native::from_ne_bytes(Self::to_ne_bytes(self))
} }
#[inline]
fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
self.handle.store_id() == store.as_store_ref().objects().id()
}
} }
)* )*
}; };

View File

@@ -551,16 +551,16 @@ impl Module {
ExportsIterator::new(iter, exports.length() as usize) ExportsIterator::new(iter, exports.length() as usize)
} }
// /// Get the custom sections of the module given a `name`. /// Get the custom sections of the module given a `name`.
// /// ///
// /// # Important /// # Important
// /// ///
// /// Following the WebAssembly spec, one name can have multiple /// Following the WebAssembly spec, one name can have multiple
// /// custom sections. That's why an iterator (rather than one element) /// custom sections. That's why an iterator (rather than one element)
// /// is returned. /// is returned.
// pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Arc<[u8]>> + 'a { pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Box<[u8]>> + 'a {
// unimplemented!(); unimplemented!()
// } }
} }
impl fmt::Debug for Module { impl fmt::Debug for Module {

View File

@@ -1,4 +1,4 @@
use crate::js::NativeWasmTypeInto; use crate::{AsStoreRef, js::NativeWasmTypeInto};
use crate::js::{externals::MemoryView, FromToNativeWasmType}; use crate::js::{externals::MemoryView, FromToNativeWasmType};
use crate::js::{MemoryAccessError, WasmRef, WasmSlice}; use crate::js::{MemoryAccessError, WasmRef, WasmSlice};
use std::convert::TryFrom; use std::convert::TryFrom;
@@ -234,6 +234,10 @@ where
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
#[inline]
fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
true // TODO ???
}
} }
unsafe impl<T: ValueType, M: MemorySize> ValueType for WasmPtr<T, M> { unsafe impl<T: ValueType, M: MemorySize> ValueType for WasmPtr<T, M> {