mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 21:58:20 +00:00
Use thiserror for MemoryAccessError
This commit is contained in:
committed by
Manos Pitsidianakis
parent
d94745c9fc
commit
dd7808b534
8
lib/api/src/js/externals/memory.rs
vendored
8
lib/api/src/js/externals/memory.rs
vendored
@@ -82,6 +82,9 @@ pub struct Memory {
|
||||
view: js_sys::Uint8Array,
|
||||
}
|
||||
|
||||
unsafe impl Send for Memory {}
|
||||
unsafe impl Sync for Memory {}
|
||||
|
||||
impl Memory {
|
||||
/// Creates a new host `Memory` from the provided [`MemoryType`].
|
||||
///
|
||||
@@ -234,8 +237,9 @@ impl Memory {
|
||||
Ok(Pages(new_pages))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn uint8view(&self) -> js_sys::Uint8Array {
|
||||
/// Used by tests
|
||||
#[doc(hidden)]
|
||||
pub fn uint8view(&self) -> js_sys::Uint8Array {
|
||||
self.view.clone()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use crate::RuntimeError;
|
||||
use wasmer_types::ValueType;
|
||||
|
||||
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
error::Error,
|
||||
fmt,
|
||||
marker::PhantomData,
|
||||
mem::{self, MaybeUninit},
|
||||
@@ -12,31 +9,24 @@ use std::{
|
||||
slice,
|
||||
string::FromUtf8Error,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use wasmer_types::ValueType;
|
||||
|
||||
/// Error for invalid [`Memory`] access.
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum MemoryAccessError {
|
||||
/// Memory access is outside heap bounds.
|
||||
#[error("memory access out of bounds")]
|
||||
HeapOutOfBounds,
|
||||
/// Address calculation overflow.
|
||||
#[error("address calculation overflow")]
|
||||
Overflow,
|
||||
/// String is not valid UTF-8.
|
||||
#[error("string is not valid utf-8")]
|
||||
NonUtf8String,
|
||||
}
|
||||
|
||||
impl fmt::Display for MemoryAccessError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MemoryAccessError::HeapOutOfBounds => write!(f, "memory access out of bounds"),
|
||||
MemoryAccessError::Overflow => write!(f, "address calculation overflow"),
|
||||
MemoryAccessError::NonUtf8String => write!(f, "string is not valid utf-8"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for MemoryAccessError {}
|
||||
|
||||
impl From<MemoryAccessError> for RuntimeError {
|
||||
fn from(err: MemoryAccessError) -> Self {
|
||||
RuntimeError::new(err.to_string())
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
use crate::RuntimeError;
|
||||
use wasmer_types::ValueType;
|
||||
|
||||
use crate::{Memory, Memory32, Memory64, WasmPtr};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
error::Error,
|
||||
fmt,
|
||||
marker::PhantomData,
|
||||
mem::{self, MaybeUninit},
|
||||
@@ -12,31 +9,24 @@ use std::{
|
||||
slice,
|
||||
string::FromUtf8Error,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use wasmer_types::ValueType;
|
||||
|
||||
/// Error for invalid [`Memory`] access.
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum MemoryAccessError {
|
||||
/// Memory access is outside heap bounds.
|
||||
#[error("memory access out of bounds")]
|
||||
HeapOutOfBounds,
|
||||
/// Address calculation overflow.
|
||||
#[error("address calculation overflow")]
|
||||
Overflow,
|
||||
/// String is not valid UTF-8.
|
||||
#[error("string is not valid utf-8")]
|
||||
NonUtf8String,
|
||||
}
|
||||
|
||||
impl fmt::Display for MemoryAccessError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
MemoryAccessError::HeapOutOfBounds => write!(f, "memory access out of bounds"),
|
||||
MemoryAccessError::Overflow => write!(f, "address calculation overflow"),
|
||||
MemoryAccessError::NonUtf8String => write!(f, "string is not valid utf-8"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for MemoryAccessError {}
|
||||
|
||||
impl From<MemoryAccessError> for RuntimeError {
|
||||
fn from(err: MemoryAccessError) -> Self {
|
||||
RuntimeError::new(err.to_string())
|
||||
|
||||
Reference in New Issue
Block a user