| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); | 87 wrapper = ScriptWrappable::associateWithWrapper(isolate, wrapperType, wrappe
r); |
| 88 if (!wrapper.IsEmpty()) | 88 if (!wrapper.IsEmpty()) |
| 89 V8HiddenValue::setHiddenValue(ScriptState::current(isolate), wrapper, V8
HiddenValue::idbCursorRequest(isolate), toV8(m_request.get(), wrapper, isolate))
; | 89 V8HiddenValue::setHiddenValue(ScriptState::current(isolate), wrapper, V8
HiddenValue::idbCursorRequest(isolate), toV8(m_request.get(), wrapper, isolate))
; |
| 90 return wrapper; | 90 return wrapper; |
| 91 } | 91 } |
| 92 | 92 |
| 93 IDBRequest* IDBCursor::update(ScriptState* scriptState, const ScriptValue& value
, ExceptionState& exceptionState) | 93 IDBRequest* IDBCursor::update(ScriptState* scriptState, const ScriptValue& value
, ExceptionState& exceptionState) |
| 94 { | 94 { |
| 95 IDB_TRACE("IDBCursor::update"); | 95 IDB_TRACE("IDBCursor::update"); |
| 96 | 96 |
| 97 if (!m_gotValue) { | |
| 98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); | |
| 99 return nullptr; | |
| 100 } | |
| 101 if (isKeyCursor()) { | |
| 102 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu
rsorErrorMessage); | |
| 103 return nullptr; | |
| 104 } | |
| 105 if (isDeleted()) { | |
| 106 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | |
| 107 return nullptr; | |
| 108 } | |
| 109 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 97 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 110 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 98 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 111 return nullptr; | 99 return nullptr; |
| 112 } | 100 } |
| 113 if (!m_transaction->isActive()) { | 101 if (!m_transaction->isActive()) { |
| 114 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 102 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 115 return nullptr; | 103 return nullptr; |
| 116 } | 104 } |
| 117 if (m_transaction->isReadOnly()) { | 105 if (m_transaction->isReadOnly()) { |
| 118 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); | 106 exceptionState.throwDOMException(ReadOnlyError, "The record may not be u
pdated inside a read-only transaction."); |
| 119 return nullptr; | 107 return nullptr; |
| 120 } | 108 } |
| 109 if (isDeleted()) { |
| 110 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 111 return nullptr; |
| 112 } |
| 113 if (!m_gotValue) { |
| 114 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 115 return nullptr; |
| 116 } |
| 117 if (isKeyCursor()) { |
| 118 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu
rsorErrorMessage); |
| 119 return nullptr; |
| 120 } |
| 121 | 121 |
| 122 IDBObjectStore* objectStore = effectiveObjectStore(); | 122 IDBObjectStore* objectStore = effectiveObjectStore(); |
| 123 return objectStore->put(scriptState, WebIDBPutModeCursorUpdate, IDBAny::crea
te(this), value, m_primaryKey, exceptionState); | 123 return objectStore->put(scriptState, WebIDBPutModeCursorUpdate, IDBAny::crea
te(this), value, m_primaryKey, exceptionState); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void IDBCursor::advance(unsigned count, ExceptionState& exceptionState) | 126 void IDBCursor::advance(unsigned count, ExceptionState& exceptionState) |
| 127 { | 127 { |
| 128 IDB_TRACE("IDBCursor::advance"); | 128 IDB_TRACE("IDBCursor::advance"); |
| 129 if (!count) { | 129 if (!count) { |
| 130 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); | 130 exceptionState.throwTypeError("A count argument with value 0 (zero) was
supplied, must be greater than 0."); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 133 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 134 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 134 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 if (!m_transaction->isActive()) { | 137 if (!m_transaction->isActive()) { |
| 138 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 138 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 139 return; | 139 return; |
| 140 } | 140 } |
| 141 if (isDeleted()) { |
| 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 143 return; |
| 144 } |
| 141 if (!m_gotValue) { | 145 if (!m_gotValue) { |
| 142 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); | 146 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 143 return; | 147 return; |
| 144 } | 148 } |
| 145 if (isDeleted()) { | |
| 146 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | |
| 147 return; | |
| 148 } | |
| 149 | 149 |
| 150 m_request->setPendingCursor(this); | 150 m_request->setPendingCursor(this); |
| 151 m_gotValue = false; | 151 m_gotValue = false; |
| 152 m_backend->advance(count, WebIDBCallbacksImpl::create(m_request).release()); | 152 m_backend->advance(count, WebIDBCallbacksImpl::create(m_request).release()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& ke
yValue, ExceptionState& exceptionState) | 155 void IDBCursor::continueFunction(ScriptState* scriptState, const ScriptValue& ke
yValue, ExceptionState& exceptionState) |
| 156 { | 156 { |
| 157 IDB_TRACE("IDBCursor::continue"); | 157 IDB_TRACE("IDBCursor::continue"); |
| 158 |
| 159 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 160 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 161 return; |
| 162 } |
| 163 if (!m_transaction->isActive()) { |
| 164 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 165 return; |
| 166 } |
| 167 if (!m_gotValue) { |
| 168 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 169 return; |
| 170 } |
| 171 if (isDeleted()) { |
| 172 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 173 return; |
| 174 } |
| 175 |
| 158 IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : Script
Value::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState); | 176 IDBKey* key = keyValue.isUndefined() || keyValue.isNull() ? nullptr : Script
Value::to<IDBKey*>(scriptState->isolate(), keyValue, exceptionState); |
| 159 if (exceptionState.hadException()) | 177 if (exceptionState.hadException()) |
| 160 return; | 178 return; |
| 161 if (key && !key->isValid()) { | 179 if (key && !key->isValid()) { |
| 162 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 180 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 163 return; | 181 return; |
| 164 } | 182 } |
| 165 continueFunction(key, nullptr, exceptionState); | 183 continueFunction(key, nullptr, exceptionState); |
| 166 } | 184 } |
| 167 | 185 |
| 168 void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) | 186 void IDBCursor::continuePrimaryKey(ScriptState* scriptState, const ScriptValue&
keyValue, const ScriptValue& primaryKeyValue, ExceptionState& exceptionState) |
| 169 { | 187 { |
| 170 IDB_TRACE("IDBCursor::continuePrimaryKey"); | 188 IDB_TRACE("IDBCursor::continuePrimaryKey"); |
| 189 |
| 190 if (m_transaction->isFinished() || m_transaction->isFinishing()) { |
| 191 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); |
| 192 return; |
| 193 } |
| 194 if (!m_transaction->isActive()) { |
| 195 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 196 return; |
| 197 } |
| 198 if (!m_gotValue) { |
| 199 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 200 return; |
| 201 } |
| 202 if (isDeleted()) { |
| 203 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 204 return; |
| 205 } |
| 206 |
| 171 if (m_source->getType() != IDBAny::IDBIndexType) { | 207 if (m_source->getType() != IDBAny::IDBIndexType) { |
| 172 exceptionState.throwDOMException(InvalidAccessError, "The cursor's sourc
e is not an index."); | 208 exceptionState.throwDOMException(InvalidAccessError, "The cursor's sourc
e is not an index."); |
| 173 return; | 209 return; |
| 174 } | 210 } |
| 175 if (m_direction != WebIDBCursorDirectionNext && m_direction != WebIDBCursorD
irectionPrev) { | 211 if (m_direction != WebIDBCursorDirectionNext && m_direction != WebIDBCursorD
irectionPrev) { |
| 176 exceptionState.throwDOMException(InvalidAccessError, "The cursor's direc
tion is not 'next' or 'prev'."); | 212 exceptionState.throwDOMException(InvalidAccessError, "The cursor's direc
tion is not 'next' or 'prev'."); |
| 177 return; | 213 return; |
| 178 } | 214 } |
| 179 | 215 |
| 180 IDBKey* key = ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exc
eptionState); | 216 IDBKey* key = ScriptValue::to<IDBKey*>(scriptState->isolate(), keyValue, exc
eptionState); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 191 if (!primaryKey->isValid()) { | 227 if (!primaryKey->isValid()) { |
| 192 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); | 228 exceptionState.throwDOMException(DataError, IDBDatabase::notValidKeyErro
rMessage); |
| 193 return; | 229 return; |
| 194 } | 230 } |
| 195 | 231 |
| 196 continueFunction(key, primaryKey, exceptionState); | 232 continueFunction(key, primaryKey, exceptionState); |
| 197 } | 233 } |
| 198 | 234 |
| 199 void IDBCursor::continueFunction(IDBKey* key, IDBKey* primaryKey, ExceptionState
& exceptionState) | 235 void IDBCursor::continueFunction(IDBKey* key, IDBKey* primaryKey, ExceptionState
& exceptionState) |
| 200 { | 236 { |
| 201 ASSERT(!primaryKey || (key && primaryKey)); | 237 DCHECK(m_transaction->isActive()); |
| 202 | 238 DCHECK(m_gotValue); |
| 203 if (m_transaction->isFinished() || m_transaction->isFinishing()) { | 239 DCHECK(!isDeleted()); |
| 204 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionFinishedErrorMessage); | 240 DCHECK(!primaryKey || (key && primaryKey)); |
| 205 return; | |
| 206 } | |
| 207 if (!m_transaction->isActive()) { | |
| 208 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | |
| 209 return; | |
| 210 } | |
| 211 | |
| 212 if (!m_gotValue) { | |
| 213 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); | |
| 214 return; | |
| 215 } | |
| 216 | |
| 217 if (isDeleted()) { | |
| 218 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | |
| 219 return; | |
| 220 } | |
| 221 | 241 |
| 222 if (key) { | 242 if (key) { |
| 223 ASSERT(m_key); | 243 DCHECK(m_key); |
| 224 if (m_direction == WebIDBCursorDirectionNext || m_direction == WebIDBCur
sorDirectionNextNoDuplicate) { | 244 if (m_direction == WebIDBCursorDirectionNext || m_direction == WebIDBCur
sorDirectionNextNoDuplicate) { |
| 225 const bool ok = m_key->isLessThan(key) | 245 const bool ok = m_key->isLessThan(key) |
| 226 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); | 246 || (primaryKey && m_key->isEqual(key) && m_primaryKey->isLessTha
n(primaryKey)); |
| 227 if (!ok) { | 247 if (!ok) { |
| 228 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); | 248 exceptionState.throwDOMException(DataError, "The parameter is le
ss than or equal to this cursor's position."); |
| 229 return; | 249 return; |
| 230 } | 250 } |
| 231 | 251 |
| 232 } else { | 252 } else { |
| 233 const bool ok = key->isLessThan(m_key.get()) | 253 const bool ok = key->isLessThan(m_key.get()) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 254 return nullptr; | 274 return nullptr; |
| 255 } | 275 } |
| 256 if (!m_transaction->isActive()) { | 276 if (!m_transaction->isActive()) { |
| 257 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); | 277 exceptionState.throwDOMException(TransactionInactiveError, IDBDatabase::
transactionInactiveErrorMessage); |
| 258 return nullptr; | 278 return nullptr; |
| 259 } | 279 } |
| 260 if (m_transaction->isReadOnly()) { | 280 if (m_transaction->isReadOnly()) { |
| 261 exceptionState.throwDOMException(ReadOnlyError, "The record may not be d
eleted inside a read-only transaction."); | 281 exceptionState.throwDOMException(ReadOnlyError, "The record may not be d
eleted inside a read-only transaction."); |
| 262 return nullptr; | 282 return nullptr; |
| 263 } | 283 } |
| 264 | 284 if (isDeleted()) { |
| 285 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); |
| 286 return nullptr; |
| 287 } |
| 265 if (!m_gotValue) { | 288 if (!m_gotValue) { |
| 266 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); | 289 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::noValue
ErrorMessage); |
| 267 return nullptr; | 290 return nullptr; |
| 268 } | 291 } |
| 269 if (isKeyCursor()) { | 292 if (isKeyCursor()) { |
| 270 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu
rsorErrorMessage); | 293 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::isKeyCu
rsorErrorMessage); |
| 271 return nullptr; | 294 return nullptr; |
| 272 } | 295 } |
| 273 if (isDeleted()) { | |
| 274 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::sourceD
eletedErrorMessage); | |
| 275 return nullptr; | |
| 276 } | |
| 277 if (!m_transaction->backendDB()) { | 296 if (!m_transaction->backendDB()) { |
| 278 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); | 297 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::databas
eClosedErrorMessage); |
| 279 return nullptr; | 298 return nullptr; |
| 280 } | 299 } |
| 281 | 300 |
| 282 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState); | 301 IDBKeyRange* keyRange = IDBKeyRange::only(m_primaryKey, exceptionState); |
| 283 ASSERT(!exceptionState.hadException()); | 302 ASSERT(!exceptionState.hadException()); |
| 284 | 303 |
| 285 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); | 304 IDBRequest* request = IDBRequest::create(scriptState, IDBAny::create(this),
m_transaction.get()); |
| 286 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject
Store()->id(), keyRange, WebIDBCallbacksImpl::create(request).release()); | 305 m_transaction->backendDB()->deleteRange(m_transaction->id(), effectiveObject
Store()->id(), keyRange, WebIDBCallbacksImpl::create(request).release()); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 case WebIDBCursorDirectionPrevNoDuplicate: | 420 case WebIDBCursorDirectionPrevNoDuplicate: |
| 402 return IndexedDBNames::prevunique; | 421 return IndexedDBNames::prevunique; |
| 403 | 422 |
| 404 default: | 423 default: |
| 405 ASSERT_NOT_REACHED(); | 424 ASSERT_NOT_REACHED(); |
| 406 return IndexedDBNames::next; | 425 return IndexedDBNames::next; |
| 407 } | 426 } |
| 408 } | 427 } |
| 409 | 428 |
| 410 } // namespace blink | 429 } // namespace blink |
| OLD | NEW |