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

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: 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: Expose the JS engine exception state through ScriptState.
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 // Setting an explicit ExceptionState here would defer handling the alre ady thrown exception.
jsbell 2013/07/10 00:41:32 This comment should probably be reworded. And poss
arv (Not doing code reviews) 2013/07/10 02:12:59 ScriptState keeps the last exception but only for
164 return 0; 165 return 0;
165 } 166 }
166 167
167 if (serializedValue->blobURLs().size() > 0) { 168 if (serializedValue->blobURLs().size() > 0) {
168 // FIXME: Add Blob/File/FileList support 169 // FIXME: Add Blob/File/FileList support
169 ec = DataCloneError; 170 es.throwDOMException(DataCloneError);
170 return 0; 171 return 0;
171 } 172 }
172 173
173 const IDBKeyPath& keyPath = m_metadata.keyPath; 174 const IDBKeyPath& keyPath = m_metadata.keyPath;
174 const bool usesInLineKeys = !keyPath.isNull(); 175 const bool usesInLineKeys = !keyPath.isNull();
175 const bool hasKeyGenerator = autoIncrement(); 176 const bool hasKeyGenerator = autoIncrement();
176 177
177 ScriptExecutionContext* context = state->scriptExecutionContext(); 178 ScriptExecutionContext* context = state->scriptExecutionContext();
178 DOMRequestState requestState(context); 179 DOMRequestState requestState(context);
179 180
180 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) { 181 if (putMode != IDBDatabaseBackendInterface::CursorUpdate && usesInLineKeys & & key) {
181 ec = DataError; 182 es.throwDOMException(DataError);
182 return 0; 183 return 0;
183 } 184 }
184 if (!usesInLineKeys && !hasKeyGenerator && !key) { 185 if (!usesInLineKeys && !hasKeyGenerator && !key) {
185 ec = DataError; 186 es.throwDOMException(DataError);
186 return 0; 187 return 0;
187 } 188 }
188 if (usesInLineKeys) { 189 if (usesInLineKeys) {
189 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath); 190 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(&reque stState, value, keyPath);
190 if (keyPathKey && !keyPathKey->isValid()) { 191 if (keyPathKey && !keyPathKey->isValid()) {
191 ec = DataError; 192 es.throwDOMException(DataError);
192 return 0; 193 return 0;
193 } 194 }
194 if (!hasKeyGenerator && !keyPathKey) { 195 if (!hasKeyGenerator && !keyPathKey) {
195 ec = DataError; 196 es.throwDOMException(DataError);
196 return 0; 197 return 0;
197 } 198 }
198 if (hasKeyGenerator && !keyPathKey) { 199 if (hasKeyGenerator && !keyPathKey) {
199 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) { 200 if (!canInjectIDBKeyIntoScriptValue(&requestState, value, keyPath)) {
200 ec = DataError; 201 es.throwDOMException(DataError);
201 return 0; 202 return 0;
202 } 203 }
203 } 204 }
204 if (keyPathKey) 205 if (keyPathKey)
205 key = keyPathKey; 206 key = keyPathKey;
206 } 207 }
207 if (key && !key->isValid()) { 208 if (key && !key->isValid()) {
208 ec = DataError; 209 es.throwDOMException(DataError);
209 return 0; 210 return 0;
210 } 211 }
211 212
212 Vector<int64_t> indexIds; 213 Vector<int64_t> indexIds;
213 Vector<IndexKeys> indexKeys; 214 Vector<IndexKeys> indexKeys;
214 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 215 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
215 IndexKeys keys; 216 IndexKeys keys;
216 generateIndexKeysForValue(&requestState, it->value, value, &keys); 217 generateIndexKeysForValue(&requestState, it->value, value, &keys);
217 indexIds.append(it->key); 218 indexIds.append(it->key);
218 indexKeys.append(keys); 219 indexKeys.append(keys);
219 } 220 }
220 221
221 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get()); 222 RefPtr<IDBRequest> request = IDBRequest::create(context, source, m_transacti on.get());
222 Vector<char> wireBytes; 223 Vector<char> wireBytes;
223 serializedValue->toWireBytes(wireBytes); 224 serializedValue->toWireBytes(wireBytes);
224 RefPtr<SharedBuffer> valueBuffer = SharedBuffer::adoptVector(wireBytes); 225 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); 226 backendDB()->put(m_transaction->id(), id(), valueBuffer, key.release(), stat ic_cast<IDBDatabaseBackendInterface::PutMode>(putMode), request, indexIds, index Keys);
226 return request.release(); 227 return request.release();
227 } 228 }
228 229
229 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionCode& ec) 230 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, PassRefPtr<IDBKeyRange> keyRange, ExceptionState& es)
230 { 231 {
231 IDB_TRACE("IDBObjectStore::delete"); 232 IDB_TRACE("IDBObjectStore::delete");
232 if (isDeleted()) { 233 if (isDeleted()) {
233 ec = InvalidStateError; 234 es.throwDOMException(InvalidStateError);
234 return 0; 235 return 0;
235 } 236 }
236 if (!m_transaction->isActive()) { 237 if (!m_transaction->isActive()) {
237 ec = TransactionInactiveError; 238 es.throwDOMException(TransactionInactiveError);
238 return 0; 239 return 0;
239 } 240 }
240 if (m_transaction->isReadOnly()) { 241 if (m_transaction->isReadOnly()) {
241 ec = ReadOnlyError; 242 es.throwDOMException(ReadOnlyError);
242 return 0; 243 return 0;
243 } 244 }
244 if (!keyRange) { 245 if (!keyRange) {
245 ec = DataError; 246 es.throwDOMException(DataError);
246 return 0; 247 return 0;
247 } 248 }
248 249
249 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 250 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
250 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request); 251 backendDB()->deleteRange(m_transaction->id(), id(), keyRange, request);
251 return request.release(); 252 return request.release();
252 } 253 }
253 254
254 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionCode& ec) 255 PassRefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext* co ntext, const ScriptValue& key, ExceptionState& es)
255 { 256 {
256 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 257 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
257 if (ec) 258 if (es.hadException())
258 return 0; 259 return 0;
259 return deleteFunction(context, keyRange.release(), ec); 260 return deleteFunction(context, keyRange.release(), es);
260 } 261 }
261 262
262 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionCode& ec) 263 PassRefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext* context, Ex ceptionState& es)
263 { 264 {
264 IDB_TRACE("IDBObjectStore::clear"); 265 IDB_TRACE("IDBObjectStore::clear");
265 if (isDeleted()) { 266 if (isDeleted()) {
266 ec = InvalidStateError; 267 es.throwDOMException(InvalidStateError);
267 return 0; 268 return 0;
268 } 269 }
269 if (!m_transaction->isActive()) { 270 if (!m_transaction->isActive()) {
270 ec = TransactionInactiveError; 271 es.throwDOMException(TransactionInactiveError);
271 return 0; 272 return 0;
272 } 273 }
273 if (m_transaction->isReadOnly()) { 274 if (m_transaction->isReadOnly()) {
274 ec = ReadOnlyError; 275 es.throwDOMException(ReadOnlyError);
275 return 0; 276 return 0;
276 } 277 }
277 278
278 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 279 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
279 backendDB()->clear(m_transaction->id(), id(), request); 280 backendDB()->clear(m_transaction->id(), id(), request);
280 return request.release(); 281 return request.release();
281 } 282 }
282 283
283 namespace { 284 namespace {
284 // This class creates the index keys for a given index by extracting 285 // This class creates the index keys for a given index by extracting
(...skipping 22 matching lines...) Expand all
307 , m_indexMetadata(indexMetadata) 308 , m_indexMetadata(indexMetadata)
308 { 309 {
309 } 310 }
310 311
311 virtual void handleEvent(ScriptExecutionContext*, Event* event) 312 virtual void handleEvent(ScriptExecutionContext*, Event* event)
312 { 313 {
313 ASSERT(event->type() == eventNames().successEvent); 314 ASSERT(event->type() == eventNames().successEvent);
314 EventTarget* target = event->target(); 315 EventTarget* target = event->target();
315 IDBRequest* request = static_cast<IDBRequest*>(target); 316 IDBRequest* request = static_cast<IDBRequest*>(target);
316 317
317 RefPtr<IDBAny> cursorAny = request->result(ASSERT_NO_EXCEPTION); 318 RefPtr<IDBAny> cursorAny = request->result(ASSERT_NO_EXCEPTION_STATE);
318 RefPtr<IDBCursorWithValue> cursor; 319 RefPtr<IDBCursorWithValue> cursor;
319 if (cursorAny->type() == IDBAny::IDBCursorWithValueType) 320 if (cursorAny->type() == IDBAny::IDBCursorWithValueType)
320 cursor = cursorAny->idbCursorWithValue(); 321 cursor = cursorAny->idbCursorWithValue();
321 322
322 Vector<int64_t, 1> indexIds; 323 Vector<int64_t, 1> indexIds;
323 indexIds.append(m_indexMetadata.id); 324 indexIds.append(m_indexMetadata.id);
324 if (cursor) { 325 if (cursor) {
325 cursor->continueFunction(static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTIO N); 326 cursor->continueFunction(static_cast<IDBKey*>(0), ASSERT_NO_EXCEPTIO N_STATE);
326 327
327 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey(); 328 RefPtr<IDBKey> primaryKey = cursor->idbPrimaryKey();
328 ScriptValue value = cursor->value(); 329 ScriptValue value = cursor->value();
329 330
330 IDBObjectStore::IndexKeys indexKeys; 331 IDBObjectStore::IndexKeys indexKeys;
331 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys); 332 generateIndexKeysForValue(request->requestState(), m_indexMetadata, value, &indexKeys);
332 333
333 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList; 334 Vector<IDBObjectStore::IndexKeys, 1> indexKeysList;
334 indexKeysList.append(indexKeys); 335 indexKeysList.append(indexKeys);
335 336
336 m_databaseBackend->setIndexKeys(m_transactionId, m_objectStoreId, pr imaryKey, indexIds, indexKeysList); 337 m_databaseBackend->setIndexKeys(m_transactionId, m_objectStoreId, pr imaryKey, indexIds, indexKeysList);
337 } else { 338 } else {
338 // Now that we are done indexing, tell the backend to go 339 // Now that we are done indexing, tell the backend to go
339 // back to processing tasks of type NormalTask. 340 // back to processing tasks of type NormalTask.
340 m_databaseBackend->setIndexesReady(m_transactionId, m_objectStoreId, indexIds); 341 m_databaseBackend->setIndexesReady(m_transactionId, m_objectStoreId, indexIds);
341 m_databaseBackend.clear(); 342 m_databaseBackend.clear();
342 } 343 }
343 344
344 } 345 }
345 346
346 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend; 347 RefPtr<IDBDatabaseBackendInterface> m_databaseBackend;
347 const int64_t m_transactionId; 348 const int64_t m_transactionId;
348 const int64_t m_objectStoreId; 349 const int64_t m_objectStoreId;
349 const IDBIndexMetadata m_indexMetadata; 350 const IDBIndexMetadata m_indexMetadata;
350 }; 351 };
351 } 352 }
352 353
353 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, const Dictionary& options, Exce ptionCode& ec) 354 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, const Dictionary& options, Exce ptionState& es)
354 { 355 {
355 bool unique = false; 356 bool unique = false;
356 options.get("unique", unique); 357 options.get("unique", unique);
357 358
358 bool multiEntry = false; 359 bool multiEntry = false;
359 options.get("multiEntry", multiEntry); 360 options.get("multiEntry", multiEntry);
360 361
361 return createIndex(context, name, keyPath, unique, multiEntry, ec); 362 return createIndex(context, name, keyPath, unique, multiEntry, es);
362 } 363 }
363 364
364 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E xceptionCode& ec) 365 PassRefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext* context , const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, E xceptionState& es)
365 { 366 {
366 IDB_TRACE("IDBObjectStore::createIndex"); 367 IDB_TRACE("IDBObjectStore::createIndex");
367 if (!m_transaction->isVersionChange() || isDeleted()) { 368 if (!m_transaction->isVersionChange() || isDeleted()) {
368 ec = InvalidStateError; 369 es.throwDOMException(InvalidStateError);
369 return 0; 370 return 0;
370 } 371 }
371 if (!m_transaction->isActive()) { 372 if (!m_transaction->isActive()) {
372 ec = TransactionInactiveError; 373 es.throwDOMException(TransactionInactiveError);
373 return 0; 374 return 0;
374 } 375 }
375 if (!keyPath.isValid()) { 376 if (!keyPath.isValid()) {
376 ec = SyntaxError; 377 es.throwDOMException(SyntaxError);
377 return 0; 378 return 0;
378 } 379 }
379 if (name.isNull()) { 380 if (name.isNull()) {
380 ec = TypeError; 381 es.throwTypeError();
381 return 0; 382 return 0;
382 } 383 }
383 if (containsIndex(name)) { 384 if (containsIndex(name)) {
384 ec = ConstraintError; 385 es.throwDOMException(ConstraintError);
385 return 0; 386 return 0;
386 } 387 }
387 388
388 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) { 389 if (keyPath.type() == IDBKeyPath::ArrayType && multiEntry) {
389 ec = InvalidAccessError; 390 es.throwDOMException(InvalidAccessError);
390 return 0; 391 return 0;
391 } 392 }
392 393
393 int64_t indexId = m_metadata.maxIndexId + 1; 394 int64_t indexId = m_metadata.maxIndexId + 1;
394 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry); 395 backendDB()->createIndex(m_transaction->id(), id(), indexId, name, keyPath, unique, multiEntry);
395 396
396 ++m_metadata.maxIndexId; 397 ++m_metadata.maxIndexId;
397 398
398 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry); 399 IDBIndexMetadata metadata(name, indexId, keyPath, unique, multiEntry);
399 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( )); 400 RefPtr<IDBIndex> index = IDBIndex::create(metadata, this, m_transaction.get( ));
400 m_indexMap.set(name, index); 401 m_indexMap.set(name, index);
401 m_metadata.indexes.set(indexId, metadata); 402 m_metadata.indexes.set(indexId, metadata);
402 m_transaction->db()->indexCreated(id(), metadata); 403 m_transaction->db()->indexCreated(id(), metadata);
403 404
404 ASSERT(!ec); 405 ASSERT(!es.hadException());
405 if (ec) 406 if (es.hadException())
406 return 0; 407 return 0;
407 408
408 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IDBCursor::directionNext(), IDBDatabaseBackendInterface::PreemptiveTask, ec); 409 RefPtr<IDBRequest> indexRequest = openCursor(context, static_cast<IDBKeyRang e*>(0), IDBCursor::directionNext(), IDBDatabaseBackendInterface::PreemptiveTask, es);
409 ASSERT(!ec); 410 ASSERT(!es.hadException());
410 if (ec) 411 if (es.hadException())
411 return 0; 412 return 0;
412 indexRequest->preventPropagation(); 413 indexRequest->preventPropagation();
413 414
414 // This is kept alive by being the success handler of the request, which is in turn kept alive by the owning transaction. 415 // 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); 416 RefPtr<IndexPopulator> indexPopulator = IndexPopulator::create(backendDB(), m_transaction->id(), id(), metadata);
416 indexRequest->setOnsuccess(indexPopulator); 417 indexRequest->setOnsuccess(indexPopulator);
417 418
418 return index.release(); 419 return index.release();
419 } 420 }
420 421
421 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionCode& ec ) 422 PassRefPtr<IDBIndex> IDBObjectStore::index(const String& name, ExceptionState& e s)
422 { 423 {
423 IDB_TRACE("IDBObjectStore::index"); 424 IDB_TRACE("IDBObjectStore::index");
424 if (isDeleted()) { 425 if (isDeleted()) {
425 ec = InvalidStateError; 426 es.throwDOMException(InvalidStateError);
426 return 0; 427 return 0;
427 } 428 }
428 if (m_transaction->isFinished()) { 429 if (m_transaction->isFinished()) {
429 ec = InvalidStateError; 430 es.throwDOMException(InvalidStateError);
430 return 0; 431 return 0;
431 } 432 }
432 433
433 IDBIndexMap::iterator it = m_indexMap.find(name); 434 IDBIndexMap::iterator it = m_indexMap.find(name);
434 if (it != m_indexMap.end()) 435 if (it != m_indexMap.end())
435 return it->value; 436 return it->value;
436 437
437 int64_t indexId = findIndexId(name); 438 int64_t indexId = findIndexId(name);
438 if (indexId == IDBIndexMetadata::InvalidId) { 439 if (indexId == IDBIndexMetadata::InvalidId) {
439 // FIXME: Should use (NotFoundError, "..."). 440 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
440 ec = IDBNotFoundError;
441 return 0; 441 return 0;
442 } 442 }
443 443
444 const IDBIndexMetadata* indexMetadata(0); 444 const IDBIndexMetadata* indexMetadata(0);
445 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 445 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
446 if (it->value.name == name) { 446 if (it->value.name == name) {
447 indexMetadata = &it->value; 447 indexMetadata = &it->value;
448 break; 448 break;
449 } 449 }
450 } 450 }
451 ASSERT(indexMetadata); 451 ASSERT(indexMetadata);
452 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId); 452 ASSERT(indexMetadata->id != IDBIndexMetadata::InvalidId);
453 453
454 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get()); 454 RefPtr<IDBIndex> index = IDBIndex::create(*indexMetadata, this, m_transactio n.get());
455 m_indexMap.set(name, index); 455 m_indexMap.set(name, index);
456 return index.release(); 456 return index.release();
457 } 457 }
458 458
459 void IDBObjectStore::deleteIndex(const String& name, ExceptionCode& ec) 459 void IDBObjectStore::deleteIndex(const String& name, ExceptionState& es)
460 { 460 {
461 IDB_TRACE("IDBObjectStore::deleteIndex"); 461 IDB_TRACE("IDBObjectStore::deleteIndex");
462 if (!m_transaction->isVersionChange() || isDeleted()) { 462 if (!m_transaction->isVersionChange() || isDeleted()) {
463 ec = InvalidStateError; 463 es.throwDOMException(InvalidStateError);
464 return; 464 return;
465 } 465 }
466 if (!m_transaction->isActive()) { 466 if (!m_transaction->isActive()) {
467 ec = TransactionInactiveError; 467 es.throwDOMException(TransactionInactiveError);
468 return; 468 return;
469 } 469 }
470 int64_t indexId = findIndexId(name); 470 int64_t indexId = findIndexId(name);
471 if (indexId == IDBIndexMetadata::InvalidId) { 471 if (indexId == IDBIndexMetadata::InvalidId) {
472 // FIXME: Should use (NotFoundError, "..."). 472 es.throwDOMException(NotFoundError, IDBDatabase::notFoundErrorMessage);
473 ec = IDBNotFoundError;
474 return; 473 return;
475 } 474 }
476 475
477 backendDB()->deleteIndex(m_transaction->id(), id(), indexId); 476 backendDB()->deleteIndex(m_transaction->id(), id(), indexId);
478 477
479 m_metadata.indexes.remove(indexId); 478 m_metadata.indexes.remove(indexId);
480 m_transaction->db()->indexDeleted(id(), indexId); 479 m_transaction->db()->indexDeleted(id(), indexId);
481 IDBIndexMap::iterator it = m_indexMap.find(name); 480 IDBIndexMap::iterator it = m_indexMap.find(name);
482 if (it != m_indexMap.end()) { 481 if (it != m_indexMap.end()) {
483 it->value->markDeleted(); 482 it->value->markDeleted();
484 m_indexMap.remove(name); 483 m_indexMap.remove(name);
485 } 484 }
486 } 485 }
487 486
488 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack endInterface::TaskType taskType, ExceptionCode& ec) 487 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, PassRefPtr<IDBKeyRange> range, const String& directionString, IDBDatabaseBack endInterface::TaskType taskType, ExceptionState& es)
489 { 488 {
490 IDB_TRACE("IDBObjectStore::openCursor"); 489 IDB_TRACE("IDBObjectStore::openCursor");
491 if (isDeleted()) { 490 if (isDeleted()) {
492 ec = InvalidStateError; 491 es.throwDOMException(InvalidStateError);
493 return 0; 492 return 0;
494 } 493 }
495 if (!m_transaction->isActive()) { 494 if (!m_transaction->isActive()) {
496 ec = TransactionInactiveError; 495 es.throwDOMException(TransactionInactiveError);
497 return 0; 496 return 0;
498 } 497 }
499 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, ec); 498 IndexedDB::CursorDirection direction = IDBCursor::stringToDirection(directio nString, es);
500 if (ec) 499 if (es.hadException())
501 return 0; 500 return 0;
502 501
503 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 502 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
504 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction); 503 request->setCursorDetails(IndexedDB::CursorKeyAndValue, direction);
505 504
506 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>( taskType), request); 505 backendDB()->openCursor(m_transaction->id(), id(), IDBIndexMetadata::Invalid Id, range, direction, false, static_cast<IDBDatabaseBackendInterface::TaskType>( taskType), request);
507 return request.release(); 506 return request.release();
508 } 507 }
509 508
510 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& key, const String& direction, ExceptionCode& ec) 509 PassRefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext* contex t, const ScriptValue& key, const String& direction, ExceptionState& es)
511 { 510 {
512 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 511 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
513 if (ec) 512 if (es.hadException())
514 return 0; 513 return 0;
515 return openCursor(context, keyRange.release(), direction, ec); 514 return openCursor(context, keyRange.release(), direction, es);
516 } 515 }
517 516
518 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa ssRefPtr<IDBKeyRange> range, ExceptionCode& ec) 517 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, Pa ssRefPtr<IDBKeyRange> range, ExceptionState& es)
519 { 518 {
520 IDB_TRACE("IDBObjectStore::count"); 519 IDB_TRACE("IDBObjectStore::count");
521 if (isDeleted()) { 520 if (isDeleted()) {
522 ec = InvalidStateError; 521 es.throwDOMException(InvalidStateError);
523 return 0; 522 return 0;
524 } 523 }
525 if (!m_transaction->isActive()) { 524 if (!m_transaction->isActive()) {
526 ec = TransactionInactiveError; 525 es.throwDOMException(TransactionInactiveError);
527 return 0; 526 return 0;
528 } 527 }
529 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 528 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
530 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r ange, request); 529 backendDB()->count(m_transaction->id(), id(), IDBIndexMetadata::InvalidId, r ange, request);
531 return request.release(); 530 return request.release();
532 } 531 }
533 532
534 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& key, ExceptionCode& ec) 533 PassRefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext* context, co nst ScriptValue& key, ExceptionState& es)
535 { 534 {
536 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec); 535 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, es);
537 if (ec) 536 if (es.hadException())
538 return 0; 537 return 0;
539 return count(context, keyRange.release(), ec); 538 return count(context, keyRange.release(), es);
540 } 539 }
541 540
542 void IDBObjectStore::transactionFinished() 541 void IDBObjectStore::transactionFinished()
543 { 542 {
544 ASSERT(m_transaction->isFinished()); 543 ASSERT(m_transaction->isFinished());
545 544
546 // Break reference cycles. 545 // Break reference cycles.
547 m_indexMap.clear(); 546 m_indexMap.clear();
548 } 547 }
549 548
550 int64_t IDBObjectStore::findIndexId(const String& name) const 549 int64_t IDBObjectStore::findIndexId(const String& name) const
551 { 550 {
552 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) { 551 for (IDBObjectStoreMetadata::IndexMap::const_iterator it = m_metadata.indexe s.begin(); it != m_metadata.indexes.end(); ++it) {
553 if (it->value.name == name) { 552 if (it->value.name == name) {
554 ASSERT(it->key != IDBIndexMetadata::InvalidId); 553 ASSERT(it->key != IDBIndexMetadata::InvalidId);
555 return it->key; 554 return it->key;
556 } 555 }
557 } 556 }
558 return IDBIndexMetadata::InvalidId; 557 return IDBIndexMetadata::InvalidId;
559 } 558 }
560 559
561 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const 560 IDBDatabaseBackendInterface* IDBObjectStore::backendDB() const
562 { 561 {
563 return m_transaction->backendDB(); 562 return m_transaction->backendDB();
564 } 563 }
565 564
566 } // namespace WebCore 565 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698