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

Side by Side Diff: Source/modules/indexeddb/IDBCursor.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/IDBCursor.h" 27 #include "modules/indexeddb/IDBCursor.h"
28 28
29 #include "bindings/v8/ExceptionState.h"
29 #include "bindings/v8/IDBBindingUtilities.h" 30 #include "bindings/v8/IDBBindingUtilities.h"
30 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
31 #include "core/dom/ScriptExecutionContext.h" 32 #include "core/dom/ScriptExecutionContext.h"
32 #include "core/inspector/ScriptCallStack.h" 33 #include "core/inspector/ScriptCallStack.h"
33 #include "modules/indexeddb/IDBAny.h" 34 #include "modules/indexeddb/IDBAny.h"
34 #include "modules/indexeddb/IDBCallbacks.h" 35 #include "modules/indexeddb/IDBCallbacks.h"
35 #include "modules/indexeddb/IDBCursorBackendInterface.h" 36 #include "modules/indexeddb/IDBCursorBackendInterface.h"
36 #include "modules/indexeddb/IDBKey.h" 37 #include "modules/indexeddb/IDBKey.h"
37 #include "modules/indexeddb/IDBObjectStore.h" 38 #include "modules/indexeddb/IDBObjectStore.h"
38 #include "modules/indexeddb/IDBRequest.h" 39 #include "modules/indexeddb/IDBRequest.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 { 115 {
115 IDB_TRACE("IDBCursor::value"); 116 IDB_TRACE("IDBCursor::value");
116 return m_currentValue; 117 return m_currentValue;
117 } 118 }
118 119
119 IDBAny* IDBCursor::source() const 120 IDBAny* IDBCursor::source() const
120 { 121 {
121 return m_source.get(); 122 return m_source.get();
122 } 123 }
123 124
124 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionCode& ec) 125 PassRefPtr<IDBRequest> IDBCursor::update(ScriptState* state, ScriptValue& value, ExceptionState& es)
125 { 126 {
126 IDB_TRACE("IDBCursor::update"); 127 IDB_TRACE("IDBCursor::update");
127 128
128 if (!m_gotValue || isKeyCursor() || isDeleted()) { 129 if (!m_gotValue || isKeyCursor() || isDeleted()) {
129 ec = InvalidStateError; 130 es.throwDOMException(InvalidStateError);
130 return 0; 131 return 0;
131 } 132 }
132 if (!m_transaction->isActive()) { 133 if (!m_transaction->isActive()) {
133 ec = TransactionInactiveError; 134 es.throwDOMException(TransactionInactiveError);
134 return 0; 135 return 0;
135 } 136 }
136 if (m_transaction->isReadOnly()) { 137 if (m_transaction->isReadOnly()) {
137 ec = ReadOnlyError; 138 es.throwDOMException(ReadOnlyError);
138 return 0; 139 return 0;
139 } 140 }
140 141
141 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore(); 142 RefPtr<IDBObjectStore> objectStore = effectiveObjectStore();
142 const IDBKeyPath& keyPath = objectStore->metadata().keyPath; 143 const IDBKeyPath& keyPath = objectStore->metadata().keyPath;
143 const bool usesInLineKeys = !keyPath.isNull(); 144 const bool usesInLineKeys = !keyPath.isNull();
144 if (usesInLineKeys) { 145 if (usesInLineKeys) {
145 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(m_requ est->requestState(), value, keyPath); 146 RefPtr<IDBKey> keyPathKey = createIDBKeyFromScriptValueAndKeyPath(m_requ est->requestState(), value, keyPath);
146 if (!keyPathKey || !keyPathKey->isEqual(m_currentPrimaryKey.get())) { 147 if (!keyPathKey || !keyPathKey->isEqual(m_currentPrimaryKey.get())) {
147 ec = DataError; 148 es.throwDOMException(DataError);
148 return 0; 149 return 0;
149 } 150 }
150 } 151 }
151 152
152 return objectStore->put(IDBDatabaseBackendInterface::CursorUpdate, IDBAny::c reate(this), state, value, m_currentPrimaryKey, ec); 153 return objectStore->put(IDBDatabaseBackendInterface::CursorUpdate, IDBAny::c reate(this), state, value, m_currentPrimaryKey, es);
153 } 154 }
154 155
155 void IDBCursor::advance(unsigned long count, ExceptionCode& ec) 156 void IDBCursor::advance(unsigned long count, ExceptionState& es)
156 { 157 {
157 ec = 0; 158 // es.throwDOMException(0);
158 IDB_TRACE("IDBCursor::advance"); 159 IDB_TRACE("IDBCursor::advance");
159 if (!m_gotValue || isDeleted()) { 160 if (!m_gotValue || isDeleted()) {
160 ec = InvalidStateError; 161 es.throwDOMException(InvalidStateError);
161 return; 162 return;
162 } 163 }
163 164
164 if (!m_transaction->isActive()) { 165 if (!m_transaction->isActive()) {
165 ec = TransactionInactiveError; 166 es.throwDOMException(TransactionInactiveError);
166 return; 167 return;
167 } 168 }
168 169
169 if (!count) { 170 if (!count) {
170 ec = TypeError; 171 es.throwTypeError();
171 return; 172 return;
172 } 173 }
173 174
174 m_request->setPendingCursor(this); 175 m_request->setPendingCursor(this);
175 m_gotValue = false; 176 m_gotValue = false;
176 m_backend->advance(count, m_request); 177 m_backend->advance(count, m_request);
177 } 178 }
178 179
179 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionCode& ec) 180 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionState& es)
180 { 181 {
181 DOMRequestState requestState(context); 182 DOMRequestState requestState(context);
182 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 183 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue);
183 continueFunction(key.release(), ec); 184 continueFunction(key.release(), es);
184 } 185 }
185 186
186 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionCode& ec) 187 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionState& es)
187 { 188 {
188 ec = 0; 189 // es.throwDOMException(0);
189 IDB_TRACE("IDBCursor::continue"); 190 IDB_TRACE("IDBCursor::continue");
190 if (key && !key->isValid()) { 191 if (key && !key->isValid()) {
191 ec = DataError; 192 es.throwDOMException(DataError);
192 return; 193 return;
193 } 194 }
194 195
195 if (!m_transaction->isActive()) { 196 if (!m_transaction->isActive()) {
196 ec = TransactionInactiveError; 197 es.throwDOMException(TransactionInactiveError);
197 return; 198 return;
198 } 199 }
199 200
200 if (!m_gotValue || isDeleted()) { 201 if (!m_gotValue || isDeleted()) {
201 ec = InvalidStateError; 202 es.throwDOMException(InvalidStateError);
202 return; 203 return;
203 } 204 }
204 205
205 if (key) { 206 if (key) {
206 ASSERT(m_currentKey); 207 ASSERT(m_currentKey);
207 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) { 208 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) {
208 if (!m_currentKey->isLessThan(key.get())) { 209 if (!m_currentKey->isLessThan(key.get())) {
209 ec = DataError; 210 es.throwDOMException(DataError);
210 return; 211 return;
211 } 212 }
212 } else { 213 } else {
213 if (!key->isLessThan(m_currentKey.get())) { 214 if (!key->isLessThan(m_currentKey.get())) {
214 ec = DataError; 215 es.throwDOMException(DataError);
215 return; 216 return;
216 } 217 }
217 } 218 }
218 } 219 }
219 220
220 // FIXME: We're not using the context from when continue was called, which m eans the callback 221 // FIXME: We're not using the context from when continue was called, which m eans the callback
221 // will be on the original context openCursor was called on. Is this right? 222 // will be on the original context openCursor was called on. Is this right?
222 m_request->setPendingCursor(this); 223 m_request->setPendingCursor(this);
223 m_gotValue = false; 224 m_gotValue = false;
224 m_backend->continueFunction(key, m_request); 225 m_backend->continueFunction(key, m_request);
225 } 226 }
226 227
227 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionCode& ec) 228 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionState& es)
228 { 229 {
229 ec = 0; 230 // es.throwDOMException(0);
230 IDB_TRACE("IDBCursor::delete"); 231 IDB_TRACE("IDBCursor::delete");
231 if (!m_transaction->isActive()) { 232 if (!m_transaction->isActive()) {
232 ec = TransactionInactiveError; 233 es.throwDOMException(TransactionInactiveError);
233 return 0; 234 return 0;
234 } 235 }
235 if (m_transaction->isReadOnly()) { 236 if (m_transaction->isReadOnly()) {
236 ec = ReadOnlyError; 237 es.throwDOMException(ReadOnlyError);
237 return 0; 238 return 0;
238 } 239 }
239 240
240 if (!m_gotValue || isKeyCursor() || isDeleted()) { 241 if (!m_gotValue || isKeyCursor() || isDeleted()) {
241 ec = InvalidStateError; 242 es.throwDOMException(InvalidStateError);
242 return 0; 243 return 0;
243 } 244 }
244 245
245 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, ec); 246 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, es);
246 ASSERT(!ec); 247 ASSERT(!es);
247 248
248 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 249 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get());
249 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, request); 250 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, request);
250 return request.release(); 251 return request.release();
251 } 252 }
252 253
253 void IDBCursor::postSuccessHandlerCallback() 254 void IDBCursor::postSuccessHandlerCallback()
254 { 255 {
255 m_backend->postSuccessHandlerCallback(); 256 m_backend->postSuccessHandlerCallback();
256 } 257 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return index->objectStore(); 299 return index->objectStore();
299 } 300 }
300 301
301 bool IDBCursor::isDeleted() const 302 bool IDBCursor::isDeleted() const
302 { 303 {
303 if (m_source->type() == IDBAny::IDBObjectStoreType) 304 if (m_source->type() == IDBAny::IDBObjectStoreType)
304 return m_source->idbObjectStore()->isDeleted(); 305 return m_source->idbObjectStore()->isDeleted();
305 return m_source->idbIndex()->isDeleted(); 306 return m_source->idbIndex()->isDeleted();
306 } 307 }
307 308
308 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionCode& ec) 309 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionState& es)
309 { 310 {
310 if (directionString.isNull() || directionString == IDBCursor::directionNext( )) 311 if (directionString.isNull() || directionString == IDBCursor::directionNext( ))
311 return IndexedDB::CursorNext; 312 return IndexedDB::CursorNext;
312 if (directionString == IDBCursor::directionNextUnique()) 313 if (directionString == IDBCursor::directionNextUnique())
313 return IndexedDB::CursorNextNoDuplicate; 314 return IndexedDB::CursorNextNoDuplicate;
314 if (directionString == IDBCursor::directionPrev()) 315 if (directionString == IDBCursor::directionPrev())
315 return IndexedDB::CursorPrev; 316 return IndexedDB::CursorPrev;
316 if (directionString == IDBCursor::directionPrevUnique()) 317 if (directionString == IDBCursor::directionPrevUnique())
317 return IndexedDB::CursorPrevNoDuplicate; 318 return IndexedDB::CursorPrevNoDuplicate;
318 319
319 ec = TypeError; 320 es.throwTypeError();
320 return IndexedDB::CursorNext; 321 return IndexedDB::CursorNext;
321 } 322 }
322 323
323 const AtomicString& IDBCursor::directionToString(unsigned short direction) 324 const AtomicString& IDBCursor::directionToString(unsigned short direction)
324 { 325 {
325 switch (direction) { 326 switch (direction) {
326 case IndexedDB::CursorNext: 327 case IndexedDB::CursorNext:
327 return IDBCursor::directionNext(); 328 return IDBCursor::directionNext();
328 329
329 case IndexedDB::CursorNextNoDuplicate: 330 case IndexedDB::CursorNextNoDuplicate:
330 return IDBCursor::directionNextUnique(); 331 return IDBCursor::directionNextUnique();
331 332
332 case IndexedDB::CursorPrev: 333 case IndexedDB::CursorPrev:
333 return IDBCursor::directionPrev(); 334 return IDBCursor::directionPrev();
334 335
335 case IndexedDB::CursorPrevNoDuplicate: 336 case IndexedDB::CursorPrevNoDuplicate:
336 return IDBCursor::directionPrevUnique(); 337 return IDBCursor::directionPrevUnique();
337 338
338 default: 339 default:
339 ASSERT_NOT_REACHED(); 340 ASSERT_NOT_REACHED();
340 return IDBCursor::directionNext(); 341 return IDBCursor::directionNext();
341 } 342 }
342 } 343 }
343 344
344 } // namespace WebCore 345 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698