|
1 /* |
|
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * 1. Redistributions of source code must retain the above copyright |
|
8 * notice, this list of conditions and the following disclaimer. |
|
9 * 2. Redistributions in binary form must reproduce the above copyright |
|
10 * notice, this list of conditions and the following disclaimer in the |
|
11 * documentation and/or other materials provided with the distribution. |
|
12 * |
|
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 */ |
|
25 |
|
26 #include "config.h" |
|
27 #include "ExceptionCode.h" |
|
28 |
|
29 #include "EventException.h" |
|
30 #include "RangeException.h" |
|
31 #include "XMLHttpRequestException.h" |
|
32 |
|
33 #if ENABLE(SVG) |
|
34 #include "SVGException.h" |
|
35 #endif |
|
36 |
|
37 #if ENABLE(XPATH) |
|
38 #include "XPathException.h" |
|
39 #endif |
|
40 |
|
41 #if ENABLE(DATABASE) |
|
42 #include "SQLException.h" |
|
43 #endif |
|
44 |
|
45 namespace WebCore { |
|
46 |
|
47 static const char* const exceptionNames[] = { |
|
48 "INDEX_SIZE_ERR", |
|
49 "DOMSTRING_SIZE_ERR", |
|
50 "HIERARCHY_REQUEST_ERR", |
|
51 "WRONG_DOCUMENT_ERR", |
|
52 "INVALID_CHARACTER_ERR", |
|
53 "NO_DATA_ALLOWED_ERR", |
|
54 "NO_MODIFICATION_ALLOWED_ERR", |
|
55 "NOT_FOUND_ERR", |
|
56 "NOT_SUPPORTED_ERR", |
|
57 "INUSE_ATTRIBUTE_ERR", |
|
58 "INVALID_STATE_ERR", |
|
59 "SYNTAX_ERR", |
|
60 "INVALID_MODIFICATION_ERR", |
|
61 "NAMESPACE_ERR", |
|
62 "INVALID_ACCESS_ERR", |
|
63 "VALIDATION_ERR", |
|
64 "TYPE_MISMATCH_ERR", |
|
65 "SECURITY_ERR", |
|
66 "NETWORK_ERR", |
|
67 "ABORT_ERR", |
|
68 "URL_MISMATCH_ERR", |
|
69 "QUOTA_EXCEEDED_ERR" |
|
70 }; |
|
71 |
|
72 static const char* const exceptionDescriptions[] = { |
|
73 "Index or size was negative, or greater than the allowed value.", |
|
74 "The specified range of text did not fit into a DOMString.", |
|
75 "A Node was inserted somewhere it doesn't belong.", |
|
76 "A Node was used in a different document than the one that created it (that doesn't support it).", |
|
77 "An invalid or illegal character was specified, such as in an XML name.", |
|
78 "Data was specified for a Node which does not support data.", |
|
79 "An attempt was made to modify an object where modifications are not allowed.", |
|
80 "An attempt was made to reference a Node in a context where it does not exist.", |
|
81 "The implementation did not support the requested type of object or operation.", |
|
82 "An attempt was made to add an attribute that is already in use elsewhere.", |
|
83 "An attempt was made to use an object that is not, or is no longer, usable.", |
|
84 "An invalid or illegal string was specified.", |
|
85 "An attempt was made to modify the type of the underlying object.", |
|
86 "An attempt was made to create or change an object in a way which is incorrect with regard to namespaces.", |
|
87 "A parameter or an operation was not supported by the underlying object.", |
|
88 "A call to a method such as insertBefore or removeChild would make the Node invalid with respect to \"partial validity\", this exception would be raised and the operation would not be done.", |
|
89 "The type of an object was incompatible with the expected type of the parameter associated to the object.", |
|
90 "An attempt was made to break through the security policy of the user agent.", |
|
91 // FIXME: Couldn't find a description in the HTML/DOM specifications for NETWORK_ERR, ABORT_ERR, URL_MISMATCH_ERR, and QUOTA_EXCEEDED_ERR |
|
92 "A network error occured.", |
|
93 "The user aborted a request.", |
|
94 "A worker global scope represented an absolute URL that is not equal to the resulting absolute URL.", |
|
95 "An attempt was made to add something to storage that exceeded the quota." |
|
96 }; |
|
97 |
|
98 static const char* const rangeExceptionNames[] = { |
|
99 "BAD_BOUNDARYPOINTS_ERR", |
|
100 "INVALID_NODE_TYPE_ERR" |
|
101 }; |
|
102 |
|
103 static const char* const rangeExceptionDescriptions[] = { |
|
104 "The boundary-points of a Range did not meet specific requirements.", |
|
105 "The container of an boundary-point of a Range was being set to either a node of an invalid type or a node with an ancestor of an invalid type." |
|
106 }; |
|
107 |
|
108 static const char* const eventExceptionNames[] = { |
|
109 "UNSPECIFIED_EVENT_TYPE_ERR" |
|
110 }; |
|
111 |
|
112 static const char* const eventExceptionDescriptions[] = { |
|
113 "The Event's type was not specified by initializing the event before the method was called." |
|
114 }; |
|
115 |
|
116 static const char* const xmlHttpRequestExceptionNames[] = { |
|
117 "NETWORK_ERR", |
|
118 "ABORT_ERR" |
|
119 }; |
|
120 |
|
121 static const char* const xmlHttpRequestExceptionDescriptions[] = { |
|
122 "A network error occured in synchronous requests.", |
|
123 "The user aborted a request in synchronous requests." |
|
124 }; |
|
125 |
|
126 #if ENABLE(XPATH) |
|
127 static const char* const xpathExceptionNames[] = { |
|
128 "INVALID_EXPRESSION_ERR", |
|
129 "TYPE_ERR" |
|
130 }; |
|
131 |
|
132 static const char* const xpathExceptionDescriptions[] = { |
|
133 "The expression had a syntax error or otherwise is not a legal expression according to the rules of the specific XPathEvaluator.", |
|
134 "The expression could not be converted to return the specified type." |
|
135 }; |
|
136 #endif |
|
137 |
|
138 #if ENABLE(SVG) |
|
139 static const char* const svgExceptionNames[] = { |
|
140 "SVG_WRONG_TYPE_ERR", |
|
141 "SVG_INVALID_VALUE_ERR", |
|
142 "SVG_MATRIX_NOT_INVERTABLE" |
|
143 }; |
|
144 |
|
145 static const char* const svgExceptionDescriptions[] = { |
|
146 "An object of the wrong type was passed to an operation.", |
|
147 "An invalid value was passed to an operation or assigned to an attribute.", |
|
148 "An attempt was made to invert a matrix that is not invertible." |
|
149 }; |
|
150 #endif |
|
151 |
|
152 #if ENABLE(DATABASE) |
|
153 static const char* const sqlExceptionNames[] = { |
|
154 "UNKNOWN_ERR", |
|
155 "DATABASE_ERR", |
|
156 "VERSION_ERR", |
|
157 "TOO_LARGE_ERR", |
|
158 "QUOTA_ERR", |
|
159 "SYNTAX_ERR", |
|
160 "CONSTRAINT_ERR", |
|
161 "TIMEOUT_ERR" |
|
162 }; |
|
163 |
|
164 static const char* const sqlExceptionDescriptions[] = { |
|
165 "The operation failed for reasons unrelated to the database.", |
|
166 "The operation failed for some reason related to the database.", |
|
167 "The actual database version did not match the expected version.", |
|
168 "Data returned from the database is too large.", |
|
169 "Quota was exceeded.", |
|
170 "Invalid or unauthorized statement; or the number of arguments did not match the number of ? placeholders.", |
|
171 "A constraint was violated.", |
|
172 "A transaction lock could not be acquired in a reasonable time." |
|
173 }; |
|
174 #endif |
|
175 |
|
176 void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& description) |
|
177 { |
|
178 ASSERT(ec); |
|
179 |
|
180 const char* typeName; |
|
181 int code = ec; |
|
182 const char* const* nameTable; |
|
183 const char* const* descriptionTable; |
|
184 int nameTableSize; |
|
185 int nameTableOffset; |
|
186 ExceptionType type; |
|
187 |
|
188 if (code >= RangeException::RangeExceptionOffset && code <= RangeException::RangeExceptionMax) { |
|
189 type = RangeExceptionType; |
|
190 typeName = "DOM Range"; |
|
191 code -= RangeException::RangeExceptionOffset; |
|
192 nameTable = rangeExceptionNames; |
|
193 descriptionTable = rangeExceptionDescriptions; |
|
194 nameTableSize = sizeof(rangeExceptionNames) / sizeof(rangeExceptionNames[0]); |
|
195 nameTableOffset = RangeException::BAD_BOUNDARYPOINTS_ERR; |
|
196 } else if (code >= EventException::EventExceptionOffset && code <= EventException::EventExceptionMax) { |
|
197 type = EventExceptionType; |
|
198 typeName = "DOM Events"; |
|
199 code -= EventException::EventExceptionOffset; |
|
200 nameTable = eventExceptionNames; |
|
201 descriptionTable = eventExceptionDescriptions; |
|
202 nameTableSize = sizeof(eventExceptionNames) / sizeof(eventExceptionNames[0]); |
|
203 nameTableOffset = EventException::UNSPECIFIED_EVENT_TYPE_ERR; |
|
204 } else if (code >= XMLHttpRequestException::XMLHttpRequestExceptionOffset && code <= XMLHttpRequestException::XMLHttpRequestExceptionMax) { |
|
205 type = XMLHttpRequestExceptionType; |
|
206 typeName = "XMLHttpRequest"; |
|
207 code -= XMLHttpRequestException::XMLHttpRequestExceptionOffset; |
|
208 nameTable = xmlHttpRequestExceptionNames; |
|
209 descriptionTable = xmlHttpRequestExceptionDescriptions; |
|
210 nameTableSize = sizeof(xmlHttpRequestExceptionNames) / sizeof(xmlHttpRequestExceptionNames[0]); |
|
211 // XMLHttpRequest exception codes start with 101 and we don't want 100 empty elements in the name array |
|
212 nameTableOffset = XMLHttpRequestException::NETWORK_ERR; |
|
213 #if ENABLE(XPATH) |
|
214 } else if (code >= XPathException::XPathExceptionOffset && code <= XPathException::XPathExceptionMax) { |
|
215 type = XPathExceptionType; |
|
216 typeName = "DOM XPath"; |
|
217 code -= XPathException::XPathExceptionOffset; |
|
218 nameTable = xpathExceptionNames; |
|
219 descriptionTable = xpathExceptionDescriptions; |
|
220 nameTableSize = sizeof(xpathExceptionNames) / sizeof(xpathExceptionNames[0]); |
|
221 // XPath exception codes start with 51 and we don't want 51 empty elements in the name array |
|
222 nameTableOffset = XPathException::INVALID_EXPRESSION_ERR; |
|
223 #endif |
|
224 #if ENABLE(SVG) |
|
225 } else if (code >= SVGException::SVGExceptionOffset && code <= SVGException::SVGExceptionMax) { |
|
226 type = SVGExceptionType; |
|
227 typeName = "DOM SVG"; |
|
228 code -= SVGException::SVGExceptionOffset; |
|
229 nameTable = svgExceptionNames; |
|
230 descriptionTable = svgExceptionDescriptions; |
|
231 nameTableSize = sizeof(svgExceptionNames) / sizeof(svgExceptionNames[0]); |
|
232 nameTableOffset = SVGException::SVG_WRONG_TYPE_ERR; |
|
233 #endif |
|
234 #if ENABLE(DATABASE) |
|
235 } else if (code >= SQLException::SQLExceptionOffset && code <= SQLException::SQLExceptionMax) { |
|
236 type = SQLExceptionType; |
|
237 typeName = "DOM SQL"; |
|
238 code -= SQLException::SQLExceptionOffset; |
|
239 nameTable = sqlExceptionNames; |
|
240 descriptionTable = sqlExceptionDescriptions; |
|
241 nameTableSize = sizeof(sqlExceptionNames) / sizeof(sqlExceptionNames[0]); |
|
242 nameTableOffset = SQLException::UNKNOWN_ERR; |
|
243 #endif |
|
244 } else { |
|
245 type = DOMExceptionType; |
|
246 typeName = "DOM"; |
|
247 nameTable = exceptionNames; |
|
248 descriptionTable = exceptionDescriptions; |
|
249 nameTableSize = sizeof(exceptionNames) / sizeof(exceptionNames[0]); |
|
250 nameTableOffset = INDEX_SIZE_ERR; |
|
251 } |
|
252 |
|
253 description.typeName = typeName; |
|
254 description.name = (ec >= nameTableOffset && ec - nameTableOffset < nameTableSize) ? nameTable[ec - nameTableOffset] : 0; |
|
255 description.description = (ec >= nameTableOffset && ec - nameTableOffset < nameTableSize) ? descriptionTable[ec - nameTableOffset] : 0; |
|
256 description.code = code; |
|
257 description.type = type; |
|
258 |
|
259 // All exceptions used in the DOM code should have names. |
|
260 ASSERT(description.name); |
|
261 ASSERT(description.description); |
|
262 } |
|
263 |
|
264 } // namespace WebCore |