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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 << "event type was " << event->type(); | 465 << "event type was " << event->type(); |
466 const bool setTransactionActive = | 466 const bool setTransactionActive = |
467 m_transaction && | 467 m_transaction && |
468 (event->type() == EventTypeNames::success || | 468 (event->type() == EventTypeNames::success || |
469 event->type() == EventTypeNames::upgradeneeded || | 469 event->type() == EventTypeNames::upgradeneeded || |
470 (event->type() == EventTypeNames::error && !m_requestAborted)); | 470 (event->type() == EventTypeNames::error && !m_requestAborted)); |
471 | 471 |
472 if (setTransactionActive) | 472 if (setTransactionActive) |
473 m_transaction->setActive(true); | 473 m_transaction->setActive(true); |
474 | 474 |
| 475 m_didThrowInEventHandler = false; |
475 DispatchEventResult dispatchResult = | 476 DispatchEventResult dispatchResult = |
476 IDBEventDispatcher::dispatch(event, targets); | 477 IDBEventDispatcher::dispatch(event, targets); |
477 | 478 |
478 if (m_transaction) { | 479 if (m_transaction) { |
479 if (m_readyState == DONE) | 480 if (m_readyState == DONE) |
480 m_transaction->unregisterRequest(this); | 481 m_transaction->unregisterRequest(this); |
481 | 482 |
482 // Possibly abort the transaction. This must occur after unregistering (so | 483 // Possibly abort the transaction. This must occur after unregistering (so |
483 // this request doesn't receive a second error) and before deactivating | 484 // this request doesn't receive a second error) and before deactivating |
484 // (which might trigger commit). | 485 // (which might trigger commit). |
485 if (event->type() == EventTypeNames::error && | 486 if (!m_requestAborted) { |
486 dispatchResult == DispatchEventResult::NotCanceled && | 487 if (m_didThrowInEventHandler) { |
487 !m_requestAborted) { | 488 m_transaction->setError(DOMException::create( |
488 m_transaction->setError(m_error); | 489 AbortError, "Uncaught exception in event handler.")); |
489 m_transaction->abort(IGNORE_EXCEPTION_FOR_TESTING); | 490 m_transaction->abort(IGNORE_EXCEPTION_FOR_TESTING); |
| 491 } else if (event->type() == EventTypeNames::error && |
| 492 dispatchResult == DispatchEventResult::NotCanceled) { |
| 493 m_transaction->setError(m_error); |
| 494 m_transaction->abort(IGNORE_EXCEPTION_FOR_TESTING); |
| 495 } |
490 } | 496 } |
491 | 497 |
492 // If this was the last request in the transaction's list, it may commit | 498 // If this was the last request in the transaction's list, it may commit |
493 // here. | 499 // here. |
494 if (setTransactionActive) | 500 if (setTransactionActive) |
495 m_transaction->setActive(false); | 501 m_transaction->setActive(false); |
496 } | 502 } |
497 | 503 |
498 if (cursorToNotify) | 504 if (cursorToNotify) |
499 cursorToNotify->postSuccessHandlerCallback(); | 505 cursorToNotify->postSuccessHandlerCallback(); |
500 | 506 |
501 // An upgradeneeded event will always be followed by a success or error event, | 507 // An upgradeneeded event will always be followed by a success or error event, |
502 // so must be kept alive. | 508 // so must be kept alive. |
503 if (m_readyState == DONE && event->type() != EventTypeNames::upgradeneeded) | 509 if (m_readyState == DONE && event->type() != EventTypeNames::upgradeneeded) |
504 m_hasPendingActivity = false; | 510 m_hasPendingActivity = false; |
505 | 511 |
506 return dispatchResult; | 512 return dispatchResult; |
507 } | 513 } |
508 | 514 |
509 void IDBRequest::uncaughtExceptionInEventHandler() { | 515 void IDBRequest::uncaughtExceptionInEventHandler() { |
510 if (m_transaction && !m_requestAborted) { | 516 m_didThrowInEventHandler = true; |
511 m_transaction->setError(DOMException::create( | |
512 AbortError, "Uncaught exception in event handler.")); | |
513 m_transaction->abort(IGNORE_EXCEPTION_FOR_TESTING); | |
514 } | |
515 } | 517 } |
516 | 518 |
517 void IDBRequest::transactionDidFinishAndDispatch() { | 519 void IDBRequest::transactionDidFinishAndDispatch() { |
518 DCHECK(m_transaction); | 520 DCHECK(m_transaction); |
519 DCHECK(m_transaction->isVersionChange()); | 521 DCHECK(m_transaction->isVersionChange()); |
520 DCHECK(m_didFireUpgradeNeededEvent); | 522 DCHECK(m_didFireUpgradeNeededEvent); |
521 DCHECK_EQ(m_readyState, DONE); | 523 DCHECK_EQ(m_readyState, DONE); |
522 DCHECK(getExecutionContext()); | 524 DCHECK(getExecutionContext()); |
523 m_transaction.clear(); | 525 m_transaction.clear(); |
524 | 526 |
(...skipping 24 matching lines...) Expand all Loading... |
549 } | 551 } |
550 | 552 |
551 void IDBRequest::dequeueEvent(Event* event) { | 553 void IDBRequest::dequeueEvent(Event* event) { |
552 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { | 554 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { |
553 if (m_enqueuedEvents[i].get() == event) | 555 if (m_enqueuedEvents[i].get() == event) |
554 m_enqueuedEvents.remove(i); | 556 m_enqueuedEvents.remove(i); |
555 } | 557 } |
556 } | 558 } |
557 | 559 |
558 } // namespace blink | 560 } // namespace blink |
OLD | NEW |