Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: Source/modules/indexeddb/IDBDatabaseException.cpp

Issue 17379011: Make ExceptionCode be an enum that does not encode the "code" property (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/indexeddb/IDBDatabaseException.h ('k') | public/web/WebStorageQuotaError.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 30
31 #include "modules/indexeddb/IDBDatabaseException.h" 31 #include "modules/indexeddb/IDBDatabaseException.h"
32 32
33 #include "core/dom/DOMCoreException.h"
34
33 namespace WebCore { 35 namespace WebCore {
34 36
35 static const struct IDBDatabaseExceptionNameDescription { 37 static const struct IDBDatabaseExceptionNameDescription {
36 const char* const name; 38 const char* const name;
37 const char* const description; 39 const char* const description;
38 const ExceptionCode code; 40 const int code;
39 } idbDatabaseExceptions[] = { 41 } idbDatabaseExceptions[] = {
40 // These are IDB-specific errors from the spec. 42 // These are IDB-specific errors from the spec.
41 { "UnknownError", "An unknown error occurred within Indexed Database.", 0 }, 43 { "UnknownError", "An unknown error occurred within Indexed Database.", 0 },
42 { "ConstraintError", "A mutation operation in the transaction failed because a constraint was not satisfied.", 0 }, 44 { "ConstraintError", "A mutation operation in the transaction failed because a constraint was not satisfied.", 0 },
43 { "DataError", "The data provided does not meet requirements.", 0 }, 45 { "DataError", "The data provided does not meet requirements.", 0 },
44 { "TransactionInactiveError", "A request was placed against a transaction wh ich is either currently not active, or which is finished.", 0 }, 46 { "TransactionInactiveError", "A request was placed against a transaction wh ich is either currently not active, or which is finished.", 0 },
45 { "ReadOnlyError", "A write operation was attempted in a read-only transacti on.", 0 }, 47 { "ReadOnlyError", "A write operation was attempted in a read-only transacti on.", 0 },
46 { "VersionError", "An attempt was made to open a database using a lower vers ion than the existing version.", 0 }, 48 { "VersionError", "An attempt was made to open a database using a lower vers ion than the existing version.", 0 },
47 49
48 // These are IDB-specific descriptions of generic DOM Exceptions when they a re thrown from IDB APIs 50 // These are IDB-specific descriptions of generic DOM Exceptions when they a re thrown from IDB APIs
49 { "NotFoundError", "An operation failed because the requested database objec t could not be found.", NOT_FOUND_ERR }, 51 { "NotFoundError", "An operation failed because the requested database objec t could not be found.", NotFoundErrorLegacyCode },
50 { "InvalidStateError", "An operation was called on an object on which it is not allowed or at a time when it is not allowed.", INVALID_STATE_ERR }, 52 { "InvalidStateError", "An operation was called on an object on which it is not allowed or at a time when it is not allowed.", InvalidStateErrorLegacyCode } ,
51 { "InvalidAccessError", "An invalid operation was performed on an object.", INVALID_ACCESS_ERR }, 53 { "InvalidAccessError", "An invalid operation was performed on an object.", InvalidAccessErrorLegacyCode },
52 { "AbortError", "The transaction was aborted, so the request cannot be fulfi lled.", ABORT_ERR }, 54 { "AbortError", "The transaction was aborted, so the request cannot be fulfi lled.", AbortErrorLegacyCode },
53 { "TimeoutError", "A lock for the transaction could not be obtained in a rea sonable time.", TIMEOUT_ERR }, // FIXME: This isn't used yet. 55 { "TimeoutError", "A lock for the transaction could not be obtained in a rea sonable time.", TimeoutErrorLegacyCode }, // FIXME: This isn't used yet.
54 { "QuotaExceededError", "The operation failed because there was not enough r emaining storage space, or the storage quota was reached and the user declined t o give more space to the database.", QUOTA_EXCEEDED_ERR }, 56 { "QuotaExceededError", "The operation failed because there was not enough r emaining storage space, or the storage quota was reached and the user declined t o give more space to the database.", QuotaExceededErrorLegacyCode },
55 { "SyntaxError", "The keypath argument contains an invalid key path.", SYNTA X_ERR }, 57 { "SyntaxError", "The keypath argument contains an invalid key path.", Synta xErrorLegacyCode },
56 { "DataCloneError", "The data being stored could not be cloned by the intern al structured cloning algorithm.", DATA_CLONE_ERR }, 58 { "DataCloneError", "The data being stored could not be cloned by the intern al structured cloning algorithm.", DataCloneErrorLegacyCode },
57 }; 59 };
58 60
59 static const IDBDatabaseExceptionNameDescription* getErrorEntry(ExceptionCode ec ) 61 static const IDBDatabaseExceptionNameDescription* getErrorEntry(ExceptionCode ec )
60 { 62 {
61 if (ec < IDBDatabaseException::IDBDatabaseExceptionOffset || ec > IDBDatabas eException::IDBDatabaseExceptionMax) 63 if (ec < IDBDatabaseException::IDBDatabaseExceptionOffset || ec > IDBDatabas eException::IDBDatabaseExceptionMax)
62 return 0; 64 return 0;
63 65
64 size_t tableSize = WTF_ARRAY_LENGTH(idbDatabaseExceptions); 66 size_t tableSize = WTF_ARRAY_LENGTH(idbDatabaseExceptions);
65 size_t tableIndex = ec - IDBDatabaseException::UnknownError; 67 size_t tableIndex = ec - IDBDatabaseException::UnknownError;
66 68
67 return tableIndex < tableSize ? &idbDatabaseExceptions[tableIndex] : 0; 69 return tableIndex < tableSize ? &idbDatabaseExceptions[tableIndex] : 0;
68 } 70 }
69 71
70 bool IDBDatabaseException::initializeDescription(ExceptionCode ec, ExceptionCode Description* description) 72 bool IDBDatabaseException::initializeDescription(ExceptionCode ec, ExceptionCode Description* description)
71 { 73 {
72 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec); 74 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec);
73 if (!entry) 75 if (!entry)
74 return false; 76 return false;
75 77
76 description->code = entry->code; 78 description->code = entry->code;
77 description->type = DOMCoreExceptionType; 79 description->type = DOMCoreExceptionType;
78 80
79 description->name = entry ? entry->name : 0; 81 description->name = entry->name;
80 description->description = entry ? entry->description : 0; 82 description->description = entry->description;
81 83
82 return true; 84 return true;
83 } 85 }
84 86
85 String IDBDatabaseException::getErrorName(ExceptionCode ec) 87 String IDBDatabaseException::getErrorName(ExceptionCode ec)
86 { 88 {
87 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec); 89 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec);
88 ASSERT(entry); 90 ASSERT(entry);
89 if (!entry) 91 if (!entry)
90 return "UnknownError"; 92 return "UnknownError";
91 93
92 return entry->name; 94 return entry->name;
93 } 95 }
94 96
95 String IDBDatabaseException::getErrorDescription(ExceptionCode ec) 97 String IDBDatabaseException::getErrorDescription(ExceptionCode ec)
96 { 98 {
97 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec); 99 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec);
98 ASSERT(entry); 100 ASSERT(entry);
99 if (!entry) 101 if (!entry)
100 return "Unknown error."; 102 return "Unknown error.";
101 103
102 return entry->description; 104 return entry->description;
103 } 105 }
104 106
105 ExceptionCode IDBDatabaseException::getLegacyErrorCode(ExceptionCode ec) 107 int IDBDatabaseException::getLegacyErrorCode(ExceptionCode ec)
106 { 108 {
107 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec); 109 const IDBDatabaseExceptionNameDescription* entry = getErrorEntry(ec);
108 ASSERT(entry); 110 ASSERT(entry);
109 111
110 return (entry && entry->code) ? entry->code : ec - IDBDatabaseExceptionOffse t; 112 return (entry && entry->code) ? entry->code : ec - IDBDatabaseExceptionOffse t;
111 } 113 }
112 114
113 } // namespace WebCore 115 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBDatabaseException.h ('k') | public/web/WebStorageQuotaError.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698