mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-12 13:28:49 +00:00
Improved traps
# Conflicts: # lib/js-api/tests/instance.rs
This commit is contained in:
@@ -10,10 +10,16 @@ use wasm_bindgen::JsValue;
|
||||
/// indicating the cause.
|
||||
#[wasm_bindgen]
|
||||
#[derive(Clone)]
|
||||
pub struct RuntimeError {
|
||||
pub struct WasmerRuntimeError {
|
||||
inner: Arc<RuntimeErrorSource>,
|
||||
}
|
||||
|
||||
/// This type is the same as `WasmerRuntimeError`.
|
||||
///
|
||||
/// We use the `WasmerRuntimeError` name to not collide with the
|
||||
/// `RuntimeError` in JS.
|
||||
pub type RuntimeError = WasmerRuntimeError;
|
||||
|
||||
impl PartialEq for RuntimeError {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
Arc::ptr_eq(&self.inner, &other.inner)
|
||||
@@ -56,6 +62,13 @@ impl RuntimeError {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new user `RuntimeError` with the given `error`.
|
||||
pub fn user(error: impl Error + 'static) -> Self {
|
||||
RuntimeError {
|
||||
inner: Arc::new(RuntimeErrorSource::User(Box::new(error))),
|
||||
}
|
||||
}
|
||||
|
||||
/// Raises a custom user Error
|
||||
pub fn raise(error: Box<dyn Error + Send + Sync>) -> ! {
|
||||
let error = if error.is::<RuntimeError>() {
|
||||
@@ -127,9 +140,16 @@ pub fn generic_of_jsval<T: FromWasmAbi<Abi = u32>>(
|
||||
let ctor_name = Object::get_prototype_of(&js).constructor().name();
|
||||
if ctor_name == classname {
|
||||
let ptr = Reflect::get(&js, &JsValue::from_str("ptr"))?;
|
||||
let ptr_u32: u32 = ptr.as_f64().ok_or(JsValue::NULL)? as u32;
|
||||
let foo = unsafe { T::from_abi(ptr_u32) };
|
||||
Ok(foo)
|
||||
match ptr.as_f64() {
|
||||
Some(ptr_f64) => {
|
||||
let foo = unsafe { T::from_abi(ptr_f64 as u32) };
|
||||
Ok(foo)
|
||||
}
|
||||
None => {
|
||||
// We simply relay the js value
|
||||
Err(js)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Err(js)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user