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