use std::{error, fmt};
use crate::{sys, JSException, JSString, JSValue};
impl JSException {
pub const fn underlying_value(&self) -> &JSValue {
&self.value
}
pub fn name(&self) -> Result<JSString, JSException> {
self.value.as_object()?.get_property("name").as_string()
}
}
impl fmt::Display for JSException {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.underlying_value().as_string() {
Ok(string) => write!(formatter, "JSException (interpreted as string): {string}"),
Err(_) => write!(formatter, "{self:?}"),
}
}
}
impl error::Error for JSException {}
impl From<JSValue> for JSException {
fn from(value: JSValue) -> Self {
Self { value }
}
}
impl From<JSException> for sys::JSValueRef {
fn from(value: JSException) -> Self {
value.value.raw
}
}