1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.dom;
16
17 import static org.htmlunit.javascript.configuration.SupportedBrowser.FF;
18 import static org.htmlunit.javascript.configuration.SupportedBrowser.FF_ESR;
19
20 import java.util.Arrays;
21 import java.util.List;
22
23 import org.htmlunit.javascript.HtmlUnitScriptable;
24 import org.htmlunit.javascript.JavaScriptEngine;
25 import org.htmlunit.javascript.configuration.JsxClass;
26 import org.htmlunit.javascript.configuration.JsxConstant;
27 import org.htmlunit.javascript.configuration.JsxConstructor;
28 import org.htmlunit.javascript.configuration.JsxGetter;
29
30
31
32
33
34
35
36
37
38
39
40
41 @JsxClass
42 public class DOMException extends HtmlUnitScriptable {
43
44
45 @JsxConstant
46 public static final int DOMSTRING_SIZE_ERR = org.w3c.dom.DOMException.DOMSTRING_SIZE_ERR;
47
48
49 @JsxConstant
50 public static final int HIERARCHY_REQUEST_ERR = org.w3c.dom.DOMException.HIERARCHY_REQUEST_ERR;
51
52
53 @JsxConstant
54 public static final int INDEX_SIZE_ERR = org.w3c.dom.DOMException.INDEX_SIZE_ERR;
55
56
57 @JsxConstant
58 public static final int INUSE_ATTRIBUTE_ERR = org.w3c.dom.DOMException.INUSE_ATTRIBUTE_ERR;
59
60
61 @JsxConstant
62 public static final int INVALID_ACCESS_ERR = org.w3c.dom.DOMException.INVALID_ACCESS_ERR;
63
64
65 @JsxConstant
66 public static final int INVALID_CHARACTER_ERR = org.w3c.dom.DOMException.INVALID_CHARACTER_ERR;
67
68
69 @JsxConstant
70 public static final int INVALID_MODIFICATION_ERR = org.w3c.dom.DOMException.INVALID_MODIFICATION_ERR;
71
72
73 @JsxConstant
74 public static final int INVALID_STATE_ERR = org.w3c.dom.DOMException.INVALID_STATE_ERR;
75
76
77 @JsxConstant
78 public static final int NAMESPACE_ERR = org.w3c.dom.DOMException.NAMESPACE_ERR;
79
80
81 @JsxConstant
82 public static final int NO_DATA_ALLOWED_ERR = org.w3c.dom.DOMException.NO_DATA_ALLOWED_ERR;
83
84
85 @JsxConstant
86 public static final int NO_MODIFICATION_ALLOWED_ERR = org.w3c.dom.DOMException.NO_MODIFICATION_ALLOWED_ERR;
87
88
89 @JsxConstant
90 public static final int NOT_FOUND_ERR = org.w3c.dom.DOMException.NOT_FOUND_ERR;
91
92
93 @JsxConstant
94 public static final int NOT_SUPPORTED_ERR = org.w3c.dom.DOMException.NOT_SUPPORTED_ERR;
95
96
97 @JsxConstant
98 public static final int SYNTAX_ERR = org.w3c.dom.DOMException.SYNTAX_ERR;
99
100
101 @JsxConstant
102 public static final int WRONG_DOCUMENT_ERR = org.w3c.dom.DOMException.WRONG_DOCUMENT_ERR;
103
104
105 @JsxConstant
106 public static final int VALIDATION_ERR = org.w3c.dom.DOMException.VALIDATION_ERR;
107
108
109 @JsxConstant
110 public static final int TYPE_MISMATCH_ERR = org.w3c.dom.DOMException.TYPE_MISMATCH_ERR;
111
112
113 @JsxConstant
114 public static final int SECURITY_ERR = 18;
115
116
117 @JsxConstant
118 public static final int NETWORK_ERR = 19;
119
120
121 @JsxConstant
122 public static final int ABORT_ERR = 20;
123
124
125 @JsxConstant
126 public static final int URL_MISMATCH_ERR = 21;
127
128
129 @JsxConstant
130 public static final int QUOTA_EXCEEDED_ERR = 22;
131
132
133 @JsxConstant
134 public static final int TIMEOUT_ERR = 23;
135
136
137 @JsxConstant
138 public static final int INVALID_NODE_TYPE_ERR = 24;
139
140
141 @JsxConstant
142 public static final int DATA_CLONE_ERR = 25;
143
144 private static final List<String> COMMON_ERROR_NAMES = Arrays.asList(
145 "IndexSizeError",
146 null,
147 "HierarchyRequestError",
148 "WrongDocumentError",
149 "InvalidCharacterError",
150 null,
151 "NoModificationAllowedError",
152 "NotFoundError",
153 "NotSupportedError",
154 "InUseAttributeError",
155 "InvalidStateError",
156 "SyntaxError",
157 "InvalidModificationError",
158 "NamespaceError",
159 "InvalidAccessError",
160 null,
161 "TypeMismatchError",
162 "SecurityError",
163 "NetworkError",
164 "AbortError",
165 "URLMismatchError",
166 "QuotaExceededError",
167 "TimeoutError",
168 "InvalidNodeTypeError",
169 "DataCloneError");
170
171 private int code_;
172 private String name_;
173 private String message_;
174 private int lineNumber_;
175 private String fileName_;
176
177
178
179
180 public DOMException() {
181 super();
182 }
183
184
185
186
187
188
189 public DOMException(final String message, final int error) {
190 message_ = message;
191 code_ = error;
192 name_ = COMMON_ERROR_NAMES.get(error - 1);
193 }
194
195
196
197
198
199
200
201
202
203 @JsxConstructor
204 public void jsConstructor(final String message, final Object error) {
205 message_ = message;
206
207 if (error == null) {
208 code_ = 0;
209 name_ = null;
210 return;
211 }
212
213 if (JavaScriptEngine.isUndefined(error)) {
214 code_ = 0;
215 name_ = "Error";
216 return;
217 }
218
219 name_ = JavaScriptEngine.toString(error);
220
221 final int idx = COMMON_ERROR_NAMES.indexOf(name_);
222 if (idx != -1) {
223 code_ = idx + 1;
224 return;
225 }
226
227 code_ = 0;
228 }
229
230
231
232
233
234 @JsxGetter
235 public Object getCode() {
236 if (code_ == -1) {
237 return JavaScriptEngine.UNDEFINED;
238 }
239 return code_;
240 }
241
242
243
244
245
246 @JsxGetter
247 public String getName() {
248 return name_;
249 }
250
251
252
253
254
255 @JsxGetter
256 public Object getMessage() {
257 if (message_ == null) {
258 return JavaScriptEngine.UNDEFINED;
259 }
260 return message_;
261 }
262
263
264
265
266
267 @JsxGetter({FF, FF_ESR})
268 public Object getLineNumber() {
269 if (lineNumber_ == -1) {
270 return JavaScriptEngine.UNDEFINED;
271 }
272 return lineNumber_;
273 }
274
275
276
277
278
279 @JsxGetter({FF, FF_ESR})
280 public Object getFilename() {
281 if (fileName_ == null) {
282 return JavaScriptEngine.UNDEFINED;
283 }
284 return fileName_;
285 }
286
287
288
289
290
291
292 public void setLocation(final String fileName, final int lineNumber) {
293 fileName_ = fileName;
294 lineNumber_ = lineNumber;
295 }
296 }