use crate::Context;
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "JSCException")]
pub struct Exception(Object<ffi::JSCException, ffi::JSCExceptionClass>);
match fn {
type_ => || ffi::jsc_exception_get_type(),
}
}
impl Exception {
pub const NONE: Option<&'static Exception> = None;
#[doc(alias = "jsc_exception_new")]
pub fn new(context: &impl IsA<Context>, message: &str) -> Exception {
unsafe {
from_glib_full(ffi::jsc_exception_new(
context.as_ref().to_glib_none().0,
message.to_glib_none().0,
))
}
}
#[doc(alias = "jsc_exception_new_with_name")]
#[doc(alias = "new_with_name")]
pub fn with_name(context: &impl IsA<Context>, name: &str, message: &str) -> Exception {
unsafe {
from_glib_full(ffi::jsc_exception_new_with_name(
context.as_ref().to_glib_none().0,
name.to_glib_none().0,
message.to_glib_none().0,
))
}
}
}
impl std::fmt::Display for Exception {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
f.write_str(&ExceptionExt::to_str(self))
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Exception>> Sealed for T {}
}
pub trait ExceptionExt: IsA<Exception> + sealed::Sealed + 'static {
#[doc(alias = "jsc_exception_get_backtrace_string")]
#[doc(alias = "get_backtrace_string")]
fn backtrace_string(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::jsc_exception_get_backtrace_string(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "jsc_exception_get_column_number")]
#[doc(alias = "get_column_number")]
fn column_number(&self) -> u32 {
unsafe { ffi::jsc_exception_get_column_number(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "jsc_exception_get_line_number")]
#[doc(alias = "get_line_number")]
fn line_number(&self) -> u32 {
unsafe { ffi::jsc_exception_get_line_number(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "jsc_exception_get_message")]
#[doc(alias = "get_message")]
fn message(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::jsc_exception_get_message(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "jsc_exception_get_name")]
#[doc(alias = "get_name")]
fn name(&self) -> Option<glib::GString> {
unsafe { from_glib_none(ffi::jsc_exception_get_name(self.as_ref().to_glib_none().0)) }
}
#[doc(alias = "jsc_exception_get_source_uri")]
#[doc(alias = "get_source_uri")]
fn source_uri(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::jsc_exception_get_source_uri(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "jsc_exception_report")]
fn report(&self) -> Option<glib::GString> {
unsafe { from_glib_full(ffi::jsc_exception_report(self.as_ref().to_glib_none().0)) }
}
#[doc(alias = "jsc_exception_to_string")]
#[doc(alias = "to_string")]
fn to_str(&self) -> glib::GString {
unsafe { from_glib_full(ffi::jsc_exception_to_string(self.as_ref().to_glib_none().0)) }
}
}
impl<O: IsA<Exception>> ExceptionExt for O {}