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

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

Issue 18580013: IndexedDB: Make DOMException messages more useful. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Specific message for inactive transactions Created 7 years, 5 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 | « no previous file | Source/modules/indexeddb/IDBDatabase.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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 IDBAny* IDBCursor::source() const 120 IDBAny* IDBCursor::source() const
121 { 121 {
122 return m_source.get(); 122 return m_source.get();
123 } 123 }
124 124
125 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionState& es) 125 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionState& es)
126 { 126 {
127 IDB_TRACE("IDBCursor::update"); 127 IDB_TRACE("IDBCursor::update");
128 128
129 if (!m_gotValue || isKeyCursor() || isDeleted()) { 129 if (!m_gotValue) {
130 es.throwDOMException(InvalidStateError); 130 es.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage );
131 return 0;
132 }
133 if (isKeyCursor()) {
134 es.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMes sage);
135 return 0;
136 }
137 if (isDeleted()) {
138 es.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorM essage);
139 return 0;
140 }
141 if (m_transaction->isFinished()) {
142 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
131 return 0; 143 return 0;
132 } 144 }
133 if (!m_transaction->isActive()) { 145 if (!m_transaction->isActive()) {
134 es.throwDOMException(TransactionInactiveError); 146 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
135 return 0; 147 return 0;
136 } 148 }
137 if (m_transaction->isReadOnly()) { 149 if (m_transaction->isReadOnly()) {
138 es.throwDOMException(ReadOnlyError); 150 es.throwDOMException(ReadOnlyError);
139 return 0; 151 return 0;
140 } 152 }
141 153
142 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); 154 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore();
143 const IDBKeyPath& keyPath = objectStore->metadata().keyPath; 155 const IDBKeyPath& keyPath = objectStore->metadata().keyPath;
144 const bool usesInLineKeys = !keyPath.isNull(); 156 const bool usesInLineKeys = !keyPath.isNull();
145 if (usesInLineKeys) { 157 if (usesInLineKeys) {
146 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(m_requ est->requestState(), value, keyPath); 158 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(m_requ est->requestState(), value, keyPath);
147 if (!keyPathKey || !keyPathKey->isEqual(m_currentPrimaryKey.get())) { 159 if (!keyPathKey || !keyPathKey->isEqual(m_currentPrimaryKey.get())) {
148 es.throwDOMException(DataError); 160 es.throwDOMException(DataError, "The effective object store of this cursor uses in-line keys and evaluating the key path of the value parameter resu lts in a different value than the cursor's effective key.");
149 return 0; 161 return 0;
150 } 162 }
151 } 163 }
152 164
153 return objectStore->put(IDBDatabaseBackendInterface::CursorUpdate, IDBAny::c reate(this), state, value, m_currentPrimaryKey, es); 165 return objectStore->put(IDBDatabaseBackendInterface::CursorUpdate, IDBAny::c reate(this), state, value, m_currentPrimaryKey, es);
154 } 166 }
155 167
156 void IDBCursor::advance(unsigned long count, ExceptionState& es) 168 void IDBCursor::advance(unsigned long count, ExceptionState& es)
157 { 169 {
158 IDB_TRACE("IDBCursor::advance"); 170 IDB_TRACE("IDBCursor::advance");
159 if (!m_gotValue || isDeleted()) { 171 if (!m_gotValue) {
160 es.throwDOMException(InvalidStateError); 172 es.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage );
173 return;
174 }
175 if (isDeleted()) {
176 es.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorM essage);
161 return; 177 return;
162 } 178 }
163 179
180 if (m_transaction->isFinished()) {
181 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
182 return;
183 }
164 if (!m_transaction->isActive()) { 184 if (!m_transaction->isActive()) {
165 es.throwDOMException(TransactionInactiveError); 185 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
166 return; 186 return;
167 } 187 }
168 188
169 if (!count) { 189 if (!count) {
170 es.throwTypeError(); 190 es.throwTypeError();
171 return; 191 return;
172 } 192 }
173 193
174 m_request->setPendingCursor(this); 194 m_request->setPendingCursor(this);
175 m_gotValue = false; 195 m_gotValue = false;
176 m_backend->advance(count, m_request); 196 m_backend->advance(count, m_request);
177 } 197 }
178 198
179 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionState& es) 199 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionState& es)
180 { 200 {
181 DOMRequestState requestState(context); 201 DOMRequestState requestState(context);
182 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 202 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue);
183 continueFunction(key.release(), es); 203 continueFunction(key.release(), es);
184 } 204 }
185 205
186 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionState& es) 206 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionState& es)
187 { 207 {
188 IDB_TRACE("IDBCursor::continue"); 208 IDB_TRACE("IDBCursor::continue");
189 if (key && !key->isValid()) { 209 if (key && !key->isValid()) {
190 es.throwDOMException(DataError); 210 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
191 return; 211 return;
192 } 212 }
193 213
214 if (m_transaction->isFinished()) {
215 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
216 return;
217 }
194 if (!m_transaction->isActive()) { 218 if (!m_transaction->isActive()) {
195 es.throwDOMException(TransactionInactiveError); 219 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
196 return; 220 return;
197 } 221 }
198 222
199 if (!m_gotValue || isDeleted()) { 223 if (!m_gotValue) {
200 es.throwDOMException(InvalidStateError); 224 es.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage );
201 return; 225 return;
202 } 226 }
203 227
228 if (isDeleted()) {
229 es.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorM essage);
230 return;
231 }
232
204 if (key) { 233 if (key) {
205 ASSERT(m_currentKey); 234 ASSERT(m_currentKey);
206 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) { 235 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) {
207 if (!m_currentKey->isLessThan(key.get())) { 236 if (!m_currentKey->isLessThan(key.get())) {
208 es.throwDOMException(DataError); 237 es.throwDOMException(DataError, "The parameter is less than or e qual to this cursor's position.");
209 return; 238 return;
210 } 239 }
211 } else { 240 } else {
212 if (!key->isLessThan(m_currentKey.get())) { 241 if (!key->isLessThan(m_currentKey.get())) {
213 es.throwDOMException(DataError); 242 es.throwDOMException(DataError, "The parameter is greater than o r equal to this cursor's position.");
214 return; 243 return;
215 } 244 }
216 } 245 }
217 } 246 }
218 247
219 // FIXME: We're not using the context from when continue was called, which m eans the callback 248 // FIXME: We're not using the context from when continue was called, which m eans the callback
220 // will be on the original context openCursor was called on. Is this right? 249 // will be on the original context openCursor was called on. Is this right?
221 m_request->setPendingCursor(this); 250 m_request->setPendingCursor(this);
222 m_gotValue = false; 251 m_gotValue = false;
223 m_backend->continueFunction(key, m_request); 252 m_backend->continueFunction(key, m_request);
224 } 253 }
225 254
226 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionState& es) 255 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionState& es)
227 { 256 {
228 IDB_TRACE("IDBCursor::delete"); 257 IDB_TRACE("IDBCursor::delete");
258 if (m_transaction->isFinished()) {
259 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage);
260 return 0;
261 }
229 if (!m_transaction->isActive()) { 262 if (!m_transaction->isActive()) {
230 es.throwDOMException(TransactionInactiveError); 263 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage);
231 return 0; 264 return 0;
232 } 265 }
233 if (m_transaction->isReadOnly()) { 266 if (m_transaction->isReadOnly()) {
234 es.throwDOMException(ReadOnlyError); 267 es.throwDOMException(ReadOnlyError);
235 return 0; 268 return 0;
236 } 269 }
237 270
238 if (!m_gotValue || isKeyCursor() || isDeleted()) { 271 if (!m_gotValue) {
239 es.throwDOMException(InvalidStateError); 272 es.throwDOMException(InvalidStateError, IDBDatabase::noValueErrorMessage );
273 return 0;
274 }
275 if (isKeyCursor()) {
276 es.throwDOMException(InvalidStateError, IDBDatabase::isKeyCursorErrorMes sage);
277 return 0;
278 }
279 if (isDeleted()) {
280 es.throwDOMException(InvalidStateError, IDBDatabase::sourceDeletedErrorM essage);
240 return 0; 281 return 0;
241 } 282 }
242 283
243 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, es); 284 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, es);
244 ASSERT(!es); 285 ASSERT(!es);
245 286
246 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 287 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
247 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, request); 288 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, request);
248 return request.release(); 289 return request.release();
249 } 290 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 case IndexedDB::CursorPrevNoDuplicate: 374 case IndexedDB::CursorPrevNoDuplicate:
334 return IDBCursor::directionPrevUnique(); 375 return IDBCursor::directionPrevUnique();
335 376
336 default: 377 default:
337 ASSERT_NOT_REACHED(); 378 ASSERT_NOT_REACHED();
338 return IDBCursor::directionNext(); 379 return IDBCursor::directionNext();
339 } 380 }
340 } 381 }
341 382
342 } // namespace WebCore 383 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | Source/modules/indexeddb/IDBDatabase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698