2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "modules/indexeddb/IDBObjectStore.h"
29 #include "bindings/v8/ExceptionState.h"
30 #include "bindings/v8/ExceptionStatePlaceholder.h"
31 #include "bindings/v8/IDBBindingUtilities.h"
32 #include "bindings/v8/ScriptState.h"
33 #include "core/dom/DOMStringList.h"
34 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/ExecutionContext.h"
36 #include "modules/indexeddb/IDBAny.h"
37 #include "modules/indexeddb/IDBCursorWithValue.h"
38 #include "modules/indexeddb/IDBDatabase.h"
39 #include "modules/indexeddb/IDBKeyPath.h"
40 #include "modules/indexeddb/IDBTracing.h"
41 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
42 #include "platform/SharedBuffer.h"
43 #include "public/platform/WebData.h"
44 #include "public/platform/WebIDBKey.h"
45 #include "public/platform/WebIDBKeyRange.h"
47 using blink::WebIDBCallbacks;
48 using blink::WebIDBCursor;
49 using blink::WebIDBDatabase;
53 IDBObjectStore::IDBObjectStore(const IDBObjectStoreMetadata& metadata, IDBTransaction* transaction)
54 : m_metadata(metadata)
55 , m_transaction(transaction)
58 ASSERT(m_transaction);
59 // We pass a reference to this object before it can be adopted.
60 relaxAdoptionRequirement();
61 ScriptWrappable::init(this);
64 ScriptValue IDBObjectStore::keyPath(ExecutionContext* context) const
66 DOMRequestState requestState(context);
67 return idbAnyToScriptValue(&requestState, IDBAny::create(m_metadata.keyPath));
70 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
72 IDB_TRACE("IDBObjectStore::indexNames");
73 RefPtr<DOMStringList> indexNames = DOMStringList::create();
74 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it)
75 indexNames->append(it->value.name);
77 return indexNames.release();
80 PassRefPtr<IDBRequest> IDBObjectStore::get(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState)
82 IDB_TRACE("IDBObjectStore::get");
84 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
87 if (m_transaction->isFinished()) {
88 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
91 if (!m_transaction->isActive()) {
92 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
95 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, exceptionState);
96 if (exceptionState.hadException())
99 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage);
103 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
104 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, keyRange.release(), false, WebIDBCallbacksImpl::create(request).leakPtr());
105 return request.release();
108 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIndexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::IndexKeys* indexKeys)
111 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState, objectValue, indexMetadata.keyPath);
116 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) {
117 if (!indexKey->isValid())
120 indexKeys->append(indexKey);
122 ASSERT(indexMetadata.multiEntry);
123 ASSERT(indexKey->type() == IDBKey::ArrayType);
124 indexKey = IDBKey::createMultiEntryArray(indexKey->array());
126 for (size_t i = 0; i < indexKey->array().size(); ++i)
127 indexKeys->append(indexKey->array()[i]);
131 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptState* state, ScriptValue& value, const ScriptValue& key, ExceptionState& exceptionState)
133 IDB_TRACE("IDBObjectStore::add");
134 return put(WebIDBDatabase::AddOnly, IDBAny::create(this), state, value, key, exceptionState);
137 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& value, const ScriptValue& key, ExceptionState& exceptionState)
139 IDB_TRACE("IDBObjectStore::put");
140 return put(WebIDBDatabase::AddOrUpdate, IDBAny::create(this), state, value, key, exceptionState);
143 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, const ScriptValue& keyValue, ExceptionState& exceptionState)
145 ExecutionContext* context = state->executionContext();
146 DOMRequestState requestState(context);
147 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&requestState, keyValue);
148 return put(putMode, source, state, value, key.release(), exceptionState);
151 PassRefPtr<IDBRequest> IDBObjectStore::put(WebIDBDatabase::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, PassRefPtr<IDBKey> prpKey, ExceptionState& exceptionState)
153 RefPtr<IDBKey> key = prpKey;
155 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
158 if (m_transaction->isFinished()) {
159 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
162 if (!m_transaction->isActive()) {
163 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
166 if (m_transaction->isReadOnly()) {
167 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transactionReadOnlyErrorMessage);
171 RefPtr<SerializedScriptValue> serializedValue = SerializedScriptValue::create(value, exceptionState, state);
172 if (exceptionState.hadException())
175 if (serializedValue->containsBlobs()) {
176 // FIXME: Add Blob/File/FileList support
177 exceptionState.throwDOMException(DataCloneError, "The object store currently does not support blob values.");
181 const IDBKeyPath& keyPath = m_metadata.keyPath;
182 const bool usesInLineKeys = !keyPath.isNull();
183 const bool hasKeyGenerator = autoIncrement();
185 ExecutionContext* context = state->executionContext();
186 DOMRequestState requestState(context);
188 if (putMode != WebIDBDatabase::CursorUpdate && usesInLineKeys && key) {
189 exceptionState.throwDOMException(DataError, "The object store uses in-line keys and the key parameter was provided.");
192 if (!usesInLineKeys && !hasKeyGenerator && !key) {
193 exceptionState.throwDOMException(DataError, "The object store uses out-of-line keys and has no key generator and the key parameter was not provided.");
196 if (usesInLineKeys) {
197 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&requestState, value, keyPath);
198 if (keyPathKey && !keyPathKey->isValid()) {
199 exceptionState.throwDOMException(DataError, "Evaluating the object store's key path yielded a value that is not a valid key.");
202 if (!hasKeyGenerator && !keyPathKey) {
203 exceptionState.throwDOMException(DataError, "Evaluating the object store's key path did not yield a value.");
206 if (hasKeyGenerator && !keyPathKey) {
207 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
208 exceptionState.throwDOMException(DataError, "A generated key could not be inserted into the value.");
215 if (key && !key->isValid()) {
216 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErrorMessage);
220 Vector<int64_t> indexIds;
221 Vector<IndexKeys> indexKeys;
222 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
224 generateIndexKeysForValue(&requestState, it->value, value, &keys);
225 indexIds.append(it->key);
226 indexKeys.append(keys);
229 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transaction.get());
230 Vector<char> wireBytes;
231 serializedValue->toWireBytes(wireBytes);
232 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
233 backendDB()->put(m_transaction->id(), id(), blink::WebData(valueBuffer), key.release(), static_cast<WebIDBDatabase::PutMode>(putMode), WebIDBCallbacksImpl::create(request).leakPtr(), indexIds, indexKeys);
234 return request.release();
237 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ExecutionContext* context, const ScriptValue& key, ExceptionState& exceptionState)
239 IDB_TRACE("IDBObjectStore::delete");
241 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
244 if (m_transaction->isFinished()) {
245 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
248 if (!m_transaction->isActive()) {
249 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
252 if (m_transaction->isReadOnly()) {
253 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transactionReadOnlyErrorMessage);
257 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, exceptionState);
258 if (exceptionState.hadException())
261 exceptionState.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage);
265 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
266 backendDB()->deleteRange(m_transaction->id(), id(), keyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr());
267 return request.release();
270 PassRefPtr<IDBRequest> IDBObjectStore::clear(ExecutionContext* context, ExceptionState& exceptionState)
272 IDB_TRACE("IDBObjectStore::clear");
274 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
277 if (m_transaction->isFinished()) {
278 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
281 if (!m_transaction->isActive()) {
282 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
285 if (m_transaction->isReadOnly()) {
286 exceptionState.throwDOMException(ReadOnlyError, IDBDatabase::transactionReadOnlyErrorMessage);
290 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
291 backendDB()->clear(m_transaction->id(), id(), WebIDBCallbacksImpl::create(request).leakPtr());
292 return request.release();
296 // This class creates the index keys for a given index by extracting
297 // them from the SerializedScriptValue, for all the existing values in
298 // the objectStore. It only needs to be kept alive by virtue of being
299 // a listener on an IDBRequest object, in the same way that JavaScript
300 // cursor success handlers are kept alive.
301 class IndexPopulator FINAL : public EventListener {
303 static PassRefPtr<IndexPopulator> create(PassRefPtr<IDBDatabase> database, int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
305 return adoptRef(new IndexPopulator(database, transactionId, objectStoreId, indexMetadata));
308 virtual bool operator==(const EventListener& other) OVERRIDE
310 return this == &other;
314 IndexPopulator(PassRefPtr<IDBDatabase> database, int64_t transactionId, int64_t objectStoreId, const IDBIndexMetadata& indexMetadata)
315 : EventListener(CPPEventListenerType)
316 , m_database(database)
317 , m_transactionId(transactionId)
318 , m_objectStoreId(objectStoreId)
319 , m_indexMetadata(indexMetadata)
323 virtual void handleEvent(ExecutionContext* context, Event* event) OVERRIDE
325 ASSERT(event->type() == EventTypeNames::success);
326 EventTarget* target = event->target();
327 IDBRequest* request = static_cast<IDBRequest*>(target);
329 RefPtr<IDBAny> cursorAny = request->resultAsAny();
330 RefPtr<IDBCursorWithValue> cursor;
331 if (cursorAny->type() == IDBAny::IDBCursorWithValueType)
332 cursor = cursorAny->idbCursorWithValue();
334 Vector<int64_t> indexIds;
335 indexIds.append(m_indexMetadata.id);
337 cursor->continueFunction(static_cast<IDBKey*>(0), static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTION);
339 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey();
340 ScriptValue value = cursor->value(context);
342 IDBObjectStore::IndexKeys indexKeys;
343 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys);
345 Vector<IDBObjectStore::IndexKeys> indexKeysList;
346 indexKeysList.append(indexKeys);
348 m_database->backend()->setIndexKeys(m_transactionId, m_objectStoreId, primaryKey.release(), indexIds, indexKeysList);
350 // Now that we are done indexing, tell the backend to go
351 // back to processing tasks of type NormalTask.
352 m_database->backend()->setIndexesReady(m_transactionId, m_objectStoreId, indexIds);
358 RefPtr<IDBDatabase> m_database;
359 const int64_t m_transactionId;
360 const int64_t m_objectStoreId;
361 const IDBIndexMetadata m_indexMetadata;
365 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, const String& name, const IDBKeyPath& keyPath, const Dictionary& options, ExceptionState& exceptionState)
368 options.get("unique", unique);
370 bool multiEntry = false;
371 options.get("multiEntry", multiEntry);
373 return createIndex(context, name, keyPath, unique, multiEntry, exceptionState);
376 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ExecutionContext* context, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, ExceptionState& exceptionState)
378 IDB_TRACE("IDBObjectStore::createIndex");
379 if (!m_transaction->isVersionChange()) {
380 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionErrorMessage);
384 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
387 if (m_transaction->isFinished()) {
388 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
391 if (!m_transaction->isActive()) {
392 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
395 if (!keyPath.isValid()) {
396 exceptionState.throwDOMException(SyntaxError, "The keyPath argument contains an invalid key path.");
400 exceptionState.throwTypeError("The name provided is null.");
403 if (containsIndex(name)) {
404 exceptionState.throwDOMException(ConstraintError, "An index with the specified name already exists.");
408 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
409 exceptionState.throwDOMException(InvalidAccessError, "The keyPath argument was an array and the multiEntry option is true.");
413 int64_t indexId = m_metadata.maxIndexId + 1;
414 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
416 ++m_metadata.maxIndexId;
418 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
419 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get());
420 m_indexMap.set(name, index);
421 m_metadata.indexes.set(indexId, metadata);
422 m_transaction->db()->indexCreated(id(), metadata);
424 ASSERT(!exceptionState.hadException());
425 if (exceptionState.hadException())
428 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRange*>(0), blink::WebIDBCursor::Next, WebIDBDatabase::PreemptiveTask);
429 indexRequest->preventPropagation();
431 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
432 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(transaction()->db(), m_transaction->id(), id(), metadata);
433 indexRequest->setOnsuccess(indexPopulator);
435 return index.release();
438 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& exceptionState)
440 IDB_TRACE("IDBObjectStore::index");
442 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
445 if (m_transaction->isFinished()) {
446 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::transactionFinishedErrorMessage);
450 IDBIndexMap::iterator it = m_indexMap.find(name);
451 if (it != m_indexMap.end())
454 int64_t indexId = findIndexId(name);
455 if (indexId == IDBIndexMetadata::InvalidId) {
456 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage);
460 const IDBIndexMetadata* indexMetadata(0);
461 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
462 if (it->value.name == name) {
463 indexMetadata = &it->value;
467 ASSERT(indexMetadata);
468 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId);
470 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transaction.get());
471 m_indexMap.set(name, index);
472 return index.release();
475 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& exceptionState)
477 IDB_TRACE("IDBObjectStore::deleteIndex");
478 if (!m_transaction->isVersionChange()) {
479 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::notVersionChangeTransactionErrorMessage);
483 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
486 if (m_transaction->isFinished()) {
487 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
490 if (!m_transaction->isActive()) {
491 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
494 int64_t indexId = findIndexId(name);
495 if (indexId == IDBIndexMetadata::InvalidId) {
496 exceptionState.throwDOMException(NotFoundError, IDBDatabase::noSuchIndexErrorMessage);
500 backendDB()->deleteIndex(m_transaction->id(), id(), indexId);
502 m_metadata.indexes.remove(indexId);
503 m_transaction->db()->indexDeleted(id(), indexId);
504 IDBIndexMap::iterator it = m_indexMap.find(name);
505 if (it != m_indexMap.end()) {
506 it->value->markDeleted();
507 m_indexMap.remove(name);
511 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState)
513 IDB_TRACE("IDBObjectStore::openCursor");
515 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
518 if (m_transaction->isFinished()) {
519 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
522 if (!m_transaction->isActive()) {
523 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
527 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionString, exceptionState);
528 if (exceptionState.hadException())
531 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
532 if (exceptionState.hadException())
535 return openCursor(context, keyRange, direction, WebIDBDatabase::NormalTask);
538 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ExecutionContext* context, PassRefPtr<IDBKeyRange> range, WebIDBCursor::Direction direction, WebIDBDatabase::TaskType taskType)
540 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
541 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
543 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, range, direction, false, taskType, WebIDBCallbacksImpl::create(request).leakPtr());
544 return request.release();
547 PassRefPtr<IDBRequest> IDBObjectStore::openKeyCursor(ExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& exceptionState)
549 IDB_TRACE("IDBObjectStore::openKeyCursor");
551 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
554 if (m_transaction->isFinished()) {
555 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
558 if (!m_transaction->isActive()) {
559 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
563 WebIDBCursor::Direction direction = IDBCursor::stringToDirection(directionString, exceptionState);
564 if (exceptionState.hadException())
567 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
568 if (exceptionState.hadException())
571 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
572 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction);
574 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, keyRange.release(), direction, true, WebIDBDatabase::NormalTask, WebIDBCallbacksImpl::create(request).leakPtr());
575 return request.release();
578 PassRefPtr<IDBRequest> IDBObjectStore::count(ExecutionContext* context, const ScriptValue& range, ExceptionState& exceptionState)
580 IDB_TRACE("IDBObjectStore::count");
582 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::objectStoreDeletedErrorMessage);
585 if (m_transaction->isFinished()) {
586 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionFinishedErrorMessage);
589 if (!m_transaction->isActive()) {
590 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::transactionInactiveErrorMessage);
594 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, exceptionState);
595 if (exceptionState.hadException())
598 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), m_transaction.get());
599 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, keyRange.release(), WebIDBCallbacksImpl::create(request).leakPtr());
600 return request.release();
603 void IDBObjectStore::transactionFinished()
605 ASSERT(m_transaction->isFinished());
607 // Break reference cycles.
611 int64_t IDBObjectStore::findIndexId(const String& name) const
613 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexes.begin(); it != m_metadata.indexes.end(); ++it) {
614 if (it->value.name == name) {
615 ASSERT(it->key != IDBIndexMetadata::InvalidId);
619 return IDBIndexMetadata::InvalidId;
622 WebIDBDatabase* IDBObjectStore::backendDB() const
624 return m_transaction->backendDB();
627 } // namespace WebCore