2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "ExceptionCode.h"
29 #include "EventException.h"
30 #include "IDBDatabaseException.h"
31 #include "RangeException.h"
32 #include "XMLHttpRequestException.h"
35 #include "SVGException.h"
39 #include "XPathException.h"
43 #include "SQLException.h"
46 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
47 #include "FileException.h"
48 #include "OperationNotAllowedException.h"
53 static const char* const exceptionNames[] = {
56 "HIERARCHY_REQUEST_ERR",
58 "INVALID_CHARACTER_ERR",
59 "NO_DATA_ALLOWED_ERR",
60 "NO_MODIFICATION_ALLOWED_ERR",
63 "INUSE_ATTRIBUTE_ERR",
66 "INVALID_MODIFICATION_ERR",
77 "INVALID_NODE_TYPE_ERR",
81 static const char* const exceptionDescriptions[] = {
82 "Index or size was negative, or greater than the allowed value.",
83 "The specified range of text did not fit into a DOMString.",
84 "A Node was inserted somewhere it doesn't belong.",
85 "A Node was used in a different document than the one that created it (that doesn't support it).",
86 "An invalid or illegal character was specified, such as in an XML name.",
87 "Data was specified for a Node which does not support data.",
88 "An attempt was made to modify an object where modifications are not allowed.",
89 "An attempt was made to reference a Node in a context where it does not exist.",
90 "The implementation did not support the requested type of object or operation.",
91 "An attempt was made to add an attribute that is already in use elsewhere.",
92 "An attempt was made to use an object that is not, or is no longer, usable.",
93 "An invalid or illegal string was specified.",
94 "An attempt was made to modify the type of the underlying object.",
95 "An attempt was made to create or change an object in a way which is incorrect with regard to namespaces.",
96 "A parameter or an operation was not supported by the underlying object.",
97 "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.",
98 "The type of an object was incompatible with the expected type of the parameter associated to the object.",
99 "An attempt was made to break through the security policy of the user agent.",
100 // FIXME: Couldn't find a description in the HTML/DOM specifications for NETWORK_ERR, ABORT_ERR, URL_MISMATCH_ERR, and QUOTA_EXCEEDED_ERR
101 "A network error occured.",
102 "The user aborted a request.",
103 "A worker global scope represented an absolute URL that is not equal to the resulting absolute URL.",
104 "An attempt was made to add something to storage that exceeded the quota.",
105 "A timeout occurred.",
106 "The supplied node is invalid or has an invalid ancestor for this operation.",
107 "An object could not be cloned."
110 static const char* const rangeExceptionNames[] = {
111 "BAD_BOUNDARYPOINTS_ERR",
112 "INVALID_NODE_TYPE_ERR"
115 static const char* const rangeExceptionDescriptions[] = {
116 "The boundary-points of a Range did not meet specific requirements.",
117 "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."
120 static const char* const eventExceptionNames[] = {
121 "UNSPECIFIED_EVENT_TYPE_ERR",
122 "DISPATCH_REQUEST_ERR"
125 static const char* const eventExceptionDescriptions[] = {
126 "The Event's type was not specified by initializing the event before the method was called.",
127 "The Event object is already being dispatched."
130 static const char* const xmlHttpRequestExceptionNames[] = {
135 static const char* const xmlHttpRequestExceptionDescriptions[] = {
136 "A network error occured in synchronous requests.",
137 "The user aborted a request in synchronous requests."
141 static const char* const xpathExceptionNames[] = {
142 "INVALID_EXPRESSION_ERR",
146 static const char* const xpathExceptionDescriptions[] = {
147 "The expression had a syntax error or otherwise is not a legal expression according to the rules of the specific XPathEvaluator.",
148 "The expression could not be converted to return the specified type."
153 static const char* const svgExceptionNames[] = {
154 "SVG_WRONG_TYPE_ERR",
155 "SVG_INVALID_VALUE_ERR",
156 "SVG_MATRIX_NOT_INVERTABLE"
159 static const char* const svgExceptionDescriptions[] = {
160 "An object of the wrong type was passed to an operation.",
161 "An invalid value was passed to an operation or assigned to an attribute.",
162 "An attempt was made to invert a matrix that is not invertible."
167 static const char* const sqlExceptionNames[] = {
178 static const char* const sqlExceptionDescriptions[] = {
179 "The operation failed for reasons unrelated to the database.",
180 "The operation failed for some reason related to the database.",
181 "The actual database version did not match the expected version.",
182 "Data returned from the database is too large.",
183 "Quota was exceeded.",
184 "Invalid or unauthorized statement; or the number of arguments did not match the number of ? placeholders.",
185 "A constraint was violated.",
186 "A transaction lock could not be acquired in a reasonable time."
190 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
191 static const char* const fileExceptionNames[] = {
197 "NO_MODIFICATION_ALLOWED_ERR",
200 "INVALID_MODIFICATION_ERR",
201 "QUOTA_EXCEEDED_ERR",
206 static const char* const fileExceptionDescriptions[] = {
207 "A requested file or directory could not be found at the time an operation was processed.",
208 "It was determined that certain files are unsafe for access within a Web application, or that too many calls are being made on file resources.",
209 "An ongoing operation was aborted, typically with a call to abort().",
210 "The requested file could not be read, typically due to permission problems that have occured after a reference to a file was acquired.",
211 "A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.",
212 "An attempt was made to write to a file or directory which could not be modified due to the state of the underlying filesystem.",
213 "An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk.",
214 "An invalid or unsupported argument was given, like an invalid line ending specifier.",
215 "The modification request was illegal.",
216 "The operation failed because it would cause the application to exceed its storage quota.",
217 "The path supplied exists, but was not an entry of requested type.",
218 "An attempt was made to create a file or directory where an element already exists."
221 static const char* const operationNotAllowedExceptionNames[] = {
225 static const char* const operationNotAllowedExceptionDescriptions[] = {
226 "A read method was called while the object was in the LOADING state due to a previous read call."
230 #if ENABLE(INDEXED_DATABASE)
231 static const char* const idbDatabaseExceptionNames[] = {
247 static const char* const idbDatabaseExceptionDescriptions[] = {
248 "An unknown error occurred within Indexed Database.",
249 "NON_TRANSIENT_ERR", // FIXME: Write a better message if it's ever possible this is thrown.
250 "The name supplied does not match any existing item.",
251 "The request cannot be completed due to a failed constraint.",
252 "The data provided does not meet the requirements of the function.",
253 "This function is not allowed to be called in such a context.",
254 "The data supplied cannot be serialized according to the structured cloning algorithm.",
255 "RECOVERABLE_ERR", // FIXME: This isn't even used.
256 "TRANSIENT_ERR", // FIXME: This isn't even used.
257 "TIMEOUT_ERR", // This can't be thrown.
258 "DEADLOCK_ERR", // This can't be thrown.
259 "Write operations cannot be preformed on a read-only transaction.",
260 "The transaction was aborted, so the request cannot be fulfilled."
264 void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& description)
268 const char* typeName;
270 const char* const* nameTable;
271 const char* const* descriptionTable;
276 if (code >= RangeException::RangeExceptionOffset && code <= RangeException::RangeExceptionMax) {
277 type = RangeExceptionType;
278 typeName = "DOM Range";
279 code -= RangeException::RangeExceptionOffset;
280 nameTable = rangeExceptionNames;
281 descriptionTable = rangeExceptionDescriptions;
282 nameTableSize = WTF_ARRAY_LENGTH(rangeExceptionNames);
283 nameTableOffset = RangeException::BAD_BOUNDARYPOINTS_ERR;
284 } else if (code >= EventException::EventExceptionOffset && code <= EventException::EventExceptionMax) {
285 type = EventExceptionType;
286 typeName = "DOM Events";
287 code -= EventException::EventExceptionOffset;
288 nameTable = eventExceptionNames;
289 descriptionTable = eventExceptionDescriptions;
290 nameTableSize = WTF_ARRAY_LENGTH(eventExceptionNames);
291 nameTableOffset = EventException::UNSPECIFIED_EVENT_TYPE_ERR;
292 } else if (code >= XMLHttpRequestException::XMLHttpRequestExceptionOffset && code <= XMLHttpRequestException::XMLHttpRequestExceptionMax) {
293 type = XMLHttpRequestExceptionType;
294 typeName = "XMLHttpRequest";
295 code -= XMLHttpRequestException::XMLHttpRequestExceptionOffset;
296 nameTable = xmlHttpRequestExceptionNames;
297 descriptionTable = xmlHttpRequestExceptionDescriptions;
298 nameTableSize = WTF_ARRAY_LENGTH(xmlHttpRequestExceptionNames);
299 // XMLHttpRequest exception codes start with 101 and we don't want 100 empty elements in the name array
300 nameTableOffset = XMLHttpRequestException::NETWORK_ERR;
302 } else if (code >= XPathException::XPathExceptionOffset && code <= XPathException::XPathExceptionMax) {
303 type = XPathExceptionType;
304 typeName = "DOM XPath";
305 code -= XPathException::XPathExceptionOffset;
306 nameTable = xpathExceptionNames;
307 descriptionTable = xpathExceptionDescriptions;
308 nameTableSize = WTF_ARRAY_LENGTH(xpathExceptionNames);
309 // XPath exception codes start with 51 and we don't want 51 empty elements in the name array
310 nameTableOffset = XPathException::INVALID_EXPRESSION_ERR;
313 } else if (code >= SVGException::SVGExceptionOffset && code <= SVGException::SVGExceptionMax) {
314 type = SVGExceptionType;
315 typeName = "DOM SVG";
316 code -= SVGException::SVGExceptionOffset;
317 nameTable = svgExceptionNames;
318 descriptionTable = svgExceptionDescriptions;
319 nameTableSize = WTF_ARRAY_LENGTH(svgExceptionNames);
320 nameTableOffset = SVGException::SVG_WRONG_TYPE_ERR;
323 } else if (code >= SQLException::SQLExceptionOffset && code <= SQLException::SQLExceptionMax) {
324 type = SQLExceptionType;
325 typeName = "DOM SQL";
326 code -= SQLException::SQLExceptionOffset;
327 nameTable = sqlExceptionNames;
328 descriptionTable = sqlExceptionDescriptions;
329 nameTableSize = WTF_ARRAY_LENGTH(sqlExceptionNames);
330 nameTableOffset = SQLException::UNKNOWN_ERR;
332 #if ENABLE(BLOB) || ENABLE(FILE_SYSTEM)
333 } else if (code >= FileException::FileExceptionOffset && code <= FileException::FileExceptionMax) {
334 type = FileExceptionType;
335 typeName = "DOM File";
336 code -= FileException::FileExceptionOffset;
337 nameTable = fileExceptionNames;
338 descriptionTable = fileExceptionDescriptions;
339 nameTableSize = WTF_ARRAY_LENGTH(fileExceptionNames);
340 nameTableOffset = FileException::NOT_FOUND_ERR;
341 } else if (code >= OperationNotAllowedException::OperationNotAllowedExceptionOffset && code <= OperationNotAllowedException::OperationNotAllowedExceptionMax) {
342 type = OperationNotAllowedExceptionType;
343 typeName = "DOM OperationNotAllowed";
344 code -= OperationNotAllowedException::OperationNotAllowedExceptionOffset;
345 nameTable = operationNotAllowedExceptionNames;
346 descriptionTable = operationNotAllowedExceptionDescriptions;
347 nameTableSize = WTF_ARRAY_LENGTH(operationNotAllowedExceptionNames);
348 nameTableOffset = OperationNotAllowedException::NOT_ALLOWED_ERR;
350 #if ENABLE(INDEXED_DATABASE)
351 } else if (code >= IDBDatabaseException::IDBDatabaseExceptionOffset && code <= IDBDatabaseException::IDBDatabaseExceptionMax) {
352 type = IDBDatabaseExceptionType;
353 typeName = "DOM IDBDatabase";
354 code -= IDBDatabaseException::IDBDatabaseExceptionOffset;
355 nameTable = idbDatabaseExceptionNames;
356 descriptionTable = idbDatabaseExceptionDescriptions;
357 nameTableSize = WTF_ARRAY_LENGTH(idbDatabaseExceptionNames);
358 nameTableOffset = IDBDatabaseException::UNKNOWN_ERR;
361 type = DOMExceptionType;
363 nameTable = exceptionNames;
364 descriptionTable = exceptionDescriptions;
365 nameTableSize = WTF_ARRAY_LENGTH(exceptionNames);
366 nameTableOffset = INDEX_SIZE_ERR;
369 description.typeName = typeName;
370 description.name = (ec >= nameTableOffset && ec - nameTableOffset < nameTableSize) ? nameTable[ec - nameTableOffset] : 0;
371 description.description = (ec >= nameTableOffset && ec - nameTableOffset < nameTableSize) ? descriptionTable[ec - nameTableOffset] : 0;
372 description.code = code;
373 description.type = type;
375 // All exceptions used in the DOM code should have names.
376 ASSERT(description.name);
377 ASSERT(description.description);
380 } // namespace WebCore