mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 12:48:20 +00:00
Added hashing to the StoreHandle and Funciton env in wasmer-js
This commit is contained in:
@@ -10,7 +10,7 @@ use crate::js::{AsStoreMut, AsStoreRef, StoreMut, StoreRef};
|
||||
/// The function environment data is owned by the `Store`.
|
||||
pub struct FunctionEnv<T> {
|
||||
pub(crate) handle: StoreHandle<VMFunctionEnvironment>,
|
||||
_phantom: PhantomData<T>,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> FunctionEnv<T> {
|
||||
@@ -24,14 +24,14 @@ impl<T> FunctionEnv<T> {
|
||||
store.as_store_mut().objects_mut(),
|
||||
VMFunctionEnvironment::new(value),
|
||||
),
|
||||
_phantom: PhantomData,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_handle(handle: StoreHandle<VMFunctionEnvironment>) -> Self {
|
||||
Self {
|
||||
handle,
|
||||
_phantom: PhantomData,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,11 +71,26 @@ impl<T> FunctionEnv<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> PartialEq for FunctionEnv<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.handle == other.handle
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eq for FunctionEnv<T> {}
|
||||
|
||||
impl<T> std::hash::Hash for FunctionEnv<T> {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.handle.hash(state);
|
||||
self.marker.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for FunctionEnv<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
handle: self.handle.clone(),
|
||||
_phantom: self._phantom,
|
||||
marker: self.marker,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ mod objects {
|
||||
/// Every handle to an object managed by a context also contains the ID of the
|
||||
/// context. This is used to check that a handle is always used with the
|
||||
/// correct context.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct StoreId(NonZeroU64);
|
||||
|
||||
impl Default for StoreId {
|
||||
@@ -298,6 +298,14 @@ mod objects {
|
||||
self.id == other.id
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> std::hash::Hash for StoreHandle<T> {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.id.hash(state);
|
||||
self.internal.idx.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for StoreHandle<T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
|
||||
Reference in New Issue
Block a user