mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 14:48:27 +00:00
Improved traps, now fully working
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
#![warn(unused_import_braces)]
|
#![warn(unused_import_braces)]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
allow(clippy::new_without_default, vtable_address_comparisons)
|
allow(clippy::new_without_default, clippy::vtable_address_comparisons)
|
||||||
)]
|
)]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "cargo-clippy",
|
feature = "cargo-clippy",
|
||||||
@@ -19,8 +19,7 @@
|
|||||||
clippy::float_arithmetic,
|
clippy::float_arithmetic,
|
||||||
clippy::mut_mut,
|
clippy::mut_mut,
|
||||||
clippy::nonminimal_bool,
|
clippy::nonminimal_bool,
|
||||||
clippy::option_map_unwrap_or,
|
clippy::map_unwrap_or,
|
||||||
clippy::option_map_unwrap_or_else,
|
|
||||||
clippy::print_stdout,
|
clippy::print_stdout,
|
||||||
clippy::unicode_not_nfc,
|
clippy::unicode_not_nfc,
|
||||||
clippy::use_self
|
clippy::use_self
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// use super::frame_info::{FrameInfo, GlobalFrameInfo, FRAME_INFO};
|
// use super::frame_info::{FrameInfo, GlobalFrameInfo, FRAME_INFO};
|
||||||
use std::convert::TryInto;
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use wasm_bindgen::convert::FromWasmAbi;
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen::JsCast;
|
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
|
|
||||||
/// A struct representing an aborted instruction execution, with a message
|
/// A struct representing an aborted instruction execution, with a message
|
||||||
@@ -120,23 +119,29 @@ impl std::error::Error for RuntimeError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<JsValue> for RuntimeError {
|
pub fn generic_of_jsval<T: FromWasmAbi<Abi = u32>>(
|
||||||
fn from(original: JsValue) -> Self {
|
js: JsValue,
|
||||||
RuntimeError {
|
classname: &str,
|
||||||
inner: Arc::new(RuntimeErrorSource::Js(original)),
|
) -> Result<T, JsValue> {
|
||||||
}
|
use js_sys::{Object, Reflect};
|
||||||
// let into_runtime: Result<RuntimeError, _> = original.clone().try_into();
|
let ctor_name = Object::get_prototype_of(&js).constructor().name();
|
||||||
// match into_runtime {
|
if ctor_name == classname {
|
||||||
// Ok(rt) => rt,
|
let ptr = Reflect::get(&js, &JsValue::from_str("ptr"))?;
|
||||||
// Err(_) => RuntimeError {
|
let ptr_u32: u32 = ptr.as_f64().ok_or(JsValue::NULL)? as u32;
|
||||||
// inner: Arc::new(RuntimeErrorSource::Js(original)),
|
let foo = unsafe { T::from_abi(ptr_u32) };
|
||||||
// }
|
Ok(foo)
|
||||||
// }
|
} else {
|
||||||
// match original.dyn_into::<RuntimeError>() {
|
Err(js)
|
||||||
// Ok(rt) => rt,
|
}
|
||||||
// Err(original) => RuntimeError {
|
}
|
||||||
// inner: Arc::new(RuntimeErrorSource::Js(original)),
|
|
||||||
// }
|
impl From<JsValue> for RuntimeError {
|
||||||
// }
|
fn from(original: JsValue) -> Self {
|
||||||
|
// We try to downcast the error and see if it's
|
||||||
|
// an instance of RuntimeError instead, so we don't need
|
||||||
|
// to re-wrap it.
|
||||||
|
generic_of_jsval(original, "RuntimeError").unwrap_or_else(|js| RuntimeError {
|
||||||
|
inner: Arc::new(RuntimeErrorSource::Js(js)),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -642,7 +642,6 @@ fn test_custom_error() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
assert!(false, "Unknown error `{:?}`", e);
|
|
||||||
match e.downcast::<ExitCode>() {
|
match e.downcast::<ExitCode>() {
|
||||||
// We found the exit code used to terminate execution.
|
// We found the exit code used to terminate execution.
|
||||||
Ok(exit_code) => {
|
Ok(exit_code) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user