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

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

Issue 18398002: Remove IDBNotFoundError ExceptionCode (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing include in code gen wich causes win compile failure Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
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
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 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 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 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 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "modules/indexeddb/IDBObjectStore.h" 27 #include "modules/indexeddb/IDBObjectStore.h"
28 28
29 #include "bindings/v8/ExceptionState.h"
30 #include "bindings/v8/ExceptionStatePlaceholder.h"
29 #include "bindings/v8/IDBBindingUtilities.h" 31 #include "bindings/v8/IDBBindingUtilities.h"
30 #include "bindings/v8/SerializedScriptValue.h" 32 #include "bindings/v8/SerializedScriptValue.h"
31 #include "core/dom/DOMStringList.h" 33 #include "core/dom/DOMStringList.h"
32 #include "core/dom/ExceptionCode.h" 34 #include "core/dom/ExceptionCode.h"
33 #include "core/dom/ExceptionCodePlaceholder.h"
34 #include "core/dom/ScriptExecutionContext.h" 35 #include "core/dom/ScriptExecutionContext.h"
35 #include "core/platform/SharedBuffer.h" 36 #include "core/platform/SharedBuffer.h"
36 #include "modules/indexeddb/IDBAny.h" 37 #include "modules/indexeddb/IDBAny.h"
37 #include "modules/indexeddb/IDBCursorWithValue.h" 38 #include "modules/indexeddb/IDBCursorWithValue.h"
38 #include "modules/indexeddb/IDBDatabase.h" 39 #include "modules/indexeddb/IDBDatabase.h"
39 #include "modules/indexeddb/IDBIndex.h" 40 #include "modules/indexeddb/IDBIndex.h"
40 #include "modules/indexeddb/IDBKey.h" 41 #include "modules/indexeddb/IDBKey.h"
41 #include "modules/indexeddb/IDBKeyPath.h" 42 #include "modules/indexeddb/IDBKeyPath.h"
42 #include "modules/indexeddb/IDBKeyRange.h" 43 #include "modules/indexeddb/IDBKeyRange.h"
43 #include "modules/indexeddb/IDBTracing.h" 44 #include "modules/indexeddb/IDBTracing.h"
(...skipping 18 matching lines...) Expand all
62 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const 63 PassRefPtr<DOMStringList> IDBObjectStore::indexNames() const
63 { 64 {
64 IDB_TRACE("IDBObjectStore::indexNames"); 65 IDB_TRACE("IDBObjectStore::indexNames");
65 RefPtr<DOMStringList> indexNames = DOMStringList::create(); 66 RefPtr<DOMStringList> indexNames = DOMStringList::create();
66 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) 67 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it)
67 indexNames->append(it->value.name); 68 indexNames->append(it->value.name);
68 indexNames->sort(); 69 indexNames->sort();
69 return indexNames.release(); 70 return indexNames.release();
70 } 71 }
71 72
72 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass RefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) 73 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, Pass RefPtr<IDBKeyRange> keyRange, ExceptionState& es)
73 { 74 {
74 IDB_TRACE("IDBObjectStore::get"); 75 IDB_TRACE("IDBObjectStore::get");
75 if (isDeleted()) { 76 if (isDeleted()) {
76 ec = InvalidStateError; 77 es.throwDOMException(InvalidStateError);
77 return 0; 78 return 0;
78 } 79 }
79 if (!keyRange) { 80 if (!keyRange) {
80 ec = DataError; 81 es.throwDOMException(DataError);
81 return 0; 82 return 0;
82 } 83 }
83 if (!m_transaction->isActive()) { 84 if (!m_transaction->isActive()) {
84 ec = TransactionInactiveError; 85 es.throwDOMException(TransactionInactiveError);
85 return 0; 86 return 0;
86 } 87 }
87 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 88 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
88 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request); 89 backendDB()->get(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, key Range, false, request);
89 return request.release(); 90 return request.release();
90 } 91 }
91 92
92 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons t ScriptValue& key, ExceptionCode& ec) 93 PassRefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext* context, cons t ScriptValue& key, ExceptionState& es)
93 { 94 {
94 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 95 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
95 if (ec) 96 if (es.hadException())
96 return 0; 97 return 0;
97 return get(context, keyRange.release(), ec); 98 return get(context, keyRange.release(), es);
98 } 99 }
99 100
100 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys) 101 static void generateIndexKeysForValue(DOMRequestState* requestState, const IDBIn dexMetadata& indexMetadata, const ScriptValue& objectValue, IDBObjectStore::Inde xKeys* indexKeys)
101 { 102 {
102 ASSERT(indexKeys); 103 ASSERT(indexKeys);
103 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath); 104 RefPtr<IDBKey> indexKey = createIDBKeyFromScriptValueAndKeyPath(requestState , objectValue, indexMetadata.keyPath);
104 105
105 if (!indexKey) 106 if (!indexKey)
106 return; 107 return;
107 108
108 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) { 109 if (!indexMetadata.multiEntry || indexKey->type() != IDBKey::ArrayType) {
109 if (!indexKey->isValid()) 110 if (!indexKey->isValid())
110 return; 111 return;
111 112
112 indexKeys->append(indexKey); 113 indexKeys->append(indexKey);
113 } else { 114 } else {
114 ASSERT(indexMetadata.multiEntry); 115 ASSERT(indexMetadata.multiEntry);
115 ASSERT(indexKey->type() == IDBKey::ArrayType); 116 ASSERT(indexKey->type() == IDBKey::ArrayType);
116 indexKey = IDBKey::createMultiEntryArray(indexKey->array()); 117 indexKey = IDBKey::createMultiEntryArray(indexKey->array());
117 118
118 for (size_t i = 0; i < indexKey->array().size(); ++i) 119 for (size_t i = 0; i < indexKey->array().size(); ++i)
119 indexKeys->append(indexKey->array()[i]); 120 indexKeys->append(indexKey->array()[i]);
120 } 121 }
121 } 122 }
122 123
123 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionCode& ec) 124 PassRefPtr<IDBRequest> IDBObjectStore::add(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& es)
124 { 125 {
125 IDB_TRACE("IDBObjectStore::add"); 126 IDB_TRACE("IDBObjectStore::add");
126 return put(IDBDatabaseBackendInterface::AddOnly, IDBAny::create(this), state , value, key, ec); 127 return put(IDBDatabaseBackendInterface::AddOnly, IDBAny::create(this), state , value, key, es);
127 } 128 }
128 129
129 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionCode& ec) 130 PassRefPtr<IDBRequest> IDBObjectStore::put(ScriptState* state, ScriptValue& valu e, const ScriptValue& key, ExceptionState& es)
130 { 131 {
131 IDB_TRACE("IDBObjectStore::put"); 132 IDB_TRACE("IDBObjectStore::put");
132 return put(IDBDatabaseBackendInterface::AddOrUpdate, IDBAny::create(this), s tate, value, key, ec); 133 return put(IDBDatabaseBackendInterface::AddOrUpdate, IDBAny::create(this), s tate, value, key, es);
133 } 134 }
134 135
135 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, cons t ScriptValue& keyValue, ExceptionCode& ec) 136 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, cons t ScriptValue& keyValue, ExceptionState& es)
136 { 137 {
137 ScriptExecutionContext* context = state->scriptExecutionContext(); 138 ScriptExecutionContext* context = state->scriptExecutionContext();
138 DOMRequestState requestState(context); 139 DOMRequestState requestState(context);
139 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 140 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue);
140 return put(putMode, source, state, value, key.release(), ec); 141 return put(putMode, source, state, value, key.release(), es);
141 } 142 }
142 143
143 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass RefPtr<IDBKey> prpKey, ExceptionCode& ec) 144 PassRefPtr<IDBRequest> IDBObjectStore::put(IDBDatabaseBackendInterface::PutMode putMode, PassRefPtr<IDBAny> source, ScriptState* state, ScriptValue& value, Pass RefPtr<IDBKey> prpKey, ExceptionState& es)
144 { 145 {
145 RefPtr<IDBKey> key = prpKey; 146 RefPtr<IDBKey> key = prpKey;
146 if (isDeleted()) { 147 if (isDeleted()) {
147 ec = InvalidStateError; 148 es.throwDOMException(InvalidStateError);
148 return 0; 149 return 0;
149 } 150 }
150 if (!m_transaction->isActive()) { 151 if (!m_transaction->isActive()) {
151 ec = TransactionInactiveError; 152 es.throwDOMException(TransactionInactiveError);
152 return 0; 153 return 0;
153 } 154 }
154 if (m_transaction->isReadOnly()) { 155 if (m_transaction->isReadOnly()) {
155 ec = ReadOnlyError; 156 es.throwDOMException(ReadOnlyError);
156 return 0; 157 return 0;
157 } 158 }
158 159
159 // FIXME: Expose the JS engine exception state through ScriptState. 160 // FIXME: Make serialize etc take an ExceptionState or use ScriptState::setD OMException.
160 bool didThrow = false; 161 bool didThrow = false;
161 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0, didThrow); 162 RefPtr<SerializedScriptValue> serializedValue = value.serialize(state, 0, 0, didThrow);
162 if (didThrow) { 163 if (didThrow)
163 // Setting an explicit ExceptionCode here would defer handling the alrea dy thrown exception. 164 return 0;
165
166 if (serializedValue->blobURLs().size() > 0) {
167 // FIXME: Add Blob/File/FileList support
168 es.throwDOMException(DataCloneError);
164 return 0; 169 return 0;
165 } 170 }
166 171
167 if (serializedValue->blobURLs().size() > 0) {
168 // FIXME: Add Blob/File/FileList support
169 ec = DataCloneError;
170 return 0;
171 }
172
173 const IDBKeyPath& keyPath = m_metadata.keyPath; 172 const IDBKeyPath& keyPath = m_metadata.keyPath;
174 const bool usesInLineKeys = !keyPath.isNull(); 173 const bool usesInLineKeys = !keyPath.isNull();
175 const bool hasKeyGenerator = autoIncrement(); 174 const bool hasKeyGenerator = autoIncrement();
176 175
177 ScriptExecutionContext* context = state->scriptExecutionContext(); 176 ScriptExecutionContext* context = state->scriptExecutionContext();
178 DOMRequestState requestState(context); 177 DOMRequestState requestState(context);
179 178
180 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) { 179 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) {
181 ec = DataError; 180 es.throwDOMException(DataError);
182 return 0; 181 return 0;
183 } 182 }
184 if (!usesInLineKeys && !hasKeyGenerator && !key) { 183 if (!usesInLineKeys && !hasKeyGenerator && !key) {
185 ec = DataError; 184 es.throwDOMException(DataError);
186 return 0; 185 return 0;
187 } 186 }
188 if (usesInLineKeys) { 187 if (usesInLineKeys) {
189 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath); 188 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath);
190 if (keyPathKey && !keyPathKey->isValid()) { 189 if (keyPathKey && !keyPathKey->isValid()) {
191 ec = DataError; 190 es.throwDOMException(DataError);
192 return 0; 191 return 0;
193 } 192 }
194 if (!hasKeyGenerator && !keyPathKey) { 193 if (!hasKeyGenerator && !keyPathKey) {
195 ec = DataError; 194 es.throwDOMException(DataError);
196 return 0; 195 return 0;
197 } 196 }
198 if (hasKeyGenerator && !keyPathKey) { 197 if (hasKeyGenerator && !keyPathKey) {
199 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) { 198 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
200 ec = DataError; 199 es.throwDOMException(DataError);
201 return 0; 200 return 0;
202 } 201 }
203 } 202 }
204 if (keyPathKey) 203 if (keyPathKey)
205 key = keyPathKey; 204 key = keyPathKey;
206 } 205 }
207 if (key && !key->isValid()) { 206 if (key && !key->isValid()) {
208 ec = DataError; 207 es.throwDOMException(DataError);
209 return 0; 208 return 0;
210 } 209 }
211 210
212 Vector<int64_t> indexIds; 211 Vector<int64_t> indexIds;
213 Vector<IndexKeys> indexKeys; 212 Vector<IndexKeys> indexKeys;
214 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 213 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
215 IndexKeys keys; 214 IndexKeys keys;
216 generateIndexKeysForValue(&requestState, it->value, value, &keys); 215 generateIndexKeysForValue(&requestState, it->value, value, &keys);
217 indexIds.append(it->key); 216 indexIds.append(it->key);
218 indexKeys.append(keys); 217 indexKeys.append(keys);
219 } 218 }
220 219
221 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 220 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
222 Vector<char> wireBytes; 221 Vector<char> wireBytes;
223 serializedValue->toWireBytes(wireBytes); 222 serializedValue->toWireBytes(wireBytes);
224 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 223 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes);
225 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys); 224 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys);
226 return request.release(); 225 return request.release();
227 } 226 }
228 227
229 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) 228 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionState& es)
230 { 229 {
231 IDB_TRACE("IDBObjectStore::delete"); 230 IDB_TRACE("IDBObjectStore::delete");
232 if (isDeleted()) { 231 if (isDeleted()) {
233 ec = InvalidStateError; 232 es.throwDOMException(InvalidStateError);
234 return 0; 233 return 0;
235 } 234 }
236 if (!m_transaction->isActive()) { 235 if (!m_transaction->isActive()) {
237 ec = TransactionInactiveError; 236 es.throwDOMException(TransactionInactiveError);
238 return 0; 237 return 0;
239 } 238 }
240 if (m_transaction->isReadOnly()) { 239 if (m_transaction->isReadOnly()) {
241 ec = ReadOnlyError; 240 es.throwDOMException(ReadOnlyError);
242 return 0; 241 return 0;
243 } 242 }
244 if (!keyRange) { 243 if (!keyRange) {
245 ec = DataError; 244 es.throwDOMException(DataError);
246 return 0; 245 return 0;
247 } 246 }
248 247
249 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 248 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
250 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); 249 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request);
251 return request.release(); 250 return request.release();
252 } 251 }
253 252
254 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionCode& ec) 253 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionState& es)
255 { 254 {
256 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 255 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
257 if (ec) 256 if (es.hadException())
258 return 0; 257 return 0;
259 return deleteFunction(context, keyRange.release(), ec); 258 return deleteFunction(context, keyRange.release(), es);
260 } 259 }
261 260
262 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionCode& ec) 261 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionState& es)
263 { 262 {
264 IDB_TRACE("IDBObjectStore::clear"); 263 IDB_TRACE("IDBObjectStore::clear");
265 if (isDeleted()) { 264 if (isDeleted()) {
266 ec = InvalidStateError; 265 es.throwDOMException(InvalidStateError);
267 return 0; 266 return 0;
268 } 267 }
269 if (!m_transaction->isActive()) { 268 if (!m_transaction->isActive()) {
270 ec = TransactionInactiveError; 269 es.throwDOMException(TransactionInactiveError);
271 return 0; 270 return 0;
272 } 271 }
273 if (m_transaction->isReadOnly()) { 272 if (m_transaction->isReadOnly()) {
274 ec = ReadOnlyError; 273 es.throwDOMException(ReadOnlyError);
275 return 0; 274 return 0;
276 } 275 }
277 276
278 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 277 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
279 backendDB()->clear(m_transaction->id(), id(), request); 278 backendDB()->clear(m_transaction->id(), id(), request);
280 return request.release(); 279 return request.release();
281 } 280 }
282 281
283 namespace { 282 namespace {
284 // This class creates the index keys for a given index by extracting 283 // This class creates the index keys for a given index by extracting
(...skipping 22 matching lines...) Expand all
307 , m_indexMetadata(indexMetadata) 306 , m_indexMetadata(indexMetadata)
308 { 307 {
309 } 308 }
310 309
311 virtual void handleEvent(ScriptExecutionContext*, Event* event) 310 virtual void handleEvent(ScriptExecutionContext*, Event* event)
312 { 311 {
313 ASSERT(event->type() == eventNames().successEvent); 312 ASSERT(event->type() == eventNames().successEvent);
314 EventTarget* target = event->target(); 313 EventTarget* target = event->target();
315 IDBRequest* request = static_cast<IDBRequest*>(target); 314 IDBRequest* request = static_cast<IDBRequest*>(target);
316 315
317 RefPtr<IDBAny> cursorAny = request->result(ASSERT_NO_EXCEPTION); 316 RefPtr<IDBAny> cursorAny = request->result(ASSERT_NO_EXCEPTION_STATE);
318 RefPtr<IDBCursorWithValue> cursor; 317 RefPtr<IDBCursorWithValue> cursor;
319 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) 318 if (cursorAny->type() == IDBAny::IDBCursorWithValueType)
320 cursor = cursorAny->idbCursorWithValue(); 319 cursor = cursorAny->idbCursorWithValue();
321 320
322 Vector<int64_t, 1> indexIds; 321 Vector<int64_t, 1> indexIds;
323 indexIds.append(m_indexMetadata.id); 322 indexIds.append(m_indexMetadata.id);
324 if (cursor) { 323 if (cursor) {
325 cursor->continueFunction(static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTIO N); 324 cursor->continueFunction(static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTIO N_STATE);
326 325
327 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey(); 326 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey();
328 ScriptValue value = cursor->value(); 327 ScriptValue value = cursor->value();
329 328
330 IDBObjectStore::IndexKeys indexKeys; 329 IDBObjectStore::IndexKeys indexKeys;
331 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys); 330 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys);
332 331
333 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList; 332 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList;
334 indexKeysList.append(indexKeys); 333 indexKeysList.append(indexKeys);
335 334
336 m_databaseBackend->setIndexKeys(m_transactionId, m_objectStoreId, pr imaryKey, indexIds, indexKeysList); 335 m_databaseBackend->setIndexKeys(m_transactionId, m_objectStoreId, pr imaryKey, indexIds, indexKeysList);
337 } else { 336 } else {
338 // Now that we are done indexing, tell the backend to go 337 // Now that we are done indexing, tell the backend to go
339 // back to processing tasks of type NormalTask. 338 // back to processing tasks of type NormalTask.
340 m_databaseBackend->setIndexesReady(m_transactionId, m_objectStoreId, indexIds); 339 m_databaseBackend->setIndexesReady(m_transactionId, m_objectStoreId, indexIds);
341 m_databaseBackend.clear(); 340 m_databaseBackend.clear();
342 } 341 }
343 342
344 } 343 }
345 344
346 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend; 345 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend;
347 const int64_t m_transactionId; 346 const int64_t m_transactionId;
348 const int64_t m_objectStoreId; 347 const int64_t m_objectStoreId;
349 const IDBIndexMetadata m_indexMetadata; 348 const IDBIndexMetadata m_indexMetadata;
350 }; 349 };
351 } 350 }
352 351
353 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, const Dictionary& options, Exce ptionCode& ec) 352 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, const Dictionary& options, Exce ptionState& es)
354 { 353 {
355 bool unique = false; 354 bool unique = false;
356 options.get("unique", unique); 355 options.get("unique", unique);
357 356
358 bool multiEntry = false; 357 bool multiEntry = false;
359 options.get("multiEntry", multiEntry); 358 options.get("multiEntry", multiEntry);
360 359
361 return createIndex(context, name, keyPath, unique, multiEntry, ec); 360 return createIndex(context, name, keyPath, unique, multiEntry, es);
362 } 361 }
363 362
364 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E xceptionCode& ec) 363 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E xceptionState& es)
365 { 364 {
366 IDB_TRACE("IDBObjectStore::createIndex"); 365 IDB_TRACE("IDBObjectStore::createIndex");
367 if (!m_transaction->isVersionChange() || isDeleted()) { 366 if (!m_transaction->isVersionChange() || isDeleted()) {
368 ec = InvalidStateError; 367 es.throwDOMException(InvalidStateError);
369 return 0; 368 return 0;
370 } 369 }
371 if (!m_transaction->isActive()) { 370 if (!m_transaction->isActive()) {
372 ec = TransactionInactiveError; 371 es.throwDOMException(TransactionInactiveError);
373 return 0; 372 return 0;
374 } 373 }
375 if (!keyPath.isValid()) { 374 if (!keyPath.isValid()) {
376 ec = SyntaxError; 375 es.throwDOMException(SyntaxError);
377 return 0; 376 return 0;
378 } 377 }
379 if (name.isNull()) { 378 if (name.isNull()) {
380 ec = TypeError; 379 es.throwTypeError();
381 return 0; 380 return 0;
382 } 381 }
383 if (containsIndex(name)) { 382 if (containsIndex(name)) {
384 ec = ConstraintError; 383 es.throwDOMException(ConstraintError);
385 return 0; 384 return 0;
386 } 385 }
387 386
388 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { 387 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
389 ec = InvalidAccessError; 388 es.throwDOMException(InvalidAccessError);
390 return 0; 389 return 0;
391 } 390 }
392 391
393 int64_t indexId = m_metadata.maxIndexId + 1; 392 int64_t indexId = m_metadata.maxIndexId + 1;
394 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry); 393 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
395 394
396 ++m_metadata.maxIndexId; 395 ++m_metadata.maxIndexId;
397 396
398 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 397 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
399 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 398 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
400 m_indexMap.set(name, index); 399 m_indexMap.set(name, index);
401 m_metadata.indexes.set(indexId, metadata); 400 m_metadata.indexes.set(indexId, metadata);
402 m_transaction->db()->indexCreated(id(), metadata); 401 m_transaction->db()->indexCreated(id(), metadata);
403 402
404 ASSERT(!ec); 403 ASSERT(!es.hadException());
405 if (ec) 404 if (es.hadException())
406 return 0; 405 return 0;
407 406
408 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IDBCursor::directionNext(), IDBDatabaseBackendInterface::PreemptiveTask, ec); 407 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IDBCursor::directionNext(), IDBDatabaseBackendInterface::PreemptiveTask, es);
409 ASSERT(!ec); 408 ASSERT(!es.hadException());
410 if (ec) 409 if (es.hadException())
411 return 0; 410 return 0;
412 indexRequest->preventPropagation(); 411 indexRequest->preventPropagation();
413 412
414 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 413 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction.
415 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata); 414 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata);
416 indexRequest->setOnsuccess(indexPopulator); 415 indexRequest->setOnsuccess(indexPopulator);
417 416
418 return index.release(); 417 return index.release();
419 } 418 }
420 419
421 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionCode& ec ) 420 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e s)
422 { 421 {
423 IDB_TRACE("IDBObjectStore::index"); 422 IDB_TRACE("IDBObjectStore::index");
424 if (isDeleted()) { 423 if (isDeleted()) {
425 ec = InvalidStateError; 424 es.throwDOMException(InvalidStateError);
426 return 0; 425 return 0;
427 } 426 }
428 if (m_transaction->isFinished()) { 427 if (m_transaction->isFinished()) {
429 ec = InvalidStateError; 428 es.throwDOMException(InvalidStateError);
430 return 0; 429 return 0;
431 } 430 }
432 431
433 IDBIndexMap::iterator it = m_indexMap.find(name); 432 IDBIndexMap::iterator it = m_indexMap.find(name);
434 if (it != m_indexMap.end()) 433 if (it != m_indexMap.end())
435 return it->value; 434 return it->value;
436 435
437 int64_t indexId = findIndexId(name); 436 int64_t indexId = findIndexId(name);
438 if (indexId == IDBIndexMetadata::InvalidId) { 437 if (indexId == IDBIndexMetadata::InvalidId) {
439 // FIXME: Should use (NotFoundError, "..."). 438 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
440 ec = IDBNotFoundError;
441 return 0; 439 return 0;
442 } 440 }
443 441
444 const IDBIndexMetadata* indexMetadata(0); 442 const IDBIndexMetadata* indexMetadata(0);
445 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 443 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
446 if (it->value.name == name) { 444 if (it->value.name == name) {
447 indexMetadata = &it->value; 445 indexMetadata = &it->value;
448 break; 446 break;
449 } 447 }
450 } 448 }
451 ASSERT(indexMetadata); 449 ASSERT(indexMetadata);
452 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); 450 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId);
453 451
454 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get()); 452 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get());
455 m_indexMap.set(name, index); 453 m_indexMap.set(name, index);
456 return index.release(); 454 return index.release();
457 } 455 }
458 456
459 void IDBObjectStore::deleteIndex(const String& name, ExceptionCode& ec) 457 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es)
460 { 458 {
461 IDB_TRACE("IDBObjectStore::deleteIndex"); 459 IDB_TRACE("IDBObjectStore::deleteIndex");
462 if (!m_transaction->isVersionChange() || isDeleted()) { 460 if (!m_transaction->isVersionChange() || isDeleted()) {
463 ec = InvalidStateError; 461 es.throwDOMException(InvalidStateError);
464 return; 462 return;
465 } 463 }
466 if (!m_transaction->isActive()) { 464 if (!m_transaction->isActive()) {
467 ec = TransactionInactiveError; 465 es.throwDOMException(TransactionInactiveError);
468 return; 466 return;
469 } 467 }
470 int64_t indexId = findIndexId(name); 468 int64_t indexId = findIndexId(name);
471 if (indexId == IDBIndexMetadata::InvalidId) { 469 if (indexId == IDBIndexMetadata::InvalidId) {
472 // FIXME: Should use (NotFoundError, "..."). 470 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
473 ec = IDBNotFoundError;
474 return; 471 return;
475 } 472 }
476 473
477 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); 474 backendDB()->deleteIndex(m_transaction->id(), id(), indexId);
478 475
479 m_metadata.indexes.remove(indexId); 476 m_metadata.indexes.remove(indexId);
480 m_transaction->db()->indexDeleted(id(), indexId); 477 m_transaction->db()->indexDeleted(id(), indexId);
481 IDBIndexMap::iterator it = m_indexMap.find(name); 478 IDBIndexMap::iterator it = m_indexMap.find(name);
482 if (it != m_indexMap.end()) { 479 if (it != m_indexMap.end()) {
483 it->value->markDeleted(); 480 it->value->markDeleted();
484 m_indexMap.remove(name); 481 m_indexMap.remove(name);
485 } 482 }
486 } 483 }
487 484
488 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack endInterface::TaskType taskType, ExceptionCode& ec) 485 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack endInterface::TaskType taskType, ExceptionState& es)
489 { 486 {
490 IDB_TRACE("IDBObjectStore::openCursor"); 487 IDB_TRACE("IDBObjectStore::openCursor");
491 if (isDeleted()) { 488 if (isDeleted()) {
492 ec = InvalidStateError; 489 es.throwDOMException(InvalidStateError);
493 return 0; 490 return 0;
494 } 491 }
495 if (!m_transaction->isActive()) { 492 if (!m_transaction->isActive()) {
496 ec = TransactionInactiveError; 493 es.throwDOMException(TransactionInactiveError);
497 return 0; 494 return 0;
498 } 495 }
499 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, ec); 496 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es);
500 if (ec) 497 if (es.hadException())
501 return 0; 498 return 0;
502 499
503 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 500 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
504 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 501 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
505 502
506 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>( taskType), request); 503 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>( taskType), request);
507 return request.release(); 504 return request.release();
508 } 505 }
509 506
510 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& key, const String& direction, ExceptionCode& ec) 507 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& key, const String& direction, ExceptionState& es)
511 { 508 {
512 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 509 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
513 if (ec) 510 if (es.hadException())
514 return 0; 511 return 0;
515 return openCursor(context, keyRange.release(), direction, ec); 512 return openCursor(context, keyRange.release(), direction, es);
516 } 513 }
517 514
518 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa ssRefPtr<IDBKeyRange> range, ExceptionCode& ec) 515 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa ssRefPtr<IDBKeyRange> range, ExceptionState& es)
519 { 516 {
520 IDB_TRACE("IDBObjectStore::count"); 517 IDB_TRACE("IDBObjectStore::count");
521 if (isDeleted()) { 518 if (isDeleted()) {
522 ec = InvalidStateError; 519 es.throwDOMException(InvalidStateError);
523 return 0; 520 return 0;
524 } 521 }
525 if (!m_transaction->isActive()) { 522 if (!m_transaction->isActive()) {
526 ec = TransactionInactiveError; 523 es.throwDOMException(TransactionInactiveError);
527 return 0; 524 return 0;
528 } 525 }
529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 526 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
530 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r ange, request); 527 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r ange, request);
531 return request.release(); 528 return request.release();
532 } 529 }
533 530
534 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& key, ExceptionCode& ec) 531 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& key, ExceptionState& es)
535 { 532 {
536 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 533 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
537 if (ec) 534 if (es.hadException())
538 return 0; 535 return 0;
539 return count(context, keyRange.release(), ec); 536 return count(context, keyRange.release(), es);
540 } 537 }
541 538
542 void IDBObjectStore::transactionFinished() 539 void IDBObjectStore::transactionFinished()
543 { 540 {
544 ASSERT(m_transaction->isFinished()); 541 ASSERT(m_transaction->isFinished());
545 542
546 // Break reference cycles. 543 // Break reference cycles.
547 m_indexMap.clear(); 544 m_indexMap.clear();
548 } 545 }
549 546
550 int64_t IDBObjectStore::findIndexId(const String& name) const 547 int64_t IDBObjectStore::findIndexId(const String& name) const
551 { 548 {
552 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 549 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
553 if (it->value.name == name) { 550 if (it->value.name == name) {
554 ASSERT(it->key != IDBIndexMetadata::InvalidId); 551 ASSERT(it->key != IDBIndexMetadata::InvalidId);
555 return it->key; 552 return it->key;
556 } 553 }
557 } 554 }
558 return IDBIndexMetadata::InvalidId; 555 return IDBIndexMetadata::InvalidId;
559 } 556 }
560 557
561 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const 558 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const
562 { 559 {
563 return m_transaction->backendDB(); 560 return m_transaction->backendDB();
564 } 561 }
565 562
566 } // namespace WebCore 563 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698