Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 ASSERT(m_objectStore); | 49 ASSERT(m_objectStore); |
| 50 ASSERT(m_transaction); | 50 ASSERT(m_transaction); |
| 51 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); | 51 ASSERT(m_metadata.id != IDBIndexMetadata::InvalidId); |
| 52 ScriptWrappable::init(this); | 52 ScriptWrappable::init(this); |
| 53 } | 53 } |
| 54 | 54 |
| 55 IDBIndex::~IDBIndex() | 55 IDBIndex::~IDBIndex() |
| 56 { | 56 { |
| 57 } | 57 } |
| 58 | 58 |
| 59 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, Pas sRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState& es ) | 59 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, con st ScriptValue& range, const String& directionString, ExceptionState& es) |
| 60 { | 60 { |
| 61 IDB_TRACE("IDBIndex::openCursor"); | 61 IDB_TRACE("IDBIndex::openCursor"); |
| 62 if (isDeleted()) { | 62 if (isDeleted()) { |
| 63 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); | 63 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); |
| 64 return 0; | 64 return 0; |
| 65 } | 65 } |
| 66 if (m_transaction->isFinished()) { | 66 if (m_transaction->isFinished()) { |
| 67 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | 67 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); |
| 68 return 0; | 68 return 0; |
| 69 } | 69 } |
| 70 if (!m_transaction->isActive()) { | 70 if (!m_transaction->isActive()) { |
| 71 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); | 71 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); |
| 72 return 0; | 72 return 0; |
| 73 } | 73 } |
| 74 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); | 74 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); |
| 75 if (es.hadException()) | 75 if (es.hadException()) |
| 76 return 0; | 76 return 0; |
| 77 | 77 |
| 78 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); | |
| 79 if (es.hadException()) | |
| 80 return 0; | |
|
haraken
2013/08/25 23:51:06
Don't you need to check if(!keyRange)?
jsbell
2013/08/26 16:06:18
No - null keyrange is acceptable, and this is not
| |
| 81 | |
| 82 return openCursor(context, keyRange, direction); | |
| 83 } | |
| 84 | |
| 85 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, Pas sRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction) | |
| 86 { | |
| 78 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); | 87 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); |
| 79 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); | 88 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); |
| 80 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques t); | 89 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, false, IDBDatabaseBackendInterface::NormalTask, reques t); |
| 81 return request; | 90 return request; |
| 82 } | 91 } |
| 83 | 92 |
| 84 PassRefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext* context, con st ScriptValue& key, const String& direction, ExceptionState& es) | 93 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, const Sc riptValue& range, ExceptionState& es) |
| 85 { | |
| 86 IDB_TRACE("IDBIndex::openCursor"); | |
| 87 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | |
| 88 if (es.hadException()) | |
| 89 return 0; | |
| 90 return openCursor(context, keyRange.release(), direction, es); | |
| 91 } | |
| 92 | |
| 93 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, PassRefP tr<IDBKeyRange> keyRange, ExceptionState& es) | |
| 94 { | 94 { |
| 95 IDB_TRACE("IDBIndex::count"); | 95 IDB_TRACE("IDBIndex::count"); |
| 96 if (isDeleted()) { | 96 if (isDeleted()) { |
| 97 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); | 97 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); |
| 98 return 0; | 98 return 0; |
| 99 } | 99 } |
| 100 if (m_transaction->isFinished()) { | 100 if (m_transaction->isFinished()) { |
| 101 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | 101 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); |
| 102 return 0; | 102 return 0; |
| 103 } | 103 } |
| 104 if (!m_transaction->isActive()) { | 104 if (!m_transaction->isActive()) { |
| 105 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); | 105 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); |
| 106 return 0; | 106 return 0; |
| 107 } | 107 } |
| 108 | |
| 109 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); | |
| 110 if (es.hadException()) | |
| 111 return 0; | |
|
haraken
2013/08/25 23:51:06
Ditto.
jsbell
2013/08/26 16:06:18
Ditto. (range is optional for count())
| |
| 112 | |
| 108 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); | 113 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); |
| 109 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, request); | 114 backendDB()->count(m_transaction->id(), m_objectStore->id(), m_metadata.id, keyRange, request); |
| 110 return request; | 115 return request; |
| 111 } | 116 } |
| 112 | 117 |
| 113 PassRefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext* context, const Sc riptValue& key, ExceptionState& es) | 118 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context, const ScriptValue& range, const String& directionString, ExceptionState& es) |
| 114 { | |
| 115 IDB_TRACE("IDBIndex::count"); | |
| 116 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | |
| 117 if (es.hadException()) | |
| 118 return 0; | |
| 119 return count(context, keyRange.release(), es); | |
| 120 } | |
| 121 | |
| 122 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context, PassRefPtr<IDBKeyRange> keyRange, const String& directionString, ExceptionState& es) | |
| 123 { | 119 { |
| 124 IDB_TRACE("IDBIndex::openKeyCursor"); | 120 IDB_TRACE("IDBIndex::openKeyCursor"); |
| 125 if (isDeleted()) { | 121 if (isDeleted()) { |
| 126 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); | 122 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); |
| 127 return 0; | 123 return 0; |
| 128 } | 124 } |
| 129 if (m_transaction->isFinished()) { | 125 if (m_transaction->isFinished()) { |
| 130 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | 126 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); |
| 131 return 0; | 127 return 0; |
| 132 } | 128 } |
| 133 if (!m_transaction->isActive()) { | 129 if (!m_transaction->isActive()) { |
| 134 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); | 130 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); |
| 135 return 0; | 131 return 0; |
| 136 } | 132 } |
| 137 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); | 133 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es); |
| 138 if (es.hadException()) | 134 if (es.hadException()) |
| 139 return 0; | 135 return 0; |
| 140 | 136 |
| 137 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, range, es); | |
| 138 if (es.hadException()) | |
| 139 return 0; | |
|
haraken
2013/08/25 23:51:06
Ditto.
jsbell
2013/08/26 16:06:18
Ditto. (range is optional for openKeyCursor)
| |
| 140 | |
| 141 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); | 141 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); |
| 142 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); | 142 request->setCursorDetails(IndexedDB::CursorKeyOnly, direction); |
| 143 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request ); | 143 backendDB()->openCursor(m_transaction->id(), m_objectStore->id(), m_metadata .id, keyRange, direction, true, IDBDatabaseBackendInterface::NormalTask, request ); |
| 144 return request; | 144 return request; |
| 145 } | 145 } |
| 146 | 146 |
| 147 PassRefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext* context, const ScriptValue& key, const String& direction, ExceptionState& es) | |
| 148 { | |
| 149 IDB_TRACE("IDBIndex::openKeyCursor"); | |
| 150 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | |
| 151 if (es.hadException()) | |
| 152 return 0; | |
| 153 return openKeyCursor(context, keyRange.release(), direction, es); | |
| 154 } | |
| 155 | |
| 156 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, const Scri ptValue& key, ExceptionState& es) | 147 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, const Scri ptValue& key, ExceptionState& es) |
| 157 { | 148 { |
| 158 IDB_TRACE("IDBIndex::get"); | 149 IDB_TRACE("IDBIndex::get"); |
| 159 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | |
| 160 if (es.hadException()) | |
| 161 return 0; | |
| 162 return get(context, keyRange.release(), es); | |
| 163 } | |
| 164 | |
| 165 PassRefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext* context, PassRefPtr <IDBKeyRange> keyRange, ExceptionState& es) | |
| 166 { | |
| 167 IDB_TRACE("IDBIndex::get"); | |
| 168 if (isDeleted()) { | 150 if (isDeleted()) { |
| 169 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); | 151 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); |
| 170 return 0; | 152 return 0; |
| 171 } | 153 } |
| 172 if (m_transaction->isFinished()) { | 154 if (m_transaction->isFinished()) { |
| 173 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | 155 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); |
| 174 return 0; | 156 return 0; |
| 175 } | 157 } |
| 176 if (!m_transaction->isActive()) { | 158 if (!m_transaction->isActive()) { |
| 177 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); | 159 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); |
| 178 return 0; | 160 return 0; |
| 179 } | 161 } |
| 162 | |
| 163 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es ); | |
| 164 if (es.hadException()) | |
| 165 return 0; | |
| 180 if (!keyRange) { | 166 if (!keyRange) { |
|
jsbell
2013/08/26 16:06:18
A key or range is NOT optional for get(), hence th
| |
| 181 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); | 167 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); |
| 182 return 0; | 168 return 0; |
| 183 } | 169 } |
| 184 | 170 |
| 185 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); | 171 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); |
| 186 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, false, request); | 172 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, false, request); |
| 187 return request; | 173 return request; |
| 188 } | 174 } |
| 189 | 175 |
| 190 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, const S criptValue& key, ExceptionState& es) | 176 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, const S criptValue& key, ExceptionState& es) |
| 191 { | 177 { |
| 192 IDB_TRACE("IDBIndex::getKey"); | 178 IDB_TRACE("IDBIndex::getKey"); |
| 193 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es); | |
| 194 if (es.hadException()) | |
| 195 return 0; | |
| 196 | |
| 197 return getKey(context, keyRange.release(), es); | |
| 198 } | |
| 199 | |
| 200 PassRefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext* context, PassRef Ptr<IDBKeyRange> keyRange, ExceptionState& es) | |
| 201 { | |
| 202 IDB_TRACE("IDBIndex::getKey"); | |
| 203 if (isDeleted()) { | 179 if (isDeleted()) { |
| 204 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); | 180 es.throwDOMException(InvalidStateError, IDBDatabase::indexDeletedErrorMe ssage); |
| 205 return 0; | 181 return 0; |
| 206 } | 182 } |
| 207 if (m_transaction->isFinished()) { | 183 if (m_transaction->isFinished()) { |
| 208 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); | 184 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionF inishedErrorMessage); |
| 209 return 0; | 185 return 0; |
| 210 } | 186 } |
| 211 if (!m_transaction->isActive()) { | 187 if (!m_transaction->isActive()) { |
| 212 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); | 188 es.throwDOMException(TransactionInactiveError, IDBDatabase::transactionI nactiveErrorMessage); |
| 213 return 0; | 189 return 0; |
| 214 } | 190 } |
| 191 | |
| 192 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::fromScriptValue(context, key, es ); | |
| 193 if (es.hadException()) | |
| 194 return 0; | |
| 215 if (!keyRange) { | 195 if (!keyRange) { |
|
jsbell
2013/08/26 16:06:18
Ditto for getKey()
| |
| 216 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); | 196 es.throwDOMException(DataError, IDBDatabase::noKeyOrKeyRangeErrorMessage ); |
| 217 return 0; | 197 return 0; |
| 218 } | 198 } |
| 219 | 199 |
| 220 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); | 200 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); |
| 221 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, true, request); | 201 backendDB()->get(m_transaction->id(), m_objectStore->id(), m_metadata.id, ke yRange, true, request); |
| 222 return request; | 202 return request; |
| 223 } | 203 } |
| 224 | 204 |
| 225 IDBDatabaseBackendInterface* IDBIndex::backendDB() const | 205 IDBDatabaseBackendInterface* IDBIndex::backendDB() const |
| 226 { | 206 { |
| 227 return m_transaction->backendDB(); | 207 return m_transaction->backendDB(); |
| 228 } | 208 } |
| 229 | 209 |
| 230 bool IDBIndex::isDeleted() const | 210 bool IDBIndex::isDeleted() const |
| 231 { | 211 { |
| 232 return m_deleted || m_objectStore->isDeleted(); | 212 return m_deleted || m_objectStore->isDeleted(); |
| 233 } | 213 } |
| 234 | 214 |
| 235 } // namespace WebCore | 215 } // namespace WebCore |
| OLD | NEW |