blob: 69babf1716038d63cd88a9c0ce24f7d3291b31b0 [file] [log] [blame]
jorlow@chromium.orge3865912010-05-26 15:39:35 +00001/*
2 * Copyright (C) 2010 Google 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 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +000025
jorlow@chromium.orge3865912010-05-26 15:39:35 +000026#include "config.h"
andreip@google.com63e33312010-08-03 19:20:09 +000027#include "IDBObjectStore.h"
jorlow@chromium.orge3865912010-05-26 15:39:35 +000028
jorlow@chromium.org9c02b652010-11-26 16:33:28 +000029#if ENABLE(INDEXED_DATABASE)
30
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +000031#include "DOMStringList.h"
jorlow@chromium.orge3865912010-05-26 15:39:35 +000032#include "IDBAny.h"
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +000033#include "IDBBindingUtilities.h"
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +000034#include "IDBCursorWithValue.h"
jsbell@chromium.orgddfcb6f2012-06-22 22:09:22 +000035#include "IDBDatabase.h"
jorlow@chromium.org9c02b652010-11-26 16:33:28 +000036#include "IDBDatabaseException.h"
jorlow@chromium.orgeb5eb5b2010-07-30 15:29:58 +000037#include "IDBIndex.h"
jorlow@chromium.orga815bc82010-07-12 10:00:45 +000038#include "IDBKey.h"
commit-queue@webkit.org67816382011-08-25 05:31:51 +000039#include "IDBKeyPath.h"
bulach@chromium.org51cb8ff2010-08-06 10:37:41 +000040#include "IDBKeyRange.h"
jorlow@chromium.org383e1542011-02-04 23:45:27 +000041#include "IDBTransaction.h"
beidson@apple.com1367e452013-09-30 20:32:21 +000042#include "Logging.h"
alecflett@chromium.org4759eef2012-10-17 22:57:30 +000043#include "ScriptExecutionContext.h"
jorlow@chromium.orge3865912010-05-26 15:39:35 +000044#include "SerializedScriptValue.h"
alecflett@chromium.org9d1da952013-02-15 21:01:49 +000045#include "SharedBuffer.h"
jorlow@chromium.orge3865912010-05-26 15:39:35 +000046
jorlow@chromium.orge3865912010-05-26 15:39:35 +000047namespace WebCore {
48
alecflett@chromium.org6d7e1482013-01-10 07:33:14 +000049IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransaction* transaction)
jsbell@chromium.orgddfcb6f2012-06-22 22:09:22 +000050 : m_metadata(metadata)
andreip@google.combccb32d2010-09-23 14:34:22 +000051 , m_transaction(transaction)
jsbell@chromium.org46990082012-06-15 22:49:04 +000052 , m_deleted(false)
jorlow@chromium.orge3865912010-05-26 15:39:35 +000053{
jorlow@chromium.org4e087e02010-09-30 16:55:46 +000054 ASSERT(m_transaction);
vitalyr@chromium.orgb6133032010-07-08 17:01:51 +000055 // We pass a reference to this object before it can be adopted.
56 relaxAdoptionRequirement();
jorlow@chromium.orge3865912010-05-26 15:39:35 +000057}
58
andreip@google.com63e33312010-08-03 19:20:09 +000059PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +000060{
beidson@apple.com1367e452013-09-30 20:32:21 +000061 LOG(StorageAPI, "IDBObjectStore::indexNames");
jsbell@chromium.orgddfcb6f2012-06-22 22:09:22 +000062 RefPtr<DOMStringList> indexNames = DOMStringList::create();
63 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it)
alecflett@chromium.orge33cc6b2012-11-01 18:07:22 +000064 indexNames->append(it->value.name);
jsbell@chromium.orgddfcb6f2012-06-22 22:09:22 +000065 indexNames->sort();
66 return indexNames.release();
jsbell@chromium.orgb6581b62012-05-17 23:03:05 +000067}
68
commit-queue@webkit.org205a6322012-04-21 00:16:48 +000069PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec)
jorlow@chromium.orge3865912010-05-26 15:39:35 +000070{
beidson@apple.com1367e452013-09-30 20:32:21 +000071 LOG(StorageAPI, "IDBObjectStore::get");
jsbell@chromium.org99332ea2012-06-21 00:31:41 +000072 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +000073 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org99332ea2012-06-21 00:31:41 +000074 return 0;
75 }
commit-queue@webkit.org205a6322012-04-21 00:16:48 +000076 if (!keyRange) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +000077 ec = IDBDatabaseException::DataError;
commit-queue@webkit.orga7e8f752011-10-24 20:51:02 +000078 return 0;
79 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +000080 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +000081 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +000082 return 0;
83 }
andreip@google.combccb32d2010-09-23 14:34:22 +000084 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
alecflett@chromium.org51757b62013-01-05 20:42:38 +000085 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, keyRange, false, request);
andreip@google.combccb32d2010-09-23 14:34:22 +000086 return request.release();
jorlow@chromium.orge3865912010-05-26 15:39:35 +000087}
88
jsbell@chromium.org174edbc2013-01-22 21:21:34 +000089PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, const ScriptValue& key, ExceptionCode& ec)
commit-queue@webkit.org205a6322012-04-21 00:16:48 +000090{
jsbell@chromium.org174edbc2013-01-22 21:21:34 +000091 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec);
commit-queue@webkit.org205a6322012-04-21 00:16:48 +000092 if (ec)
93 return 0;
94 return get(context, keyRange.release(), ec);
95}
96
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +000097static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIndexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* indexKeys)
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +000098{
99 ASSERT(indexKeys);
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000100 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState, objectValue, indexMetadata.keyPath);
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +0000101
102 if (!indexKey)
103 return;
104
105 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) {
106 if (!indexKey->isValid())
107 return;
108
109 indexKeys->append(indexKey);
110 } else {
111 ASSERT(indexMetadata.multiEntry);
112 ASSERT(indexKey->type() == IDBKey::ArrayType);
113 indexKey = IDBKey::createMultiEntryArray(indexKey->array());
114
115 for (size_t i = 0; i < indexKey->array().size(); ++i)
116 indexKeys->append(indexKey->array()[i]);
117 }
118}
119
weinig@apple.com95472c92013-09-14 02:01:26 +0000120PassRefPtr<IDBRequest> IDBObjectStore::add(JSC::ExecState* state, ScriptValue& value, const ScriptValue& key, ExceptionCode& ec)
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000121{
beidson@apple.com1367e452013-09-30 20:32:21 +0000122 LOG(StorageAPI, "IDBObjectStore::add");
beidson@apple.com7b14f472013-11-09 06:27:23 +0000123 return put(IDBDatabaseBackend::AddOnly, IDBAny::create(this), state, value, key, ec);
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000124}
125
weinig@apple.com95472c92013-09-14 02:01:26 +0000126PassRefPtr<IDBRequest> IDBObjectStore::add(JSC::ExecState* state, ScriptValue& value, ExceptionCode& ec)
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000127{
beidson@apple.com1367e452013-09-30 20:32:21 +0000128 LOG(StorageAPI, "IDBObjectStore::add");
beidson@apple.com7b14f472013-11-09 06:27:23 +0000129 return put(IDBDatabaseBackend::AddOnly, IDBAny::create(this), state, value, static_cast<IDBKey*>(0), ec);
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000130}
131
weinig@apple.com95472c92013-09-14 02:01:26 +0000132PassRefPtr<IDBRequest> IDBObjectStore::put(JSC::ExecState* state, ScriptValue& value, const ScriptValue& key, ExceptionCode& ec)
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000133{
beidson@apple.com1367e452013-09-30 20:32:21 +0000134 LOG(StorageAPI, "IDBObjectStore::put");
beidson@apple.com7b14f472013-11-09 06:27:23 +0000135 return put(IDBDatabaseBackend::AddOrUpdate, IDBAny::create(this), state, value, key, ec);
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000136}
137
weinig@apple.com95472c92013-09-14 02:01:26 +0000138PassRefPtr<IDBRequest> IDBObjectStore::put(JSC::ExecState* state, ScriptValue& value, ExceptionCode& ec)
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000139{
beidson@apple.com1367e452013-09-30 20:32:21 +0000140 LOG(StorageAPI, "IDBObjectStore::put");
beidson@apple.com7b14f472013-11-09 06:27:23 +0000141 return put(IDBDatabaseBackend::AddOrUpdate, IDBAny::create(this), state, value, static_cast<IDBKey*>(0), ec);
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000142}
143
beidson@apple.com7b14f472013-11-09 06:27:23 +0000144PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackend::PutMode putMode, PassRefPtr<IDBAny> source, JSC::ExecState* state, ScriptValue& value, const ScriptValue& keyValue, ExceptionCode& ec)
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000145{
weinig@apple.com95472c92013-09-14 02:01:26 +0000146 ScriptExecutionContext* context = scriptExecutionContextFromExecState(state);
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000147 DOMRequestState requestState(context);
148 RefPtr<IDBKey> key = scriptValueToIDBKey(&requestState, keyValue);
149 return put(putMode, source, state, value, key.release(), ec);
150}
151
beidson@apple.com7b14f472013-11-09 06:27:23 +0000152PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackend::PutMode putMode, PassRefPtr<IDBAny> source, JSC::ExecState* state, ScriptValue& value, PassRefPtr<IDBKey> prpKey, ExceptionCode& ec)
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000153{
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000154 RefPtr<IDBKey> key = prpKey;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000155 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000156 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000157 return 0;
158 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000159 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000160 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000161 return 0;
162 }
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000163 if (m_transaction->isReadOnly()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000164 ec = IDBDatabaseException::ReadOnlyError;
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000165 return 0;
166 }
commit-queue@webkit.orga4062fe2012-09-12 23:20:22 +0000167
jsbell@chromium.org181492f2013-03-29 19:36:38 +0000168 // FIXME: Expose the JS engine exception state through ScriptState.
169 bool didThrow = false;
170 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0, didThrow);
171 if (didThrow) {
172 // Setting an explicit ExceptionCode here would defer handling the already thrown exception.
commit-queue@webkit.orga4062fe2012-09-12 23:20:22 +0000173 return 0;
174 }
175
176 if (serializedValue->blobURLs().size() > 0) {
jsbell@chromium.orgdfafc062012-03-16 19:26:00 +0000177 // FIXME: Add Blob/File/FileList support
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000178 ec = IDBDatabaseException::DataCloneError;
jsbell@chromium.orgdfafc062012-03-16 19:26:00 +0000179 return 0;
180 }
181
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000182 const IDBKeyPath& keyPath = m_metadata.keyPath;
183 const bool usesInLineKeys = !keyPath.isNull();
184 const bool hasKeyGenerator = autoIncrement();
commit-queue@webkit.orgdfdea212012-11-22 04:34:40 +0000185
weinig@apple.com95472c92013-09-14 02:01:26 +0000186 ScriptExecutionContext* context = scriptExecutionContextFromExecState(state);
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000187 DOMRequestState requestState(context);
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000188
beidson@apple.com7b14f472013-11-09 06:27:23 +0000189 if (putMode != IDBDatabaseBackend::CursorUpdate && usesInLineKeys && key) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000190 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000191 return 0;
192 }
193 if (!usesInLineKeys && !hasKeyGenerator && !key) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000194 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000195 return 0;
196 }
197 if (usesInLineKeys) {
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000198 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&requestState, value, keyPath);
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000199 if (keyPathKey && !keyPathKey->isValid()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000200 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000201 return 0;
202 }
203 if (!hasKeyGenerator && !keyPathKey) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000204 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000205 return 0;
206 }
207 if (hasKeyGenerator && !keyPathKey) {
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000208 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000209 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000210 return 0;
211 }
212 }
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +0000213 if (keyPathKey)
214 key = keyPathKey;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000215 }
216 if (key && !key->isValid()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000217 ec = IDBDatabaseException::DataError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000218 return 0;
219 }
220
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000221 Vector<int64_t> indexIds;
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +0000222 Vector<IndexKeys> indexKeys;
223 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
224 IndexKeys keys;
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000225 generateIndexKeysForValue(&requestState, it->value, value, &keys);
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000226 indexIds.append(it->key);
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +0000227 indexKeys.append(keys);
228 }
commit-queue@webkit.org4b923fc2012-07-27 07:30:27 +0000229
230 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transaction.get());
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000231 Vector<uint8_t> valueBytes = serializedValue->toWireBytes();
alecflett@chromium.org9d1da952013-02-15 21:01:49 +0000232 // This is a hack to account for disagreements about whether SerializedScriptValue should deal in Vector<uint8_t> or Vector<char>.
233 // See https://lists.webkit.org/pipermail/webkit-dev/2013-February/023682.html
234 Vector<char>* valueBytesSigned = reinterpret_cast<Vector<char>*>(&valueBytes);
235 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(*valueBytesSigned);
beidson@apple.com7b14f472013-11-09 06:27:23 +0000236 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), static_cast<IDBDatabaseBackend::PutMode>(putMode), request, indexIds, indexKeys);
jorlow@chromium.org74252442011-03-01 23:55:36 +0000237 return request.release();
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000238}
239
jsbell@chromium.orga8a43402012-02-18 02:46:13 +0000240PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec)
241{
beidson@apple.com1367e452013-09-30 20:32:21 +0000242 LOG(StorageAPI, "IDBObjectStore::delete");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000243 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000244 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000245 return 0;
246 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000247 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000248 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000249 return 0;
250 }
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000251 if (m_transaction->isReadOnly()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000252 ec = IDBDatabaseException::ReadOnlyError;
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000253 return 0;
254 }
jsbell@chromium.orga8a43402012-02-18 02:46:13 +0000255 if (!keyRange) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000256 ec = IDBDatabaseException::DataError;
jsbell@chromium.orga8a43402012-02-18 02:46:13 +0000257 return 0;
258 }
259
260 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000261 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request);
jsbell@chromium.orga8a43402012-02-18 02:46:13 +0000262 return request.release();
263}
264
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000265PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* context, const ScriptValue& key, ExceptionCode& ec)
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000266{
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000267 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec);
jsbell@chromium.org99332ea2012-06-21 00:31:41 +0000268 if (ec)
jsbell@chromium.org46990082012-06-15 22:49:04 +0000269 return 0;
jsbell@chromium.org99332ea2012-06-21 00:31:41 +0000270 return deleteFunction(context, keyRange.release(), ec);
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000271}
272
jochen@chromium.orgb1d45622011-02-12 11:56:03 +0000273PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, ExceptionCode& ec)
274{
beidson@apple.com1367e452013-09-30 20:32:21 +0000275 LOG(StorageAPI, "IDBObjectStore::clear");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000276 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000277 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000278 return 0;
279 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000280 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000281 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000282 return 0;
283 }
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000284 if (m_transaction->isReadOnly()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000285 ec = IDBDatabaseException::ReadOnlyError;
commit-queue@webkit.orgd6cf20d2012-06-12 20:45:58 +0000286 return 0;
287 }
288
jochen@chromium.orgb1d45622011-02-12 11:56:03 +0000289 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
beidson@apple.com05a35ca2013-11-15 20:57:35 +0000290 backendDB()->clearObjectStore(m_transaction->id(), id(), request);
jorlow@chromium.org74252442011-03-01 23:55:36 +0000291 return request.release();
jochen@chromium.orgb1d45622011-02-12 11:56:03 +0000292}
293
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000294namespace {
295// This class creates the index keys for a given index by extracting
296// them from the SerializedScriptValue, for all the existing values in
297// the objectStore. It only needs to be kept alive by virtue of being
298// a listener on an IDBRequest object, in the same way that JavaScript
299// cursor success handlers are kept alive.
300class IndexPopulator : public EventListener {
301public:
beidson@apple.com7b14f472013-11-09 06:27:23 +0000302 static PassRefPtr<IndexPopulator> create(PassRefPtr<IDBDatabaseBackend> backend, int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000303 {
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000304 return adoptRef(new IndexPopulator(backend, transactionId, objectStoreId, indexMetadata));
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000305 }
306
307 virtual bool operator==(const EventListener& other)
308 {
309 return this == &other;
310 }
311
312private:
beidson@apple.com7b14f472013-11-09 06:27:23 +0000313 IndexPopulator(PassRefPtr<IDBDatabaseBackend> backend, int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000314 : EventListener(CPPEventListenerType)
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000315 , m_databaseBackend(backend)
316 , m_transactionId(transactionId)
317 , m_objectStoreId(objectStoreId)
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000318 , m_indexMetadata(indexMetadata)
319 {
320 }
321
charles.wei@torchmobile.com.cn7a8f3122013-03-28 00:13:12 +0000322 virtual void handleEvent(ScriptExecutionContext*, Event* event)
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000323 {
324 ASSERT(event->type() == eventNames().successEvent);
325 EventTarget* target = event->target();
326 IDBRequest* request = static_cast<IDBRequest*>(target);
327
mkwst@chromium.orgd08810f2013-02-08 13:04:31 +0000328 RefPtr<IDBAny> cursorAny = request->result(ASSERT_NO_EXCEPTION);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000329 RefPtr<IDBCursorWithValue> cursor;
330 if (cursorAny->type() == IDBAny::IDBCursorWithValueType)
331 cursor = cursorAny->idbCursorWithValue();
332
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000333 Vector<int64_t, 1> indexIds;
334 indexIds.append(m_indexMetadata.id);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000335 if (cursor) {
mkwst@chromium.orgd08810f2013-02-08 13:04:31 +0000336 cursor->continueFunction(static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTION);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000337
jsbell@chromium.org17d698c2012-10-24 21:36:57 +0000338 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey();
jsbell@chromium.org569a1502012-10-23 05:21:22 +0000339 ScriptValue value = cursor->value();
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000340
341 IDBObjectStore::IndexKeys indexKeys;
commit-queue@webkit.orgd159e4b2012-11-16 20:56:30 +0000342 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000343
344 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList;
345 indexKeysList.append(indexKeys);
346
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000347 m_databaseBackend->setIndexKeys(m_transactionId, m_objectStoreId, primaryKey, indexIds, indexKeysList);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000348 } else {
349 // Now that we are done indexing, tell the backend to go
350 // back to processing tasks of type NormalTask.
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000351 m_databaseBackend->setIndexesReady(m_transactionId, m_objectStoreId, indexIds);
352 m_databaseBackend.clear();
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000353 }
354
355 }
356
beidson@apple.com7b14f472013-11-09 06:27:23 +0000357 RefPtr<IDBDatabaseBackend> m_databaseBackend;
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000358 const int64_t m_transactionId;
359 const int64_t m_objectStoreId;
360 const IDBIndexMetadata m_indexMetadata;
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000361};
jsbell@chromium.orgaf00b262012-05-21 21:34:39 +0000362}
363
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000364PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context, const String& name, const IDBKeyPath& keyPath, const Dictionary& options, ExceptionCode& ec)
jsbell@chromium.orgaf00b262012-05-21 21:34:39 +0000365{
commit-queue@webkit.org41e22ba2012-12-19 00:10:20 +0000366 bool unique = false;
367 options.get("unique", unique);
368
369 bool multiEntry = false;
370 options.get("multiEntry", multiEntry);
371
372 return createIndex(context, name, keyPath, unique, multiEntry, ec);
373}
374
375PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, ExceptionCode& ec)
376{
beidson@apple.com1367e452013-09-30 20:32:21 +0000377 LOG(StorageAPI, "IDBObjectStore::createIndex");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000378 if (!m_transaction->isVersionChange() || m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000379 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000380 return 0;
381 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000382 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000383 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000384 return 0;
385 }
jsbell@chromium.orgaf00b262012-05-21 21:34:39 +0000386 if (!keyPath.isValid()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000387 ec = IDBDatabaseException::SyntaxError;
commit-queue@webkit.org67816382011-08-25 05:31:51 +0000388 return 0;
389 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000390 if (name.isNull()) {
jsbell@chromium.org00c51d82012-11-14 20:22:41 +0000391 ec = TypeError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000392 return 0;
393 }
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000394 if (containsIndex(name)) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000395 ec = IDBDatabaseException::ConstraintError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000396 return 0;
397 }
commit-queue@webkit.org67816382011-08-25 05:31:51 +0000398
jsbell@chromium.org9967a5e2012-05-22 18:46:07 +0000399 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000400 ec = IDBDatabaseException::InvalidAccessError;
jsbell@chromium.org9967a5e2012-05-22 18:46:07 +0000401 return 0;
402 }
commit-queue@webkit.orge7617152011-12-01 05:22:26 +0000403
alecflett@chromium.orgcb23bff2012-10-09 01:17:59 +0000404 int64_t indexId = m_metadata.maxIndexId + 1;
alecflett@chromium.org6d7e1482013-01-10 07:33:14 +0000405 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
jsbell@chromium.org46990082012-06-15 22:49:04 +0000406
alecflett@chromium.orge49d9292012-10-04 22:38:18 +0000407 ++m_metadata.maxIndexId;
408
409 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000410 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get());
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000411 m_indexMap.set(name, index);
alecflett@chromium.orge33cc6b2012-11-01 18:07:22 +0000412 m_metadata.indexes.set(indexId, metadata);
jsbell@chromium.org46990082012-06-15 22:49:04 +0000413
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000414 ASSERT(!ec);
415 if (ec)
416 return 0;
417
beidson@apple.com7b14f472013-11-09 06:27:23 +0000418 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRange*>(0), IDBCursor::directionNext(), IDBDatabaseBackend::PreemptiveTask, ec);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000419 ASSERT(!ec);
420 if (ec)
421 return 0;
jsbell@chromium.orgdbe61e52012-10-20 00:55:33 +0000422 indexRequest->preventPropagation();
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000423
424 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000425 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata);
commit-queue@webkit.org6b2e7962012-08-16 00:50:52 +0000426 indexRequest->setOnsuccess(indexPopulator);
427
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000428 return index.release();
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +0000429}
430
jorlow@chromium.orgb49ea0e2010-10-14 00:39:06 +0000431PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionCode& ec)
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +0000432{
beidson@apple.com1367e452013-09-30 20:32:21 +0000433 LOG(StorageAPI, "IDBObjectStore::index");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000434 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000435 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000436 return 0;
437 }
jsbell@chromium.org19810962012-05-16 21:02:21 +0000438 if (m_transaction->isFinished()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000439 ec = IDBDatabaseException::InvalidStateError;
jorlow@chromium.org0fb2ee72010-09-23 17:32:52 +0000440 return 0;
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000441 }
442
443 IDBIndexMap::iterator it = m_indexMap.find(name);
444 if (it != m_indexMap.end())
benjamin@webkit.orgee554052012-10-07 23:12:07 +0000445 return it->value;
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000446
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000447 int64_t indexId = findIndexId(name);
448 if (indexId == IDBIndexMetadata::InvalidId) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000449 ec = IDBDatabaseException::NotFoundError;
senorblanco@chromium.orgcde58492012-11-01 02:08:31 +0000450 return 0;
alecflett@chromium.orge33cc6b2012-11-01 18:07:22 +0000451 }
jsbell@chromium.orgddfcb6f2012-06-22 22:09:22 +0000452
alecflett@chromium.orge33cc6b2012-11-01 18:07:22 +0000453 const IDBIndexMetadata* indexMetadata(0);
454 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
455 if (it->value.name == name) {
456 indexMetadata = &it->value;
457 break;
458 }
459 }
460 ASSERT(indexMetadata);
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000461 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId);
alecflett@chromium.orge33cc6b2012-11-01 18:07:22 +0000462
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000463 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transaction.get());
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000464 m_indexMap.set(name, index);
465 return index.release();
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +0000466}
467
andreip@google.com7e718832010-11-26 16:58:57 +0000468void IDBObjectStore::deleteIndex(const String& name, ExceptionCode& ec)
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +0000469{
beidson@apple.com1367e452013-09-30 20:32:21 +0000470 LOG(StorageAPI, "IDBObjectStore::deleteIndex");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000471 if (!m_transaction->isVersionChange() || m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000472 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000473 return;
474 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000475 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000476 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000477 return;
478 }
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000479 int64_t indexId = findIndexId(name);
480 if (indexId == IDBIndexMetadata::InvalidId) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000481 ec = IDBDatabaseException::NotFoundError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000482 return;
483 }
jsbell@chromium.org46990082012-06-15 22:49:04 +0000484
alecflett@chromium.org6d7e1482013-01-10 07:33:14 +0000485 backendDB()->deleteIndex(m_transaction->id(), id(), indexId);
486
jsbell@chromium.org1d6014e2013-02-26 18:44:04 +0000487 m_metadata.indexes.remove(indexId);
alecflett@chromium.org6d7e1482013-01-10 07:33:14 +0000488 IDBIndexMap::iterator it = m_indexMap.find(name);
489 if (it != m_indexMap.end()) {
alecflett@chromium.org6d7e1482013-01-10 07:33:14 +0000490 it->value->markDeleted();
491 m_indexMap.remove(name);
jsbell@chromium.org46990082012-06-15 22:49:04 +0000492 }
jorlow@chromium.org6d85cb82010-05-28 14:30:41 +0000493}
494
beidson@apple.com7b14f472013-11-09 06:27:23 +0000495PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, ExceptionCode& ec)
496{
497 return openCursor(context, static_cast<IDBKeyRange*>(0), ec);
498}
499
500PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec)
501{
502 return openCursor(context, keyRange, IDBCursor::directionNext(), ec);
503}
504
505PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, const ScriptValue& key, ExceptionCode& ec)
506{
507 return openCursor(context, key, IDBCursor::directionNext(), ec);
508}
509
510PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> range, const String& direction, ExceptionCode& ec)
511{
512 return openCursor(context, range, direction, IDBDatabaseBackend::NormalTask, ec);
513}
514
515PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBackend::TaskType taskType, ExceptionCode& ec)
bulach@chromium.org51cb8ff2010-08-06 10:37:41 +0000516{
beidson@apple.com1367e452013-09-30 20:32:21 +0000517 LOG(StorageAPI, "IDBObjectStore::openCursor");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000518 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000519 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000520 return 0;
521 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000522 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000523 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000524 return 0;
525 }
charles.wei@torchmobile.com.cn7a8f3122013-03-28 00:13:12 +0000526 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directionString, ec);
commit-queue@webkit.org98b75ae2012-05-07 19:12:00 +0000527 if (ec)
jorlow@chromium.org9c02b652010-11-26 16:33:28 +0000528 return 0;
jorlow@chromium.org9c02b652010-11-26 16:33:28 +0000529
jorlow@chromium.org4e087e02010-09-30 16:55:46 +0000530 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
alecflett@chromium.orgdb5a6f72013-03-05 22:35:00 +0000531 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000532
beidson@apple.com7b14f472013-11-09 06:27:23 +0000533 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, range, direction, false, static_cast<IDBDatabaseBackend::TaskType>(taskType), request);
bulach@chromium.org51cb8ff2010-08-06 10:37:41 +0000534 return request.release();
535}
536
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000537PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* context, const ScriptValue& key, const String& direction, ExceptionCode& ec)
commit-queue@webkit.org634c6722012-05-03 23:39:23 +0000538{
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000539 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec);
commit-queue@webkit.org634c6722012-05-03 23:39:23 +0000540 if (ec)
541 return 0;
jsbell@chromium.orge85f95a2012-07-18 23:57:04 +0000542 return openCursor(context, keyRange.release(), direction, ec);
commit-queue@webkit.org634c6722012-05-03 23:39:23 +0000543}
544
commit-queue@webkit.org19576182011-12-16 21:27:06 +0000545PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> range, ExceptionCode& ec)
546{
beidson@apple.com1367e452013-09-30 20:32:21 +0000547 LOG(StorageAPI, "IDBObjectStore::count");
jsbell@chromium.org46990082012-06-15 22:49:04 +0000548 if (m_deleted) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000549 ec = IDBDatabaseException::InvalidStateError;
jsbell@chromium.org46990082012-06-15 22:49:04 +0000550 return 0;
551 }
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000552 if (!m_transaction->isActive()) {
jsbell@chromium.orge9e60202012-12-03 18:54:02 +0000553 ec = IDBDatabaseException::TransactionInactiveError;
jsbell@chromium.org74a6fec2012-06-26 22:04:09 +0000554 return 0;
555 }
commit-queue@webkit.org19576182011-12-16 21:27:06 +0000556 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000557 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, range, request);
commit-queue@webkit.org19576182011-12-16 21:27:06 +0000558 return request.release();
559}
560
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000561PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, const ScriptValue& key, ExceptionCode& ec)
jsbell@chromium.org93ee7422012-02-24 22:56:00 +0000562{
jsbell@chromium.org174edbc2013-01-22 21:21:34 +0000563 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec);
jsbell@chromium.org93ee7422012-02-24 22:56:00 +0000564 if (ec)
565 return 0;
566 return count(context, keyRange.release(), ec);
567}
568
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000569void IDBObjectStore::transactionFinished()
570{
jsbell@chromium.org19810962012-05-16 21:02:21 +0000571 ASSERT(m_transaction->isFinished());
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000572
573 // Break reference cycles.
574 m_indexMap.clear();
575}
576
alecflett@chromium.org0e11d582012-11-09 19:55:06 +0000577int64_t IDBObjectStore::findIndexId(const String& name) const
578{
579 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
580 if (it->value.name == name) {
581 ASSERT(it->key != IDBIndexMetadata::InvalidId);
582 return it->key;
583 }
584 }
585 return IDBIndexMetadata::InvalidId;
586}
commit-queue@webkit.org83287242011-12-20 00:57:07 +0000587
beidson@apple.com7b14f472013-11-09 06:27:23 +0000588IDBDatabaseBackend* IDBObjectStore::backendDB() const
alecflett@chromium.org51757b62013-01-05 20:42:38 +0000589{
590 return m_transaction->backendDB();
591}
592
jorlow@chromium.orge3865912010-05-26 15:39:35 +0000593} // namespace WebCore
594
595#endif // ENABLE(INDEXED_DATABASE)