javascriptcore/auto/
exception.rs1use crate::Context;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "JSCException")]
10 pub struct Exception(Object<ffi::JSCException, ffi::JSCExceptionClass>);
11
12 match fn {
13 type_ => || ffi::jsc_exception_get_type(),
14 }
15}
16
17impl Exception {
18 pub const NONE: Option<&'static Exception> = None;
19
20 #[doc(alias = "jsc_exception_new")]
21 pub fn new(context: &impl IsA<Context>, message: &str) -> Exception {
22 unsafe {
23 from_glib_full(ffi::jsc_exception_new(
24 context.as_ref().to_glib_none().0,
25 message.to_glib_none().0,
26 ))
27 }
28 }
29
30 #[doc(alias = "jsc_exception_new_with_name")]
41 #[doc(alias = "new_with_name")]
42 pub fn with_name(context: &impl IsA<Context>, name: &str, message: &str) -> Exception {
43 unsafe {
44 from_glib_full(ffi::jsc_exception_new_with_name(
45 context.as_ref().to_glib_none().0,
46 name.to_glib_none().0,
47 message.to_glib_none().0,
48 ))
49 }
50 }
51
52 }
64
65impl std::fmt::Display for Exception {
66 #[inline]
67 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68 f.write_str(&ExceptionExt::to_str(self))
69 }
70}
71
72mod sealed {
73 pub trait Sealed {}
74 impl<T: super::IsA<super::Exception>> Sealed for T {}
75}
76
77pub trait ExceptionExt: IsA<Exception> + sealed::Sealed + 'static {
78 #[doc(alias = "jsc_exception_get_backtrace_string")]
79 #[doc(alias = "get_backtrace_string")]
80 fn backtrace_string(&self) -> Option<glib::GString> {
81 unsafe {
82 from_glib_none(ffi::jsc_exception_get_backtrace_string(
83 self.as_ref().to_glib_none().0,
84 ))
85 }
86 }
87
88 #[doc(alias = "jsc_exception_get_column_number")]
89 #[doc(alias = "get_column_number")]
90 fn column_number(&self) -> u32 {
91 unsafe { ffi::jsc_exception_get_column_number(self.as_ref().to_glib_none().0) }
92 }
93
94 #[doc(alias = "jsc_exception_get_line_number")]
95 #[doc(alias = "get_line_number")]
96 fn line_number(&self) -> u32 {
97 unsafe { ffi::jsc_exception_get_line_number(self.as_ref().to_glib_none().0) }
98 }
99
100 #[doc(alias = "jsc_exception_get_message")]
101 #[doc(alias = "get_message")]
102 fn message(&self) -> Option<glib::GString> {
103 unsafe {
104 from_glib_none(ffi::jsc_exception_get_message(
105 self.as_ref().to_glib_none().0,
106 ))
107 }
108 }
109
110 #[doc(alias = "jsc_exception_get_name")]
111 #[doc(alias = "get_name")]
112 fn name(&self) -> Option<glib::GString> {
113 unsafe { from_glib_none(ffi::jsc_exception_get_name(self.as_ref().to_glib_none().0)) }
114 }
115
116 #[doc(alias = "jsc_exception_get_source_uri")]
117 #[doc(alias = "get_source_uri")]
118 fn source_uri(&self) -> Option<glib::GString> {
119 unsafe {
120 from_glib_none(ffi::jsc_exception_get_source_uri(
121 self.as_ref().to_glib_none().0,
122 ))
123 }
124 }
125
126 #[doc(alias = "jsc_exception_report")]
127 fn report(&self) -> Option<glib::GString> {
128 unsafe { from_glib_full(ffi::jsc_exception_report(self.as_ref().to_glib_none().0)) }
129 }
130
131 #[doc(alias = "jsc_exception_to_string")]
132 #[doc(alias = "to_string")]
133 fn to_str(&self) -> glib::GString {
134 unsafe { from_glib_full(ffi::jsc_exception_to_string(self.as_ref().to_glib_none().0)) }
135 }
136}
137
138impl<O: IsA<Exception>> ExceptionExt for O {}