• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace WebCore {
42 
43 static const char* const exceptionNames[] = {
44     "INDEX_SIZE_ERR",
45     "DOMSTRING_SIZE_ERR",
46     "HIERARCHY_REQUEST_ERR",
47     "WRONG_DOCUMENT_ERR",
48     "INVALID_CHARACTER_ERR",
49     "NO_DATA_ALLOWED_ERR",
50     "NO_MODIFICATION_ALLOWED_ERR",
51     "NOT_FOUND_ERR",
52     "NOT_SUPPORTED_ERR",
53     "INUSE_ATTRIBUTE_ERR",
54     "INVALID_STATE_ERR",
55     "SYNTAX_ERR",
56     "INVALID_MODIFICATION_ERR",
57     "NAMESPACE_ERR",
58     "INVALID_ACCESS_ERR",
59     "VALIDATION_ERR",
60     "TYPE_MISMATCH_ERR",
61     "SECURITY_ERR",
62     "NETWORK_ERR",
63     "ABORT_ERR",
64     "URL_MISMATCH_ERR",
65     "QUOTA_EXCEEDED_ERR"
66 };
67 
68 static const char* const rangeExceptionNames[] = {
69     "BAD_BOUNDARYPOINTS_ERR",
70     "INVALID_NODE_TYPE_ERR"
71 };
72 
73 static const char* const eventExceptionNames[] = {
74     "UNSPECIFIED_EVENT_TYPE_ERR"
75 };
76 
77 static const char* const xmlHttpRequestExceptionNames[] = {
78     "NETWORK_ERR",
79     "ABORT_ERR"
80 };
81 
82 #if ENABLE(XPATH)
83 static const char* const xpathExceptionNames[] = {
84     "INVALID_EXPRESSION_ERR",
85     "TYPE_ERR"
86 };
87 #endif
88 
89 #if ENABLE(SVG)
90 static const char* const svgExceptionNames[] = {
91     "SVG_WRONG_TYPE_ERR",
92     "SVG_INVALID_VALUE_ERR",
93     "SVG_MATRIX_NOT_INVERTABLE"
94 };
95 #endif
96 
getExceptionCodeDescription(ExceptionCode ec,ExceptionCodeDescription & description)97 void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& description)
98 {
99     ASSERT(ec);
100 
101     const char* typeName;
102     int code = ec;
103     const char* const* nameTable;
104     int nameTableSize;
105     int nameTableOffset;
106     ExceptionType type;
107 
108     if (code >= RangeException::RangeExceptionOffset && code <= RangeException::RangeExceptionMax) {
109         type = RangeExceptionType;
110         typeName = "DOM Range";
111         code -= RangeException::RangeExceptionOffset;
112         nameTable = rangeExceptionNames;
113         nameTableSize = sizeof(rangeExceptionNames) / sizeof(rangeExceptionNames[0]);
114         nameTableOffset = RangeException::BAD_BOUNDARYPOINTS_ERR;
115     } else if (code >= EventException::EventExceptionOffset && code <= EventException::EventExceptionMax) {
116         type = EventExceptionType;
117         typeName = "DOM Events";
118         code -= EventException::EventExceptionOffset;
119         nameTable = eventExceptionNames;
120         nameTableSize = sizeof(eventExceptionNames) / sizeof(eventExceptionNames[0]);
121         nameTableOffset = EventException::UNSPECIFIED_EVENT_TYPE_ERR;
122     } else if (code >= XMLHttpRequestException::XMLHttpRequestExceptionOffset && code <= XMLHttpRequestException::XMLHttpRequestExceptionMax) {
123         type = XMLHttpRequestExceptionType;
124         typeName = "XMLHttpRequest";
125         code -= XMLHttpRequestException::XMLHttpRequestExceptionOffset;
126         nameTable = xmlHttpRequestExceptionNames;
127         nameTableSize = sizeof(xmlHttpRequestExceptionNames) / sizeof(xmlHttpRequestExceptionNames[0]);
128         // XMLHttpRequest exception codes start with 101 and we don't want 100 empty elements in the name array
129         nameTableOffset = XMLHttpRequestException::NETWORK_ERR;
130 #if ENABLE(XPATH)
131     } else if (code >= XPathException::XPathExceptionOffset && code <= XPathException::XPathExceptionMax) {
132         type = XPathExceptionType;
133         typeName = "DOM XPath";
134         code -= XPathException::XPathExceptionOffset;
135         nameTable = xpathExceptionNames;
136         nameTableSize = sizeof(xpathExceptionNames) / sizeof(xpathExceptionNames[0]);
137         // XPath exception codes start with 51 and we don't want 51 empty elements in the name array
138         nameTableOffset = XPathException::INVALID_EXPRESSION_ERR;
139 #endif
140 #if ENABLE(SVG)
141     } else if (code >= SVGException::SVGExceptionOffset && code <= SVGException::SVGExceptionMax) {
142         type = SVGExceptionType;
143         typeName = "DOM SVG";
144         code -= SVGException::SVGExceptionOffset;
145         nameTable = svgExceptionNames;
146         nameTableSize = sizeof(svgExceptionNames) / sizeof(svgExceptionNames[0]);
147         nameTableOffset = SVGException::SVG_WRONG_TYPE_ERR;
148 #endif
149     } else {
150         type = DOMExceptionType;
151         typeName = "DOM";
152         nameTable = exceptionNames;
153         nameTableSize = sizeof(exceptionNames) / sizeof(exceptionNames[0]);
154         nameTableOffset = INDEX_SIZE_ERR;
155     }
156 
157     description.typeName = typeName;
158     description.name = (ec >= nameTableOffset && ec - nameTableOffset < nameTableSize) ? nameTable[ec - nameTableOffset] : 0;
159     description.code = code;
160     description.type = type;
161 
162     // All exceptions used in the DOM code should have names.
163     ASSERT(description.name);
164 }
165 
166 } // namespace WebCore
167