| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 : ActiveScriptWrappable(this) | 64 : ActiveScriptWrappable(this) |
| 65 , ActiveDOMObject(scriptState->getExecutionContext()) | 65 , ActiveDOMObject(scriptState->getExecutionContext()) |
| 66 , m_transaction(transaction) | 66 , m_transaction(transaction) |
| 67 , m_scriptState(scriptState) | 67 , m_scriptState(scriptState) |
| 68 , m_source(source) | 68 , m_source(source) |
| 69 { | 69 { |
| 70 } | 70 } |
| 71 | 71 |
| 72 IDBRequest::~IDBRequest() | 72 IDBRequest::~IDBRequest() |
| 73 { | 73 { |
| 74 ASSERT(m_readyState == DONE || m_readyState == EarlyDeath || !getExecutionCo
ntext()); | 74 DCHECK(m_readyState == DONE || m_readyState == EarlyDeath || !getExecutionCo
ntext()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 DEFINE_TRACE(IDBRequest) | 77 DEFINE_TRACE(IDBRequest) |
| 78 { | 78 { |
| 79 visitor->trace(m_transaction); | 79 visitor->trace(m_transaction); |
| 80 visitor->trace(m_source); | 80 visitor->trace(m_source); |
| 81 visitor->trace(m_result); | 81 visitor->trace(m_result); |
| 82 visitor->trace(m_error); | 82 visitor->trace(m_error); |
| 83 visitor->trace(m_enqueuedEvents); | 83 visitor->trace(m_enqueuedEvents); |
| 84 visitor->trace(m_pendingCursor); | 84 visitor->trace(m_pendingCursor); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 ScriptValue IDBRequest::source() const | 116 ScriptValue IDBRequest::source() const |
| 117 { | 117 { |
| 118 if (m_contextStopped || !getExecutionContext()) | 118 if (m_contextStopped || !getExecutionContext()) |
| 119 return ScriptValue(); | 119 return ScriptValue(); |
| 120 | 120 |
| 121 return ScriptValue::from(m_scriptState.get(), m_source); | 121 return ScriptValue::from(m_scriptState.get(), m_source); |
| 122 } | 122 } |
| 123 | 123 |
| 124 const String& IDBRequest::readyState() const | 124 const String& IDBRequest::readyState() const |
| 125 { | 125 { |
| 126 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 126 DCHECK(m_readyState == PENDING || m_readyState == DONE); |
| 127 | 127 |
| 128 if (m_readyState == PENDING) | 128 if (m_readyState == PENDING) |
| 129 return IndexedDBNames::pending; | 129 return IndexedDBNames::pending; |
| 130 | 130 |
| 131 return IndexedDBNames::done; | 131 return IndexedDBNames::done; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void IDBRequest::abort() | 134 void IDBRequest::abort() |
| 135 { | 135 { |
| 136 ASSERT(!m_requestAborted); | 136 DCHECK(!m_requestAborted); |
| 137 if (m_contextStopped || !getExecutionContext()) | 137 if (m_contextStopped || !getExecutionContext()) |
| 138 return; | 138 return; |
| 139 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 139 DCHECK(m_readyState == PENDING || m_readyState == DONE); |
| 140 if (m_readyState == DONE) | 140 if (m_readyState == DONE) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 143 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
| 144 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 144 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
| 145 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); | 145 bool removed = eventQueue->cancelEvent(m_enqueuedEvents[i].get()); |
| 146 ASSERT_UNUSED(removed, removed); | 146 ASSERT_UNUSED(removed, removed); |
| 147 } | 147 } |
| 148 m_enqueuedEvents.clear(); | 148 m_enqueuedEvents.clear(); |
| 149 | 149 |
| 150 m_error.clear(); | 150 m_error.clear(); |
| 151 m_result.clear(); | 151 m_result.clear(); |
| 152 onError(DOMException::create(AbortError, "The transaction was aborted, so th
e request cannot be fulfilled.")); | 152 onError(DOMException::create(AbortError, "The transaction was aborted, so th
e request cannot be fulfilled.")); |
| 153 m_requestAborted = true; | 153 m_requestAborted = true; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void IDBRequest::setCursorDetails(IndexedDB::CursorType cursorType, WebIDBCursor
Direction direction) | 156 void IDBRequest::setCursorDetails(IndexedDB::CursorType cursorType, WebIDBCursor
Direction direction) |
| 157 { | 157 { |
| 158 ASSERT(m_readyState == PENDING); | 158 DCHECK_EQ(m_readyState, PENDING); |
| 159 ASSERT(!m_pendingCursor); | 159 DCHECK(!m_pendingCursor); |
| 160 m_cursorType = cursorType; | 160 m_cursorType = cursorType; |
| 161 m_cursorDirection = direction; | 161 m_cursorDirection = direction; |
| 162 } | 162 } |
| 163 | 163 |
| 164 void IDBRequest::setPendingCursor(IDBCursor* cursor) | 164 void IDBRequest::setPendingCursor(IDBCursor* cursor) |
| 165 { | 165 { |
| 166 ASSERT(m_readyState == DONE); | 166 DCHECK_EQ(m_readyState, DONE); |
| 167 ASSERT(getExecutionContext()); | 167 DCHECK(getExecutionContext()); |
| 168 ASSERT(m_transaction); | 168 DCHECK(m_transaction); |
| 169 ASSERT(!m_pendingCursor); | 169 DCHECK(!m_pendingCursor); |
| 170 ASSERT(cursor == getResultCursor()); | 170 DCHECK_EQ(cursor, getResultCursor()); |
| 171 | 171 |
| 172 m_hasPendingActivity = true; | 172 m_hasPendingActivity = true; |
| 173 m_pendingCursor = cursor; | 173 m_pendingCursor = cursor; |
| 174 setResult(nullptr); | 174 setResult(nullptr); |
| 175 m_readyState = PENDING; | 175 m_readyState = PENDING; |
| 176 m_error.clear(); | 176 m_error.clear(); |
| 177 m_transaction->registerRequest(this); | 177 m_transaction->registerRequest(this); |
| 178 } | 178 } |
| 179 | 179 |
| 180 IDBCursor* IDBRequest::getResultCursor() const | 180 IDBCursor* IDBRequest::getResultCursor() const |
| 181 { | 181 { |
| 182 if (!m_result) | 182 if (!m_result) |
| 183 return nullptr; | 183 return nullptr; |
| 184 if (m_result->getType() == IDBAny::IDBCursorType) | 184 if (m_result->getType() == IDBAny::IDBCursorType) |
| 185 return m_result->idbCursor(); | 185 return m_result->idbCursor(); |
| 186 if (m_result->getType() == IDBAny::IDBCursorWithValueType) | 186 if (m_result->getType() == IDBAny::IDBCursorWithValueType) |
| 187 return m_result->idbCursorWithValue(); | 187 return m_result->idbCursorWithValue(); |
| 188 return nullptr; | 188 return nullptr; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void IDBRequest::setResultCursor(IDBCursor* cursor, IDBKey* key, IDBKey* primary
Key, PassRefPtr<IDBValue> value) | 191 void IDBRequest::setResultCursor(IDBCursor* cursor, IDBKey* key, IDBKey* primary
Key, PassRefPtr<IDBValue> value) |
| 192 { | 192 { |
| 193 ASSERT(m_readyState == PENDING); | 193 DCHECK_EQ(m_readyState, PENDING); |
| 194 m_cursorKey = key; | 194 m_cursorKey = key; |
| 195 m_cursorPrimaryKey = primaryKey; | 195 m_cursorPrimaryKey = primaryKey; |
| 196 m_cursorValue = value; | 196 m_cursorValue = value; |
| 197 ackReceivedBlobs(m_cursorValue.get()); | 197 ackReceivedBlobs(m_cursorValue.get()); |
| 198 | 198 |
| 199 onSuccessInternal(IDBAny::create(cursor)); | 199 onSuccessInternal(IDBAny::create(cursor)); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void IDBRequest::ackReceivedBlobs(const IDBValue* value) | 202 void IDBRequest::ackReceivedBlobs(const IDBValue* value) |
| 203 { | 203 { |
| 204 if (!m_transaction || !m_transaction->backendDB()) | 204 if (!m_transaction || !m_transaction->backendDB()) |
| 205 return; | 205 return; |
| 206 Vector<String> uuids = value->getUUIDs(); | 206 Vector<String> uuids = value->getUUIDs(); |
| 207 if (!uuids.isEmpty()) | 207 if (!uuids.isEmpty()) |
| 208 m_transaction->backendDB()->ackReceivedBlobs(uuids); | 208 m_transaction->backendDB()->ackReceivedBlobs(uuids); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void IDBRequest::ackReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) | 211 void IDBRequest::ackReceivedBlobs(const Vector<RefPtr<IDBValue>>& values) |
| 212 { | 212 { |
| 213 for (size_t i = 0; i < values.size(); ++i) | 213 for (size_t i = 0; i < values.size(); ++i) |
| 214 ackReceivedBlobs(values[i].get()); | 214 ackReceivedBlobs(values[i].get()); |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool IDBRequest::shouldEnqueueEvent() const | 217 bool IDBRequest::shouldEnqueueEvent() const |
| 218 { | 218 { |
| 219 if (m_contextStopped || !getExecutionContext()) | 219 if (m_contextStopped || !getExecutionContext()) |
| 220 return false; | 220 return false; |
| 221 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 221 DCHECK(m_readyState == PENDING || m_readyState == DONE); |
| 222 if (m_requestAborted) | 222 if (m_requestAborted) |
| 223 return false; | 223 return false; |
| 224 ASSERT(m_readyState == PENDING); | 224 DCHECK_EQ(m_readyState, PENDING); |
| 225 ASSERT(!m_error && !m_result); | 225 DCHECK(!m_error && !m_result); |
| 226 return true; | 226 return true; |
| 227 } | 227 } |
| 228 | 228 |
| 229 void IDBRequest::onError(DOMException* error) | 229 void IDBRequest::onError(DOMException* error) |
| 230 { | 230 { |
| 231 IDB_TRACE("IDBRequest::onError()"); | 231 IDB_TRACE("IDBRequest::onError()"); |
| 232 if (!shouldEnqueueEvent()) | 232 if (!shouldEnqueueEvent()) |
| 233 return; | 233 return; |
| 234 | 234 |
| 235 m_error = error; | 235 m_error = error; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 249 domStringList->append(stringList[i]); | 249 domStringList->append(stringList[i]); |
| 250 onSuccessInternal(IDBAny::create(domStringList)); | 250 onSuccessInternal(IDBAny::create(domStringList)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void IDBRequest::onSuccess(std::unique_ptr<WebIDBCursor> backend, IDBKey* key, I
DBKey* primaryKey, PassRefPtr<IDBValue> value) | 253 void IDBRequest::onSuccess(std::unique_ptr<WebIDBCursor> backend, IDBKey* key, I
DBKey* primaryKey, PassRefPtr<IDBValue> value) |
| 254 { | 254 { |
| 255 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); | 255 IDB_TRACE("IDBRequest::onSuccess(IDBCursor)"); |
| 256 if (!shouldEnqueueEvent()) | 256 if (!shouldEnqueueEvent()) |
| 257 return; | 257 return; |
| 258 | 258 |
| 259 ASSERT(!m_pendingCursor); | 259 DCHECK(!m_pendingCursor); |
| 260 IDBCursor* cursor = nullptr; | 260 IDBCursor* cursor = nullptr; |
| 261 switch (m_cursorType) { | 261 switch (m_cursorType) { |
| 262 case IndexedDB::CursorKeyOnly: | 262 case IndexedDB::CursorKeyOnly: |
| 263 cursor = IDBCursor::create(std::move(backend), m_cursorDirection, this,
m_source.get(), m_transaction.get()); | 263 cursor = IDBCursor::create(std::move(backend), m_cursorDirection, this,
m_source.get(), m_transaction.get()); |
| 264 break; | 264 break; |
| 265 case IndexedDB::CursorKeyAndValue: | 265 case IndexedDB::CursorKeyAndValue: |
| 266 cursor = IDBCursorWithValue::create(std::move(backend), m_cursorDirectio
n, this, m_source.get(), m_transaction.get()); | 266 cursor = IDBCursorWithValue::create(std::move(backend), m_cursorDirectio
n, this, m_source.get(), m_transaction.get()); |
| 267 break; | 267 break; |
| 268 default: | 268 default: |
| 269 ASSERT_NOT_REACHED(); | 269 NOTREACHED(); |
| 270 } | 270 } |
| 271 setResultCursor(cursor, key, primaryKey, std::move(value)); | 271 setResultCursor(cursor, key, primaryKey, std::move(value)); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void IDBRequest::onSuccess(IDBKey* idbKey) | 274 void IDBRequest::onSuccess(IDBKey* idbKey) |
| 275 { | 275 { |
| 276 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); | 276 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); |
| 277 if (!shouldEnqueueEvent()) | 277 if (!shouldEnqueueEvent()) |
| 278 return; | 278 return; |
| 279 | 279 |
| 280 if (idbKey && idbKey->isValid()) | 280 if (idbKey && idbKey->isValid()) |
| 281 onSuccessInternal(IDBAny::create(idbKey)); | 281 onSuccessInternal(IDBAny::create(idbKey)); |
| 282 else | 282 else |
| 283 onSuccessInternal(IDBAny::createUndefined()); | 283 onSuccessInternal(IDBAny::createUndefined()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void IDBRequest::onSuccess(const Vector<RefPtr<IDBValue>>& values) | 286 void IDBRequest::onSuccess(const Vector<RefPtr<IDBValue>>& values) |
| 287 { | 287 { |
| 288 IDB_TRACE("IDBRequest::onSuccess([IDBValue])"); | 288 IDB_TRACE("IDBRequest::onSuccess([IDBValue])"); |
| 289 if (!shouldEnqueueEvent()) | 289 if (!shouldEnqueueEvent()) |
| 290 return; | 290 return; |
| 291 | 291 |
| 292 ackReceivedBlobs(values); | 292 ackReceivedBlobs(values); |
| 293 onSuccessInternal(IDBAny::create(values)); | 293 onSuccessInternal(IDBAny::create(values)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 #if ENABLE(ASSERT) | 296 #if DCHECK_IS_ON() |
| 297 static IDBObjectStore* effectiveObjectStore(IDBAny* source) | 297 static IDBObjectStore* effectiveObjectStore(IDBAny* source) |
| 298 { | 298 { |
| 299 if (source->getType() == IDBAny::IDBObjectStoreType) | 299 if (source->getType() == IDBAny::IDBObjectStoreType) |
| 300 return source->idbObjectStore(); | 300 return source->idbObjectStore(); |
| 301 if (source->getType() == IDBAny::IDBIndexType) | 301 if (source->getType() == IDBAny::IDBIndexType) |
| 302 return source->idbIndex()->objectStore(); | 302 return source->idbIndex()->objectStore(); |
| 303 | 303 |
| 304 ASSERT_NOT_REACHED(); | 304 NOTREACHED(); |
| 305 return nullptr; | 305 return nullptr; |
| 306 } | 306 } |
| 307 #endif | 307 #endif // DCHECK_IS_ON() |
| 308 | 308 |
| 309 void IDBRequest::onSuccess(PassRefPtr<IDBValue> prpValue) | 309 void IDBRequest::onSuccess(PassRefPtr<IDBValue> prpValue) |
| 310 { | 310 { |
| 311 IDB_TRACE("IDBRequest::onSuccess(IDBValue)"); | 311 IDB_TRACE("IDBRequest::onSuccess(IDBValue)"); |
| 312 if (!shouldEnqueueEvent()) | 312 if (!shouldEnqueueEvent()) |
| 313 return; | 313 return; |
| 314 | 314 |
| 315 RefPtr<IDBValue> value(prpValue); | 315 RefPtr<IDBValue> value(prpValue); |
| 316 ackReceivedBlobs(value.get()); | 316 ackReceivedBlobs(value.get()); |
| 317 | 317 |
| 318 if (m_pendingCursor) { | 318 if (m_pendingCursor) { |
| 319 // Value should be null, signifying the end of the cursor's range. | 319 // Value should be null, signifying the end of the cursor's range. |
| 320 ASSERT(value->isNull()); | 320 DCHECK(value->isNull()); |
| 321 ASSERT(!value->blobInfo()->size()); | 321 DCHECK(!value->blobInfo()->size()); |
| 322 m_pendingCursor->close(); | 322 m_pendingCursor->close(); |
| 323 m_pendingCursor.clear(); | 323 m_pendingCursor.clear(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 #if ENABLE(ASSERT) | 326 #if DCHECK_IS_ON() |
| 327 if (value->primaryKey()) { | 327 if (value->primaryKey()) { |
| 328 ASSERT(value->keyPath() == effectiveObjectStore(m_source)->metadata().ke
yPath); | 328 DCHECK(value->keyPath() == effectiveObjectStore(m_source)->idbKeyPath())
; |
| 329 assertPrimaryKeyValidOrInjectable(m_scriptState.get(), value.get()); | 329 assertPrimaryKeyValidOrInjectable(m_scriptState.get(), value.get()); |
| 330 } | 330 } |
| 331 #endif | 331 #endif // DCHECK_IS_ON() |
| 332 | 332 |
| 333 onSuccessInternal(IDBAny::create(value.release())); | 333 onSuccessInternal(IDBAny::create(value.release())); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void IDBRequest::onSuccess(int64_t value) | 336 void IDBRequest::onSuccess(int64_t value) |
| 337 { | 337 { |
| 338 IDB_TRACE("IDBRequest::onSuccess(int64_t)"); | 338 IDB_TRACE("IDBRequest::onSuccess(int64_t)"); |
| 339 if (!shouldEnqueueEvent()) | 339 if (!shouldEnqueueEvent()) |
| 340 return; | 340 return; |
| 341 onSuccessInternal(IDBAny::create(value)); | 341 onSuccessInternal(IDBAny::create(value)); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void IDBRequest::onSuccess() | 344 void IDBRequest::onSuccess() |
| 345 { | 345 { |
| 346 IDB_TRACE("IDBRequest::onSuccess()"); | 346 IDB_TRACE("IDBRequest::onSuccess()"); |
| 347 if (!shouldEnqueueEvent()) | 347 if (!shouldEnqueueEvent()) |
| 348 return; | 348 return; |
| 349 onSuccessInternal(IDBAny::createUndefined()); | 349 onSuccessInternal(IDBAny::createUndefined()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void IDBRequest::onSuccessInternal(IDBAny* result) | 352 void IDBRequest::onSuccessInternal(IDBAny* result) |
| 353 { | 353 { |
| 354 ASSERT(!m_contextStopped); | 354 DCHECK(!m_contextStopped); |
| 355 ASSERT(!m_pendingCursor); | 355 DCHECK(!m_pendingCursor); |
| 356 setResult(result); | 356 setResult(result); |
| 357 enqueueEvent(Event::create(EventTypeNames::success)); | 357 enqueueEvent(Event::create(EventTypeNames::success)); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void IDBRequest::setResult(IDBAny* result) | 360 void IDBRequest::setResult(IDBAny* result) |
| 361 { | 361 { |
| 362 m_result = result; | 362 m_result = result; |
| 363 m_resultDirty = true; | 363 m_resultDirty = true; |
| 364 } | 364 } |
| 365 | 365 |
| 366 void IDBRequest::onSuccess(IDBKey* key, IDBKey* primaryKey, PassRefPtr<IDBValue>
value) | 366 void IDBRequest::onSuccess(IDBKey* key, IDBKey* primaryKey, PassRefPtr<IDBValue>
value) |
| 367 { | 367 { |
| 368 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); | 368 IDB_TRACE("IDBRequest::onSuccess(key, primaryKey, value)"); |
| 369 if (!shouldEnqueueEvent()) | 369 if (!shouldEnqueueEvent()) |
| 370 return; | 370 return; |
| 371 | 371 |
| 372 ASSERT(m_pendingCursor); | 372 DCHECK(m_pendingCursor); |
| 373 setResultCursor(m_pendingCursor.release(), key, primaryKey, std::move(value)
); | 373 setResultCursor(m_pendingCursor.release(), key, primaryKey, std::move(value)
); |
| 374 } | 374 } |
| 375 | 375 |
| 376 bool IDBRequest::hasPendingActivity() const | 376 bool IDBRequest::hasPendingActivity() const |
| 377 { | 377 { |
| 378 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can | 378 // FIXME: In an ideal world, we should return true as long as anyone has a o
r can |
| 379 // get a handle to us and we have event listeners. This is order to h
andle | 379 // get a handle to us and we have event listeners. This is order to h
andle |
| 380 // user generated events properly. | 380 // user generated events properly. |
| 381 return m_hasPendingActivity && !m_contextStopped; | 381 return m_hasPendingActivity && !m_contextStopped; |
| 382 } | 382 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 413 ExecutionContext* IDBRequest::getExecutionContext() const | 413 ExecutionContext* IDBRequest::getExecutionContext() const |
| 414 { | 414 { |
| 415 return ActiveDOMObject::getExecutionContext(); | 415 return ActiveDOMObject::getExecutionContext(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 DispatchEventResult IDBRequest::dispatchEventInternal(Event* event) | 418 DispatchEventResult IDBRequest::dispatchEventInternal(Event* event) |
| 419 { | 419 { |
| 420 IDB_TRACE("IDBRequest::dispatchEvent"); | 420 IDB_TRACE("IDBRequest::dispatchEvent"); |
| 421 if (m_contextStopped || !getExecutionContext()) | 421 if (m_contextStopped || !getExecutionContext()) |
| 422 return DispatchEventResult::CanceledBeforeDispatch; | 422 return DispatchEventResult::CanceledBeforeDispatch; |
| 423 ASSERT(m_readyState == PENDING); | 423 DCHECK_EQ(m_readyState, PENDING); |
| 424 ASSERT(m_hasPendingActivity); | 424 DCHECK(m_hasPendingActivity); |
| 425 ASSERT(m_enqueuedEvents.size()); | 425 DCHECK(m_enqueuedEvents.size()); |
| 426 ASSERT(event->target() == this); | 426 DCHECK_EQ(event->target(), this); |
| 427 | 427 |
| 428 ScriptState::Scope scope(m_scriptState.get()); | 428 ScriptState::Scope scope(m_scriptState.get()); |
| 429 | 429 |
| 430 if (event->type() != EventTypeNames::blocked) | 430 if (event->type() != EventTypeNames::blocked) |
| 431 m_readyState = DONE; | 431 m_readyState = DONE; |
| 432 dequeueEvent(event); | 432 dequeueEvent(event); |
| 433 | 433 |
| 434 HeapVector<Member<EventTarget>> targets; | 434 HeapVector<Member<EventTarget>> targets; |
| 435 targets.append(this); | 435 targets.append(this); |
| 436 if (m_transaction && !m_preventPropagation) { | 436 if (m_transaction && !m_preventPropagation) { |
| 437 targets.append(m_transaction); | 437 targets.append(m_transaction); |
| 438 // If there ever are events that are associated with a database but | 438 // If there ever are events that are associated with a database but |
| 439 // that do not have a transaction, then this will not work and we need | 439 // that do not have a transaction, then this will not work and we need |
| 440 // this object to actually hold a reference to the database (to ensure | 440 // this object to actually hold a reference to the database (to ensure |
| 441 // it stays alive). | 441 // it stays alive). |
| 442 targets.append(m_transaction->db()); | 442 targets.append(m_transaction->db()); |
| 443 } | 443 } |
| 444 | 444 |
| 445 // Cursor properties should not be updated until the success event is being
dispatched. | 445 // Cursor properties should not be updated until the success event is being
dispatched. |
| 446 IDBCursor* cursorToNotify = nullptr; | 446 IDBCursor* cursorToNotify = nullptr; |
| 447 if (event->type() == EventTypeNames::success) { | 447 if (event->type() == EventTypeNames::success) { |
| 448 cursorToNotify = getResultCursor(); | 448 cursorToNotify = getResultCursor(); |
| 449 if (cursorToNotify) | 449 if (cursorToNotify) |
| 450 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary
Key.release(), m_cursorValue.release()); | 450 cursorToNotify->setValueReady(m_cursorKey.release(), m_cursorPrimary
Key.release(), m_cursorValue.release()); |
| 451 } | 451 } |
| 452 | 452 |
| 453 if (event->type() == EventTypeNames::upgradeneeded) { | 453 if (event->type() == EventTypeNames::upgradeneeded) { |
| 454 ASSERT(!m_didFireUpgradeNeededEvent); | 454 DCHECK(!m_didFireUpgradeNeededEvent); |
| 455 m_didFireUpgradeNeededEvent = true; | 455 m_didFireUpgradeNeededEvent = true; |
| 456 } | 456 } |
| 457 | 457 |
| 458 // FIXME: When we allow custom event dispatching, this will probably need to
change. | 458 // FIXME: When we allow custom event dispatching, this will probably need to
change. |
| 459 DCHECK(event->type() == EventTypeNames::success || event->type() == EventTyp
eNames::error || event->type() == EventTypeNames::blocked || event->type() == Ev
entTypeNames::upgradeneeded) << "event type was " << event->type(); | 459 DCHECK(event->type() == EventTypeNames::success || event->type() == EventTyp
eNames::error || event->type() == EventTypeNames::blocked || event->type() == Ev
entTypeNames::upgradeneeded) << "event type was " << event->type(); |
| 460 const bool setTransactionActive = m_transaction && (event->type() == EventTy
peNames::success || event->type() == EventTypeNames::upgradeneeded || (event->ty
pe() == EventTypeNames::error && !m_requestAborted)); | 460 const bool setTransactionActive = m_transaction && (event->type() == EventTy
peNames::success || event->type() == EventTypeNames::upgradeneeded || (event->ty
pe() == EventTypeNames::error && !m_requestAborted)); |
| 461 | 461 |
| 462 if (setTransactionActive) | 462 if (setTransactionActive) |
| 463 m_transaction->setActive(true); | 463 m_transaction->setActive(true); |
| 464 | 464 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 494 void IDBRequest::uncaughtExceptionInEventHandler() | 494 void IDBRequest::uncaughtExceptionInEventHandler() |
| 495 { | 495 { |
| 496 if (m_transaction && !m_requestAborted) { | 496 if (m_transaction && !m_requestAborted) { |
| 497 m_transaction->setError(DOMException::create(AbortError, "Uncaught excep
tion in event handler.")); | 497 m_transaction->setError(DOMException::create(AbortError, "Uncaught excep
tion in event handler.")); |
| 498 m_transaction->abort(IGNORE_EXCEPTION); | 498 m_transaction->abort(IGNORE_EXCEPTION); |
| 499 } | 499 } |
| 500 } | 500 } |
| 501 | 501 |
| 502 void IDBRequest::transactionDidFinishAndDispatch() | 502 void IDBRequest::transactionDidFinishAndDispatch() |
| 503 { | 503 { |
| 504 ASSERT(m_transaction); | 504 DCHECK(m_transaction); |
| 505 ASSERT(m_transaction->isVersionChange()); | 505 DCHECK(m_transaction->isVersionChange()); |
| 506 ASSERT(m_didFireUpgradeNeededEvent); | 506 DCHECK(m_didFireUpgradeNeededEvent); |
| 507 ASSERT(m_readyState == DONE); | 507 DCHECK_EQ(m_readyState, DONE); |
| 508 ASSERT(getExecutionContext()); | 508 DCHECK(getExecutionContext()); |
| 509 m_transaction.clear(); | 509 m_transaction.clear(); |
| 510 | 510 |
| 511 if (m_contextStopped) | 511 if (m_contextStopped) |
| 512 return; | 512 return; |
| 513 | 513 |
| 514 m_readyState = PENDING; | 514 m_readyState = PENDING; |
| 515 } | 515 } |
| 516 | 516 |
| 517 void IDBRequest::enqueueEvent(Event* event) | 517 void IDBRequest::enqueueEvent(Event* event) |
| 518 { | 518 { |
| 519 ASSERT(m_readyState == PENDING || m_readyState == DONE); | 519 DCHECK(m_readyState == PENDING || m_readyState == DONE); |
| 520 | 520 |
| 521 if (m_contextStopped || !getExecutionContext()) | 521 if (m_contextStopped || !getExecutionContext()) |
| 522 return; | 522 return; |
| 523 | 523 |
| 524 DCHECK(m_readyState == PENDING || m_didFireUpgradeNeededEvent) << "When queu
eing event " << event->type() << ", m_readyState was " << m_readyState; | 524 DCHECK(m_readyState == PENDING || m_didFireUpgradeNeededEvent) << "When queu
eing event " << event->type() << ", m_readyState was " << m_readyState; |
| 525 | 525 |
| 526 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); | 526 EventQueue* eventQueue = getExecutionContext()->getEventQueue(); |
| 527 event->setTarget(this); | 527 event->setTarget(this); |
| 528 | 528 |
| 529 // Keep track of enqueued events in case we need to abort prior to dispatch, | 529 // Keep track of enqueued events in case we need to abort prior to dispatch, |
| 530 // in which case these must be cancelled. If the events not dispatched for | 530 // in which case these must be cancelled. If the events not dispatched for |
| 531 // other reasons they must be removed from this list via dequeueEvent(). | 531 // other reasons they must be removed from this list via dequeueEvent(). |
| 532 if (eventQueue->enqueueEvent(event)) | 532 if (eventQueue->enqueueEvent(event)) |
| 533 m_enqueuedEvents.append(event); | 533 m_enqueuedEvents.append(event); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void IDBRequest::dequeueEvent(Event* event) | 536 void IDBRequest::dequeueEvent(Event* event) |
| 537 { | 537 { |
| 538 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 538 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
| 539 if (m_enqueuedEvents[i].get() == event) | 539 if (m_enqueuedEvents[i].get() == event) |
| 540 m_enqueuedEvents.remove(i); | 540 m_enqueuedEvents.remove(i); |
| 541 } | 541 } |
| 542 } | 542 } |
| 543 | 543 |
| 544 } // namespace blink | 544 } // namespace blink |
| OLD | NEW |