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