17 #include <glog/logging.h> 19 #include <unordered_map> 29 constexpr
const char* kDefaultErrorName =
"Error";
32 #define DEFINE_MAPPING(code, msg, number) \ 33 { #code, msg, code, number } 34 struct ExceptionInfo {
39 } g_exception_map_[] = {
42 "The operation would yield an incorrect node tree.", 3),
46 "The string contains invalid characters.", 5),
54 "The string did not match the expected pattern.", 12),
58 "The operation is not allowed by Namespaces in XML.", 14),
60 "The object does not support the operation or argument.",
63 "The type of the object does not match the expected type.",
69 "The given URL does not match another URL.", 21),
73 "The node is incorrect or has an incorrect ancestor for " 82 "The operation failed for an unknown transient reason " 83 "(e.g. out of memory).",
86 "A mutation operation in a transaction failed because a " 87 "constraint was not satisfied.",
91 "A request was placed against a transaction which is " 92 "currently not active, or which is finished.",
95 "The mutating operation was attempted in a \"readonly\" " 99 "An attempt was made to open a database using a lower " 100 "version than the existing version.",
103 "The operation failed for an operation-specific reason.", 0),
105 "The request is not allowed by the user agent or the " 106 "platform in the current context, possibly because the " 107 "user denied permission.",
109 static_assert(
sizeof(g_exception_map_) /
sizeof(g_exception_map_[0]) ==
111 "Not all exceptions appear in map");
112 #undef DEFINE_MAPPING 115 for (
const auto& except : g_exception_map_) {
116 if (except.type == type) {
120 LOG(FATAL) <<
"Unknown exception type: " <<
type;
123 const ExceptionInfo* GetInfoByName(optional<std::string>
name) {
124 if (!name.has_value()) {
128 for (
const auto& except : g_exception_map_) {
129 if (except.name == name) {
137 int GetNativeCode(optional<std::string> name) {
138 const ExceptionInfo* except = GetInfoByName(name);
139 return except ? except->native_code : 0;
142 std::string GetDefaultMessage(optional<std::string> name) {
143 const ExceptionInfo* except = GetInfoByName(name);
144 return except ? except->message :
"";
150 : error_name(GetInfo(type).
name),
156 message(message.value_or(GetInfo(type).message)),
163 code(GetNativeCode(name)) {}
166 DOMException::~DOMException() {}
171 AddConstant(
"HIERARCHY_REQUEST_ERR",
174 AddConstant(
"INVALID_CHARACTER_ERR",
176 AddConstant(
"NO_MODIFICATION_ALLOWED_ERR",
178 AddConstant(
"NOT_FOUND_ERR", GetInfo(
NotFoundError).native_code);
182 AddConstant(
"SYNTAX_ERR", GetInfo(
SyntaxError).native_code);
183 AddConstant(
"INVALID_MODIFICATION_ERR",
185 AddConstant(
"NAMESPACE_ERR", GetInfo(
NamespaceError).native_code);
188 AddConstant(
"SECURITY_ERR", GetInfo(
SecurityError).native_code);
189 AddConstant(
"NETWORK_ERR", GetInfo(
NetworkError).native_code);
190 AddConstant(
"ABORT_ERR", GetInfo(
AbortError).native_code);
193 AddConstant(
"TIMEOUT_ERR", GetInfo(
TimeoutError).native_code);
194 AddConstant(
"INVALID_NODE_TYPE_ERR",
196 AddConstant(
"DATA_CLONE_ERR", GetInfo(
DataCloneError).native_code);
#define DEFINE_MAPPING(code, msg, number)
T value_or(U &&default_value) const &
DOMException(ExceptionCode type)
const std::string error_name
const std::string message