wasmer/entities/exception/
inner.rs1use crate::vm::VMExceptionRef;
2use crate::{
3 AsStoreMut, AsStoreRef, BackendTag, ExportError, Exportable, Extern, Tag, Value,
4 macros::backend::{gen_rt_ty, match_rt},
5 vm::{VMExtern, VMExternTag},
6};
7
8gen_rt_ty!(Exception
15 @cfg feature = "artifact-size" => derive(loupe::MemoryUsage)
16 @derives Debug, Clone, PartialEq, Eq, derive_more::From
17);
18
19impl BackendException {
20 #[inline]
22 #[allow(irrefutable_let_patterns)]
23 pub fn new(store: &mut impl AsStoreMut, tag: &Tag, payload: &[Value]) -> Self {
24 match &store.as_store_mut().inner.store {
25 #[cfg(feature = "sys")]
26 crate::BackendStore::Sys(_) => {
27 let BackendTag::Sys(tag) = &tag.0 else {
28 panic!("cannot create Exception with Tag from another backend");
29 };
30
31 Self::Sys(crate::backend::sys::exception::Exception::new(
32 store, tag, payload,
33 ))
34 }
35 _ => unimplemented!("new is only implemented for the sys backend"),
36 }
37 }
38
39 #[inline]
41 pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
42 match self {
43 #[cfg(feature = "sys")]
44 Self::Sys(s) => s.is_from_store(store),
45 _ => unimplemented!("is_from_store is only implemented for the sys backend"),
46 }
47 }
48
49 #[inline]
51 pub fn tag(&self, store: &impl AsStoreRef) -> Tag {
52 match self {
53 #[cfg(feature = "sys")]
54 Self::Sys(s) => Tag(BackendTag::Sys(s.tag(store))),
55 _ => unimplemented!("tag is only implemented for the sys backend"),
56 }
57 }
58
59 #[inline]
61 pub fn payload(&self, store: &mut impl AsStoreMut) -> Vec<Value> {
62 match self {
63 #[cfg(feature = "sys")]
64 Self::Sys(s) => s.payload(store),
65 _ => unimplemented!("payload is only implemented for the sys backend"),
66 }
67 }
68
69 #[inline]
71 pub fn vm_exceptionref(&self) -> VMExceptionRef {
72 match self {
73 #[cfg(feature = "sys")]
74 Self::Sys(s) => VMExceptionRef::Sys(s.exnref()),
75 _ => unimplemented!("vm_exceptionref is only implemented for the sys backend"),
76 }
77 }
78
79 #[inline]
81 pub fn from_vm_exceptionref(exnref: VMExceptionRef) -> Self {
82 match exnref {
83 #[cfg(feature = "sys")]
84 VMExceptionRef::Sys(s) => {
85 Self::Sys(crate::backend::sys::exception::Exception::from_exnref(s))
86 }
87 _ => unimplemented!("from_vm_exceptionref is only implemented for the sys backend"),
88 }
89 }
90}