mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 13:58:38 +00:00
Fixed for the JS version
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use crate::WasmSliceAccess;
|
||||
use crate::access::{SliceCow, RefCow, WasmRefAccess};
|
||||
use crate::js::externals::memory::MemoryBuffer;
|
||||
use crate::js::RuntimeError;
|
||||
use crate::js::{Memory32, Memory64, MemoryView, WasmPtr};
|
||||
@@ -121,6 +123,12 @@ impl<'a, T: ValueType> WasmRef<'a, T> {
|
||||
let data = unsafe { slice::from_raw_parts(data.as_ptr() as *const _, data.len()) };
|
||||
self.buffer.write(self.offset, data)
|
||||
}
|
||||
|
||||
/// Gains direct access to the memory of this slice
|
||||
#[inline]
|
||||
pub fn access(self) -> Result<WasmRefAccess<'a, T>, MemoryAccessError> {
|
||||
WasmRefAccess::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ValueType> fmt::Debug for WasmRef<'a, T> {
|
||||
@@ -250,6 +258,12 @@ impl<'a, T: ValueType> WasmSlice<'a, T> {
|
||||
self.index(idx).write(val)
|
||||
}
|
||||
|
||||
/// Gains direct access to the memory of this slice
|
||||
#[inline]
|
||||
pub fn access(self) -> Result<WasmSliceAccess<'a, T>, MemoryAccessError> {
|
||||
WasmSliceAccess::new(self)
|
||||
}
|
||||
|
||||
/// Reads the entire slice into the given buffer.
|
||||
///
|
||||
/// The length of the buffer must match the length of the slice.
|
||||
@@ -414,7 +428,7 @@ where
|
||||
let buf = slice.read_to_vec()?;
|
||||
Ok(Self {
|
||||
slice,
|
||||
buf: SliceCow::Owned(buf),
|
||||
buf: SliceCow::Owned(buf, false),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -424,10 +438,10 @@ where
|
||||
T: wasmer_types::ValueType,
|
||||
{
|
||||
fn new(ptr: WasmRef<'a, T>) -> Result<Self, MemoryAccessError> {
|
||||
let val = slice.read()?;
|
||||
let val = ptr.read()?;
|
||||
Ok(Self {
|
||||
ptr,
|
||||
buf: RefCow::Owned(val),
|
||||
buf: RefCow::Owned(val, false),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user