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(new String[] {
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 }
181
182
183
184
185
186
187
188
189
190 @JsxConstructor
191 public void jsConstructor(final String message, final Object error) {
192 message_ = message;
193
194 if (error == null) {
195 code_ = 0;
196 name_ = null;
197 return;
198 }
199
200 if (JavaScriptEngine.isUndefined(error)) {
201 code_ = 0;
202 name_ = "Error";
203 return;
204 }
205
206 name_ = JavaScriptEngine.toString(error);
207
208 final int idx = COMMON_ERROR_NAMES.indexOf(name_);
209 if (idx != -1) {
210 code_ = idx + 1;
211 return;
212 }
213
214 code_ = 0;
215 }
216
217
218
219
220
221
222 public DOMException(final String message, final int error) {
223 message_ = message;
224 code_ = error;
225 name_ = COMMON_ERROR_NAMES.get(error - 1);
226 }
227
228
229
230
231
232 @JsxGetter
233 public Object getCode() {
234 if (code_ == -1) {
235 return JavaScriptEngine.UNDEFINED;
236 }
237 return code_;
238 }
239
240
241
242
243
244 @JsxGetter
245 public String getName() {
246 return name_;
247 }
248
249
250
251
252
253 @JsxGetter
254 public Object getMessage() {
255 if (message_ == null) {
256 return JavaScriptEngine.UNDEFINED;
257 }
258 return message_;
259 }
260
261
262
263
264
265 @JsxGetter({FF, FF_ESR})
266 public Object getLineNumber() {
267 if (lineNumber_ == -1) {
268 return JavaScriptEngine.UNDEFINED;
269 }
270 return lineNumber_;
271 }
272
273
274
275
276
277 @JsxGetter({FF, FF_ESR})
278 public Object getFilename() {
279 if (fileName_ == null) {
280 return JavaScriptEngine.UNDEFINED;
281 }
282 return fileName_;
283 }
284
285
286
287
288
289
290 public void setLocation(final String fileName, final int lineNumber) {
291 fileName_ = fileName;
292 lineNumber_ = lineNumber;
293 }
294 }