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

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: 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/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 IDB_TRACE("IDBCursor::advance"); 158 IDB_TRACE("IDBCursor::advance");
159 if (!m_gotValue || isDeleted()) { 159 if (!m_gotValue || isDeleted()) {
160 ec = InvalidStateError; 160 es.throwDOMException(InvalidStateError);
161 return; 161 return;
162 } 162 }
163 163
164 if (!m_transaction->isActive()) { 164 if (!m_transaction->isActive()) {
165 ec = TransactionInactiveError; 165 es.throwDOMException(TransactionInactiveError);
166 return; 166 return;
167 } 167 }
168 168
169 if (!count) { 169 if (!count) {
170 ec = TypeError; 170 es.throwTypeError();
171 return; 171 return;
172 } 172 }
173 173
174 m_request->setPendingCursor(this); 174 m_request->setPendingCursor(this);
175 m_gotValue = false; 175 m_gotValue = false;
176 m_backend->advance(count, m_request); 176 m_backend->advance(count, m_request);
177 } 177 }
178 178
179 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionCode& ec) 179 void IDBCursor::continueFunction(ScriptExecutionContext* context, const ScriptVa lue& keyValue, ExceptionState& es)
180 { 180 {
181 DOMRequestState requestState(context); 181 DOMRequestState requestState(context);
182 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue); 182 RefPtr<IDBKey> key = keyValue.isUndefined() ? 0 : scriptValueToIDBKey(&reque stState, keyValue);
183 continueFunction(key.release(), ec); 183 continueFunction(key.release(), es);
184 } 184 }
185 185
186 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionCode& ec) 186 void IDBCursor::continueFunction(PassRefPtr<IDBKey> key, ExceptionState& es)
187 { 187 {
188 ec = 0;
189 IDB_TRACE("IDBCursor::continue"); 188 IDB_TRACE("IDBCursor::continue");
190 if (key && !key->isValid()) { 189 if (key && !key->isValid()) {
191 ec = DataError; 190 es.throwDOMException(DataError);
192 return; 191 return;
193 } 192 }
194 193
195 if (!m_transaction->isActive()) { 194 if (!m_transaction->isActive()) {
196 ec = TransactionInactiveError; 195 es.throwDOMException(TransactionInactiveError);
197 return; 196 return;
198 } 197 }
199 198
200 if (!m_gotValue || isDeleted()) { 199 if (!m_gotValue || isDeleted()) {
201 ec = InvalidStateError; 200 es.throwDOMException(InvalidStateError);
202 return; 201 return;
203 } 202 }
204 203
205 if (key) { 204 if (key) {
206 ASSERT(m_currentKey); 205 ASSERT(m_currentKey);
207 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) { 206 if (m_direction == IndexedDB::CursorNext || m_direction == IndexedDB::Cu rsorNextNoDuplicate) {
208 if (!m_currentKey->isLessThan(key.get())) { 207 if (!m_currentKey->isLessThan(key.get())) {
209 ec = DataError; 208 es.throwDOMException(DataError);
210 return; 209 return;
211 } 210 }
212 } else { 211 } else {
213 if (!key->isLessThan(m_currentKey.get())) { 212 if (!key->isLessThan(m_currentKey.get())) {
214 ec = DataError; 213 es.throwDOMException(DataError);
215 return; 214 return;
216 } 215 }
217 } 216 }
218 } 217 }
219 218
220 // FIXME: We're not using the context from when continue was called, which m eans the callback 219 // 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? 220 // will be on the original context openCursor was called on. Is this right?
222 m_request->setPendingCursor(this); 221 m_request->setPendingCursor(this);
223 m_gotValue = false; 222 m_gotValue = false;
224 m_backend->continueFunction(key, m_request); 223 m_backend->continueFunction(key, m_request);
225 } 224 }
226 225
227 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionCode& ec) 226 PassRefPtr<IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext* context , ExceptionState& es)
228 { 227 {
229 ec = 0;
230 IDB_TRACE("IDBCursor::delete"); 228 IDB_TRACE("IDBCursor::delete");
231 if (!m_transaction->isActive()) { 229 if (!m_transaction->isActive()) {
232 ec = TransactionInactiveError; 230 es.throwDOMException(TransactionInactiveError);
233 return 0; 231 return 0;
234 } 232 }
235 if (m_transaction->isReadOnly()) { 233 if (m_transaction->isReadOnly()) {
236 ec = ReadOnlyError; 234 es.throwDOMException(ReadOnlyError);
237 return 0; 235 return 0;
238 } 236 }
239 237
240 if (!m_gotValue || isKeyCursor() || isDeleted()) { 238 if (!m_gotValue || isKeyCursor() || isDeleted()) {
241 ec = InvalidStateError; 239 es.throwDOMException(InvalidStateError);
242 return 0; 240 return 0;
243 } 241 }
244 242
245 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, ec); 243 RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(m_currentPrimaryKey, es);
246 ASSERT(!ec); 244 ASSERT(!es);
247 245
248 RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this ), m_transaction.get()); 246 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); 247 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject Store()->id(), keyRange, request);
250 return request.release(); 248 return request.release();
251 } 249 }
252 250
253 void IDBCursor::postSuccessHandlerCallback() 251 void IDBCursor::postSuccessHandlerCallback()
254 { 252 {
255 m_backend->postSuccessHandlerCallback(); 253 m_backend->postSuccessHandlerCallback();
256 } 254 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return index->objectStore(); 296 return index->objectStore();
299 } 297 }
300 298
301 bool IDBCursor::isDeleted() const 299 bool IDBCursor::isDeleted() const
302 { 300 {
303 if (m_source->type() == IDBAny::IDBObjectStoreType) 301 if (m_source->type() == IDBAny::IDBObjectStoreType)
304 return m_source->idbObjectStore()->isDeleted(); 302 return m_source->idbObjectStore()->isDeleted();
305 return m_source->idbIndex()->isDeleted(); 303 return m_source->idbIndex()->isDeleted();
306 } 304 }
307 305
308 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionCode& ec) 306 IndexedDB::CursorDirection IDBCursor::stringToDirection(const String& directionS tring, ExceptionState& es)
309 { 307 {
310 if (directionString.isNull() || directionString == IDBCursor::directionNext( )) 308 if (directionString.isNull() || directionString == IDBCursor::directionNext( ))
311 return IndexedDB::CursorNext; 309 return IndexedDB::CursorNext;
312 if (directionString == IDBCursor::directionNextUnique()) 310 if (directionString == IDBCursor::directionNextUnique())
313 return IndexedDB::CursorNextNoDuplicate; 311 return IndexedDB::CursorNextNoDuplicate;
314 if (directionString == IDBCursor::directionPrev()) 312 if (directionString == IDBCursor::directionPrev())
315 return IndexedDB::CursorPrev; 313 return IndexedDB::CursorPrev;
316 if (directionString == IDBCursor::directionPrevUnique()) 314 if (directionString == IDBCursor::directionPrevUnique())
317 return IndexedDB::CursorPrevNoDuplicate; 315 return IndexedDB::CursorPrevNoDuplicate;
318 316
319 ec = TypeError; 317 es.throwTypeError();
320 return IndexedDB::CursorNext; 318 return IndexedDB::CursorNext;
321 } 319 }
322 320
323 const AtomicString& IDBCursor::directionToString(unsigned short direction) 321 const AtomicString& IDBCursor::directionToString(unsigned short direction)
324 { 322 {
325 switch (direction) { 323 switch (direction) {
326 case IndexedDB::CursorNext: 324 case IndexedDB::CursorNext:
327 return IDBCursor::directionNext(); 325 return IDBCursor::directionNext();
328 326
329 case IndexedDB::CursorNextNoDuplicate: 327 case IndexedDB::CursorNextNoDuplicate:
330 return IDBCursor::directionNextUnique(); 328 return IDBCursor::directionNextUnique();
331 329
332 case IndexedDB::CursorPrev: 330 case IndexedDB::CursorPrev:
333 return IDBCursor::directionPrev(); 331 return IDBCursor::directionPrev();
334 332
335 case IndexedDB::CursorPrevNoDuplicate: 333 case IndexedDB::CursorPrevNoDuplicate:
336 return IDBCursor::directionPrevUnique(); 334 return IDBCursor::directionPrevUnique();
337 335
338 default: 336 default:
339 ASSERT_NOT_REACHED(); 337 ASSERT_NOT_REACHED();
340 return IDBCursor::directionNext(); 338 return IDBCursor::directionNext();
341 } 339 }
342 } 340 }
343 341
344 } // namespace WebCore 342 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698