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