1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use webcore::value::Reference;
use webapi::error::{IError, Error};
pub trait IDomException: IError {}
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(instance_of = "DOMException")]
#[reference(subclass_of(Error))]
pub struct DomException( Reference );
impl IError for DomException {}
impl IDomException for DomException {}
error_boilerplate! { DomException }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct HierarchyRequestError( Reference );
impl IError for HierarchyRequestError {}
impl IDomException for HierarchyRequestError {}
error_boilerplate! { HierarchyRequestError, dom_exception = "HierarchyRequestError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidAccessError( Reference );
impl IError for InvalidAccessError {}
impl IDomException for InvalidAccessError {}
error_boilerplate! { InvalidAccessError, dom_exception = "InvalidAccessError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NoModificationAllowedError( Reference );
impl IError for NoModificationAllowedError {}
impl IDomException for NoModificationAllowedError {}
error_boilerplate! { NoModificationAllowedError, dom_exception = "NoModificationAllowedError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NotFoundError( Reference );
impl IError for NotFoundError {}
impl IDomException for NotFoundError {}
error_boilerplate! { NotFoundError, dom_exception = "NotFoundError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct SecurityError( Reference );
impl IError for SecurityError {}
impl IDomException for SecurityError {}
error_boilerplate! { SecurityError, dom_exception = "SecurityError" }
#[derive(Clone, Debug, PartialEq, Eq, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct SyntaxError( Reference );
impl IError for SyntaxError {}
impl IDomException for SyntaxError {}
error_boilerplate! { SyntaxError, dom_exception = "SyntaxError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct IndexSizeError( Reference );
impl IError for IndexSizeError {}
impl IDomException for IndexSizeError {}
error_boilerplate! { IndexSizeError, dom_exception = "IndexSizeError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidStateError( Reference );
impl IError for InvalidStateError {}
impl IDomException for InvalidStateError {}
error_boilerplate! { InvalidStateError, dom_exception = "InvalidStateError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NotSupportedError( Reference );
impl IError for NotSupportedError {}
impl IDomException for NotSupportedError {}
error_boilerplate! { NotSupportedError, dom_exception = "NotSupportedError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidCharacterError( Reference );
impl IError for InvalidCharacterError {}
impl IDomException for InvalidCharacterError {}
error_boilerplate! { InvalidCharacterError, dom_exception = "InvalidCharacterError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct InvalidPointerId( Reference );
impl IError for InvalidPointerId {}
impl IDomException for InvalidPointerId {}
error_boilerplate! { InvalidPointerId, dom_exception = "InvalidPointerId" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct AbortError( Reference );
impl IError for AbortError {}
impl IDomException for AbortError {}
error_boilerplate! { AbortError, dom_exception = "AbortError" }
#[derive(Clone, Debug, ReferenceType)]
#[reference(subclass_of(Error, DomException))]
pub struct NamespaceError( Reference );
impl IError for NamespaceError {}
impl IDomException for NamespaceError {}
error_boilerplate! { NamespaceError, dom_exception = "NamespaceError" }
#[cfg(all(test, feature = "web_test"))]
mod test {
use super::*;
use webcore::try_from::TryInto;
fn new_dom_exception(message: &str, name: &str) -> DomException {
js!(
return new DOMException(@{message}, @{name});
).try_into().unwrap()
}
#[test]
fn test_error() {
let name = "HierarchyRequestError";
let err: DomException = new_dom_exception("foo", name);
let err: HierarchyRequestError = err.try_into().expect("Expected HierarchyRequestError");
assert_eq!(err.name(), name);
let err: DomException = new_dom_exception("foo", name);
let err: Result<SyntaxError, _> = err.try_into();
assert!(err.is_err());
}
}