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

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

Issue 72363002: Rename es => exceptionState in other than bindings/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Retry Created 7 years, 1 month 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/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBRequest.cpp » ('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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const 57 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
58 { 58 {
59 IDB_TRACE("IDBObjectStore::indexNames"); 59 IDB_TRACE("IDBObjectStore::indexNames");
60 RefPtr<DOMStringList> indexNames = DOMStringList::create(); 60 RefPtr<DOMStringList> indexNames = DOMStringList::create();
61 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) 61 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it)
62 indexNames->append(it->value.name); 62 indexNames->append(it->value.name);
63 indexNames->sort(); 63 indexNames->sort();
64 return indexNames.release(); 64 return indexNames.release();
65 } 65 }
66 66
67 PassRefPtr<IDBRequest> IDBObjectStore::get(ExecutionContext* context, const Scri ptValue& key, ExceptionState& es) 67 PassRefPtr<IDBRequest> IDBObjectStore::get(ExecutionContext* context, const Scri ptValue& key, ExceptionState& exceptionState)
68 { 68 {
69 IDB_TRACE("IDBObjectStore::get"); 69 IDB_TRACE("IDBObjectStore::get");
70 if (isDeleted()) { 70 if (isDeleted()) {
71 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 71 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
72 return 0; 72 return 0;
73 } 73 }
74 if (m_transaction->isFinished()) { 74 if (m_transaction->isFinished()) {
75 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 75 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
76 return 0; 76 return 0;
77 } 77 }
78 if (!m_transaction->isActive()) { 78 if (!m_transaction->isActive()) {
79 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 79 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
80 return 0; 80 return 0;
81 } 81 }
82 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es ); 82 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
83 if (es.hadException()) 83 if (exceptionState.hadException())
84 return 0; 84 return 0;
85 if (!keyRange) { 85 if (!keyRange) {
86 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); 86 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
87 return 0; 87 return 0;
88 } 88 }
89 89
90 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 90 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
91 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request); 91 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request);
92 return request.release(); 92 return request.release();
93 } 93 }
94 94
95 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys) 95 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys)
96 { 96 {
(...skipping 11 matching lines...) Expand all
108 } else { 108 } else {
109 ASSERT(indexMetadata.multiEntry); 109 ASSERT(indexMetadata.multiEntry);
110 ASSERT(indexKey->type() == IDBKey::ArrayType); 110 ASSERT(indexKey->type() == IDBKey::ArrayType);
111 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); 111 indexKey = IDBKey::createMultiEntryArray(indexKey->array());
112 112
113 for (size_t i = 0; i < indexKey->array().size(); ++i) 113 for (size_t i = 0; i < indexKey->array().size(); ++i)
114 indexKeys->append(indexKey->array()[i]); 114 indexKeys->append(indexKey->array()[i]);
115 } 115 }
116 } 116 }
117 117
118 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& es) 118 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& exceptionState)
119 { 119 {
120 IDB_TRACE("IDBObjectStore::add"); 120 IDB_TRACE("IDBObjectStore::add");
121 return put(IDBDatabaseBackendInterface::AddOnly, IDBAny::create(this), state , value, key, es); 121 return put(IDBDatabaseBackendInterface::AddOnly, IDBAny::create(this), state , value, key, exceptionState);
122 } 122 }
123 123
124 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& es) 124 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& exceptionState)
125 { 125 {
126 IDB_TRACE("IDBObjectStore::put"); 126 IDB_TRACE("IDBObjectStore::put");
127 return put(IDBDatabaseBackendInterface::AddOrUpdate, IDBAny::create(this), s tate, value, key, es); 127 return put(IDBDatabaseBackendInterface::AddOrUpdate, IDBAny::create(this), s tate, value, key, exceptionState);
128 } 128 }
129 129
130 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, cons t ScriptValue& keyValue, ExceptionState& es) 130 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, cons t ScriptValue& keyValue, ExceptionState& exceptionState)
131 { 131 {
132 ExecutionContext* context = state->executionContext(); 132 ExecutionContext* context = state->executionContext();
133 DOMRequestState requestState(context); 133 DOMRequestState requestState(context);
134 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 134 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue);
135 return put(putMode, source, state, value, key.release(), es); 135 return put(putMode, source, state, value, key.release(), exceptionState);
136 } 136 }
137 137
138 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass RefPtr<IDBKey> prpKey, ExceptionState& es) 138 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass RefPtr<IDBKey> prpKey, ExceptionState& exceptionState)
139 { 139 {
140 RefPtr<IDBKey> key = prpKey; 140 RefPtr<IDBKey> key = prpKey;
141 if (isDeleted()) { 141 if (isDeleted()) {
142 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
143 return 0; 143 return 0;
144 } 144 }
145 if (m_transaction->isFinished()) { 145 if (m_transaction->isFinished()) {
146 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 146 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
147 return 0; 147 return 0;
148 } 148 }
149 if (!m_transaction->isActive()) { 149 if (!m_transaction->isActive()) {
150 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 150 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
151 return 0; 151 return 0;
152 } 152 }
153 if (m_transaction->isReadOnly()) { 153 if (m_transaction->isReadOnly()) {
154 es.throwUninformativeAndGenericDOMException(ReadOnlyError); 154 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError);
155 return 0; 155 return 0;
156 } 156 }
157 157
158 // FIXME: Make SerializedScriptValue::create etc take an ExceptionState or u se ScriptState::setDOMException. 158 // FIXME: Make SerializedScriptValue::create etc take an ExceptionState or u se ScriptState::setDOMException.
159 bool didThrow = false; 159 bool didThrow = false;
160 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, didThrow, state); 160 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::creat e(value, didThrow, state);
161 if (didThrow) 161 if (didThrow)
162 return 0; 162 return 0;
163 163
164 if (serializedValue->containsBlobs()) { 164 if (serializedValue->containsBlobs()) {
165 // FIXME: Add Blob/File/FileList support 165 // FIXME: Add Blob/File/FileList support
166 es.throwUninformativeAndGenericDOMException(DataCloneError); 166 exceptionState.throwUninformativeAndGenericDOMException(DataCloneError);
167 return 0; 167 return 0;
168 } 168 }
169 169
170 const IDBKeyPath& keyPath = m_metadata.keyPath; 170 const IDBKeyPath& keyPath = m_metadata.keyPath;
171 const bool usesInLineKeys = !keyPath.isNull(); 171 const bool usesInLineKeys = !keyPath.isNull();
172 const bool hasKeyGenerator = autoIncrement(); 172 const bool hasKeyGenerator = autoIncrement();
173 173
174 ExecutionContext* context = state->executionContext(); 174 ExecutionContext* context = state->executionContext();
175 DOMRequestState requestState(context); 175 DOMRequestState requestState(context);
176 176
177 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) { 177 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) {
178 es.throwDOMException(DataError, "The object store uses in-line keys and the key parameter was provided."); 178 exceptionState.throwDOMException(DataError, "The object store uses in-li ne keys and the key parameter was provided.");
179 return 0; 179 return 0;
180 } 180 }
181 if (!usesInLineKeys && !hasKeyGenerator && !key) { 181 if (!usesInLineKeys && !hasKeyGenerator && !key) {
182 es.throwDOMException(DataError, "The object store uses out-of-line keys and has no key generator and the key parameter was not provided."); 182 exceptionState.throwDOMException(DataError, "The object store uses out-o f-line keys and has no key generator and the key parameter was not provided.");
183 return 0; 183 return 0;
184 } 184 }
185 if (usesInLineKeys) { 185 if (usesInLineKeys) {
186 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath); 186 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath);
187 if (keyPathKey && !keyPathKey->isValid()) { 187 if (keyPathKey && !keyPathKey->isValid()) {
188 es.throwDOMException(DataError, "Evaluating the object store's key p ath yielded a value that is not a valid key."); 188 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path yielded a value that is not a valid key.");
189 return 0; 189 return 0;
190 } 190 }
191 if (!hasKeyGenerator && !keyPathKey) { 191 if (!hasKeyGenerator && !keyPathKey) {
192 es.throwDOMException(DataError, "Evaluating the object store's key p ath did not yield a value."); 192 exceptionState.throwDOMException(DataError, "Evaluating the object s tore's key path did not yield a value.");
193 return 0; 193 return 0;
194 } 194 }
195 if (hasKeyGenerator && !keyPathKey) { 195 if (hasKeyGenerator && !keyPathKey) {
196 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) { 196 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
197 es.throwDOMException(DataError, "A generated key could not be in serted into the value."); 197 exceptionState.throwDOMException(DataError, "A generated key cou ld not be inserted into the value.");
198 return 0; 198 return 0;
199 } 199 }
200 } 200 }
201 if (keyPathKey) 201 if (keyPathKey)
202 key = keyPathKey; 202 key = keyPathKey;
203 } 203 }
204 if (key && !key->isValid()) { 204 if (key && !key->isValid()) {
205 es.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage); 205 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro rMessage);
206 return 0; 206 return 0;
207 } 207 }
208 208
209 Vector<int64_t> indexIds; 209 Vector<int64_t> indexIds;
210 Vector<IndexKeys> indexKeys; 210 Vector<IndexKeys> indexKeys;
211 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 211 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
212 IndexKeys keys; 212 IndexKeys keys;
213 generateIndexKeysForValue(&requestState, it->value, value, &keys); 213 generateIndexKeysForValue(&requestState, it->value, value, &keys);
214 indexIds.append(it->key); 214 indexIds.append(it->key);
215 indexKeys.append(keys); 215 indexKeys.append(keys);
216 } 216 }
217 217
218 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 218 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
219 Vector<char> wireBytes; 219 Vector<char> wireBytes;
220 serializedValue->toWireBytes(wireBytes); 220 serializedValue->toWireBytes(wireBytes);
221 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 221 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
222 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys); 222 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys);
223 return request.release(); 223 return request.release();
224 } 224 }
225 225
226 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& es) 226 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState)
227 { 227 {
228 IDB_TRACE("IDBObjectStore::delete"); 228 IDB_TRACE("IDBObjectStore::delete");
229 if (isDeleted()) { 229 if (isDeleted()) {
230 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 230 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
231 return 0; 231 return 0;
232 } 232 }
233 if (m_transaction->isFinished()) { 233 if (m_transaction->isFinished()) {
234 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 234 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
235 return 0; 235 return 0;
236 } 236 }
237 if (!m_transaction->isActive()) { 237 if (!m_transaction->isActive()) {
238 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 238 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
239 return 0; 239 return 0;
240 } 240 }
241 if (m_transaction->isReadOnly()) { 241 if (m_transaction->isReadOnly()) {
242 es.throwUninformativeAndGenericDOMException(ReadOnlyError); 242 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError);
243 return 0; 243 return 0;
244 } 244 }
245 245
246 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es ); 246 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, ex ceptionState);
247 if (es.hadException()) 247 if (exceptionState.hadException())
248 return 0; 248 return 0;
249 if (!keyRange) { 249 if (!keyRange) {
250 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); 250 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRange ErrorMessage);
251 return 0; 251 return 0;
252 } 252 }
253 253
254 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 254 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
255 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); 255 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request);
256 return request.release(); 256 return request.release();
257 } 257 }
258 258
259 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& es) 259 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, Exceptio nState& exceptionState)
260 { 260 {
261 IDB_TRACE("IDBObjectStore::clear"); 261 IDB_TRACE("IDBObjectStore::clear");
262 if (isDeleted()) { 262 if (isDeleted()) {
263 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 263 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
264 return 0; 264 return 0;
265 } 265 }
266 if (m_transaction->isFinished()) { 266 if (m_transaction->isFinished()) {
267 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 267 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
268 return 0; 268 return 0;
269 } 269 }
270 if (!m_transaction->isActive()) { 270 if (!m_transaction->isActive()) {
271 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 271 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
272 return 0; 272 return 0;
273 } 273 }
274 if (m_transaction->isReadOnly()) { 274 if (m_transaction->isReadOnly()) {
275 es.throwUninformativeAndGenericDOMException(ReadOnlyError); 275 exceptionState.throwUninformativeAndGenericDOMException(ReadOnlyError);
276 return 0; 276 return 0;
277 } 277 }
278 278
279 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 279 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
280 backendDB()->clear(m_transaction->id(), id(), request); 280 backendDB()->clear(m_transaction->id(), id(), request);
281 return request.release(); 281 return request.release();
282 } 282 }
283 283
284 namespace { 284 namespace {
285 // This class creates the index keys for a given index by extracting 285 // This class creates the index keys for a given index by extracting
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 344
345 } 345 }
346 346
347 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend; 347 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend;
348 const int64_t m_transactionId; 348 const int64_t m_transactionId;
349 const int64_t m_objectStoreId; 349 const int64_t m_objectStoreId;
350 const IDBIndexMetadata m_indexMetadata; 350 const IDBIndexMetadata m_indexMetadata;
351 }; 351 };
352 } 352 }
353 353
354 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, const Dictionary& options, ExceptionS tate& es) 354 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, const Dictionary& options, ExceptionS tate& exceptionState)
355 { 355 {
356 bool unique = false; 356 bool unique = false;
357 options.get("unique", unique); 357 options.get("unique", unique);
358 358
359 bool multiEntry = false; 359 bool multiEntry = false;
360 options.get("multiEntry", multiEntry); 360 options.get("multiEntry", multiEntry);
361 361
362 return createIndex(context, name, keyPath, unique, multiEntry, es); 362 return createIndex(context, name, keyPath, unique, multiEntry, exceptionStat e);
363 } 363 }
364 364
365 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excepti onState& es) 365 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, cons t String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, Excepti onState& exceptionState)
366 { 366 {
367 IDB_TRACE("IDBObjectStore::createIndex"); 367 IDB_TRACE("IDBObjectStore::createIndex");
368 if (!m_transaction->isVersionChange()) { 368 if (!m_transaction->isVersionChange()) {
369 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra nsactionErrorMessage); 369 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage);
370 return 0; 370 return 0;
371 } 371 }
372 if (isDeleted()) { 372 if (isDeleted()) {
373 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 373 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
374 return 0; 374 return 0;
375 } 375 }
376 if (m_transaction->isFinished()) { 376 if (m_transaction->isFinished()) {
377 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 377 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
378 return 0; 378 return 0;
379 } 379 }
380 if (!m_transaction->isActive()) { 380 if (!m_transaction->isActive()) {
381 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 381 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
382 return 0; 382 return 0;
383 } 383 }
384 if (!keyPath.isValid()) { 384 if (!keyPath.isValid()) {
385 es.throwDOMException(SyntaxError, "The keyPath argument contains an inva lid key path."); 385 exceptionState.throwDOMException(SyntaxError, "The keyPath argument cont ains an invalid key path.");
386 return 0; 386 return 0;
387 } 387 }
388 if (name.isNull()) { 388 if (name.isNull()) {
389 es.throwUninformativeAndGenericTypeError(); 389 exceptionState.throwUninformativeAndGenericTypeError();
390 return 0; 390 return 0;
391 } 391 }
392 if (containsIndex(name)) { 392 if (containsIndex(name)) {
393 es.throwDOMException(ConstraintError, "An index with the specified name already exists."); 393 exceptionState.throwDOMException(ConstraintError, "An index with the spe cified name already exists.");
394 return 0; 394 return 0;
395 } 395 }
396 396
397 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { 397 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
398 es.throwDOMException(InvalidAccessError, "The keyPath argument was an ar ray and the multiEntry option is true."); 398 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argume nt was an array and the multiEntry option is true.");
399 return 0; 399 return 0;
400 } 400 }
401 401
402 int64_t indexId = m_metadata.maxIndexId + 1; 402 int64_t indexId = m_metadata.maxIndexId + 1;
403 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry); 403 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
404 404
405 ++m_metadata.maxIndexId; 405 ++m_metadata.maxIndexId;
406 406
407 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 407 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
408 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 408 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
409 m_indexMap.set(name, index); 409 m_indexMap.set(name, index);
410 m_metadata.indexes.set(indexId, metadata); 410 m_metadata.indexes.set(indexId, metadata);
411 m_transaction->db()->indexCreated(id(), metadata); 411 m_transaction->db()->indexCreated(id(), metadata);
412 412
413 ASSERT(!es.hadException()); 413 ASSERT(!exceptionState.hadException());
414 if (es.hadException()) 414 if (exceptionState.hadException())
415 return 0; 415 return 0;
416 416
417 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IndexedDB::CursorNext, IDBDatabaseBackendInterface::PreemptiveTask); 417 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IndexedDB::CursorNext, IDBDatabaseBackendInterface::PreemptiveTask);
418 indexRequest->preventPropagation(); 418 indexRequest->preventPropagation();
419 419
420 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 420 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
421 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata); 421 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata);
422 indexRequest->setOnsuccess(indexPopulator); 422 indexRequest->setOnsuccess(indexPopulator);
423 423
424 return index.release(); 424 return index.release();
425 } 425 }
426 426
427 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e s) 427 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e xceptionState)
428 { 428 {
429 IDB_TRACE("IDBObjectStore::index"); 429 IDB_TRACE("IDBObjectStore::index");
430 if (isDeleted()) { 430 if (isDeleted()) {
431 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 431 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
432 return 0; 432 return 0;
433 } 433 }
434 if (m_transaction->isFinished()) { 434 if (m_transaction->isFinished()) {
435 es.throwDOMException(InvalidStateError, IDBDatabase::transactionFinished ErrorMessage); 435 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transac tionFinishedErrorMessage);
436 return 0; 436 return 0;
437 } 437 }
438 438
439 IDBIndexMap::iterator it = m_indexMap.find(name); 439 IDBIndexMap::iterator it = m_indexMap.find(name);
440 if (it != m_indexMap.end()) 440 if (it != m_indexMap.end())
441 return it->value; 441 return it->value;
442 442
443 int64_t indexId = findIndexId(name); 443 int64_t indexId = findIndexId(name);
444 if (indexId == IDBIndexMetadata::InvalidId) { 444 if (indexId == IDBIndexMetadata::InvalidId) {
445 es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage ); 445 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex ErrorMessage);
446 return 0; 446 return 0;
447 } 447 }
448 448
449 const IDBIndexMetadata* indexMetadata(0); 449 const IDBIndexMetadata* indexMetadata(0);
450 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 450 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
451 if (it->value.name == name) { 451 if (it->value.name == name) {
452 indexMetadata = &it->value; 452 indexMetadata = &it->value;
453 break; 453 break;
454 } 454 }
455 } 455 }
456 ASSERT(indexMetadata); 456 ASSERT(indexMetadata);
457 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); 457 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId);
458 458
459 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get()); 459 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get());
460 m_indexMap.set(name, index); 460 m_indexMap.set(name, index);
461 return index.release(); 461 return index.release();
462 } 462 }
463 463
464 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es) 464 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& exceptionSt ate)
465 { 465 {
466 IDB_TRACE("IDBObjectStore::deleteIndex"); 466 IDB_TRACE("IDBObjectStore::deleteIndex");
467 if (!m_transaction->isVersionChange()) { 467 if (!m_transaction->isVersionChange()) {
468 es.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTra nsactionErrorMessage); 468 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVers ionChangeTransactionErrorMessage);
469 return; 469 return;
470 } 470 }
471 if (isDeleted()) { 471 if (isDeleted()) {
472 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 472 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
473 return; 473 return;
474 } 474 }
475 if (m_transaction->isFinished()) { 475 if (m_transaction->isFinished()) {
476 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 476 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
477 return; 477 return;
478 } 478 }
479 if (!m_transaction->isActive()) { 479 if (!m_transaction->isActive()) {
480 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 480 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
481 return; 481 return;
482 } 482 }
483 int64_t indexId = findIndexId(name); 483 int64_t indexId = findIndexId(name);
484 if (indexId == IDBIndexMetadata::InvalidId) { 484 if (indexId == IDBIndexMetadata::InvalidId) {
485 es.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage ); 485 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndex ErrorMessage);
486 return; 486 return;
487 } 487 }
488 488
489 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); 489 backendDB()->deleteIndex(m_transaction->id(), id(), indexId);
490 490
491 m_metadata.indexes.remove(indexId); 491 m_metadata.indexes.remove(indexId);
492 m_transaction->db()->indexDeleted(id(), indexId); 492 m_transaction->db()->indexDeleted(id(), indexId);
493 IDBIndexMap::iterator it = m_indexMap.find(name); 493 IDBIndexMap::iterator it = m_indexMap.find(name);
494 if (it != m_indexMap.end()) { 494 if (it != m_indexMap.end()) {
495 it->value->markDeleted(); 495 it->value->markDeleted();
496 m_indexMap.remove(name); 496 m_indexMap.remove(name);
497 } 497 }
498 } 498 }
499 499
500 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, con st ScriptValue& range, const String& directionString, ExceptionState& es) 500 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, con st ScriptValue& range, const String& directionString, ExceptionState& exceptionS tate)
501 { 501 {
502 IDB_TRACE("IDBObjectStore::openCursor"); 502 IDB_TRACE("IDBObjectStore::openCursor");
503 if (isDeleted()) { 503 if (isDeleted()) {
504 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 504 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
505 return 0; 505 return 0;
506 } 506 }
507 if (m_transaction->isFinished()) { 507 if (m_transaction->isFinished()) {
508 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 508 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
509 return 0; 509 return 0;
510 } 510 }
511 if (!m_transaction->isActive()) { 511 if (!m_transaction->isActive()) {
512 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 512 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
513 return 0; 513 return 0;
514 } 514 }
515 515
516 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); 516 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, exceptionState);
517 if (es.hadException()) 517 if (exceptionState.hadException())
518 return 0; 518 return 0;
519 519
520 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); 520 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
521 if (es.hadException()) 521 if (exceptionState.hadException())
522 return 0; 522 return 0;
523 523
524 return openCursor(context, keyRange, direction, IDBDatabaseBackendInterface: :NormalTask); 524 return openCursor(context, keyRange, direction, IDBDatabaseBackendInterface: :NormalTask);
525 } 525 }
526 526
527 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, IndexedDB::CursorDirection direction, IDBDatabaseBac kendInterface::TaskType taskType) 527 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, Pas sRefPtr<IDBKeyRange> range, IndexedDB::CursorDirection direction, IDBDatabaseBac kendInterface::TaskType taskType)
528 { 528 {
529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
530 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 530 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
531 531
532 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, request); 532 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, taskType, request);
533 return request.release(); 533 return request.release();
534 } 534 }
535 535
536 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& es) 536 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& excepti onState)
537 { 537 {
538 IDB_TRACE("IDBObjectStore::openKeyCursor"); 538 IDB_TRACE("IDBObjectStore::openKeyCursor");
539 if (isDeleted()) { 539 if (isDeleted()) {
540 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 540 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
541 return 0; 541 return 0;
542 } 542 }
543 if (m_transaction->isFinished()) { 543 if (m_transaction->isFinished()) {
544 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 544 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
545 return 0; 545 return 0;
546 } 546 }
547 if (!m_transaction->isActive()) { 547 if (!m_transaction->isActive()) {
548 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 548 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
549 return 0; 549 return 0;
550 } 550 }
551 551
552 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); 552 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, exceptionState);
553 if (es.hadException()) 553 if (exceptionState.hadException())
554 return 0; 554 return 0;
555 555
556 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); 556 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
557 if (es.hadException()) 557 if (exceptionState.hadException())
558 return 0; 558 return 0;
559 559
560 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 560 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
561 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); 561 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
562 562
563 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request) ; 563 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request) ;
564 return request.release(); 564 return request.release();
565 } 565 }
566 566
567 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& es) 567 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const Sc riptValue& range, ExceptionState& exceptionState)
568 { 568 {
569 IDB_TRACE("IDBObjectStore::count"); 569 IDB_TRACE("IDBObjectStore::count");
570 if (isDeleted()) { 570 if (isDeleted()) {
571 es.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedE rrorMessage); 571 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectS toreDeletedErrorMessage);
572 return 0; 572 return 0;
573 } 573 }
574 if (m_transaction->isFinished()) { 574 if (m_transaction->isFinished()) {
575 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); 575 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionFinishedErrorMessage);
576 return 0; 576 return 0;
577 } 577 }
578 if (!m_transaction->isActive()) { 578 if (!m_transaction->isActive()) {
579 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); 579 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase:: transactionInactiveErrorMessage);
580 return 0; 580 return 0;
581 } 581 }
582 582
583 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); 583 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
584 if (es.hadException()) 584 if (exceptionState.hadException())
585 return 0; 585 return 0;
586 586
587 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 587 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
588 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange, request); 588 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, k eyRange, request);
589 return request.release(); 589 return request.release();
590 } 590 }
591 591
592 void IDBObjectStore::transactionFinished() 592 void IDBObjectStore::transactionFinished()
593 { 593 {
594 ASSERT(m_transaction->isFinished()); 594 ASSERT(m_transaction->isFinished());
(...skipping 12 matching lines...) Expand all
607 } 607 }
608 return IDBIndexMetadata::InvalidId; 608 return IDBIndexMetadata::InvalidId;
609 } 609 }
610 610
611 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const 611 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const
612 { 612 {
613 return m_transaction->backendDB(); 613 return m_transaction->backendDB();
614 } 614 }
615 615
616 } // namespace WebCore 616 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBObjectStore.h ('k') | Source/modules/indexeddb/IDBRequest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698