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

Side by Side Diff: Source/modules/indexeddb/IDBRequest.cpp

Issue 243523003: Fire window.onerror for uncaught IndexedDB errors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased and linkage fix Created 5 years, 3 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
« no previous file with comments | « Source/modules/indexeddb/IDBRequest.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 13 matching lines...) Expand all
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "config.h" 29 #include "config.h"
30 #include "modules/indexeddb/IDBRequest.h" 30 #include "modules/indexeddb/IDBRequest.h"
31 31
32 #include "bindings/core/v8/ExceptionState.h" 32 #include "bindings/core/v8/ExceptionState.h"
33 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 33 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
34 #include "bindings/core/v8/ScriptCallStackFactory.h"
34 #include "bindings/modules/v8/ToV8ForModules.h" 35 #include "bindings/modules/v8/ToV8ForModules.h"
35 #include "bindings/modules/v8/V8BindingForModules.h" 36 #include "bindings/modules/v8/V8BindingForModules.h"
36 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "core/events/ErrorEvent.h"
37 #include "core/events/EventQueue.h" 39 #include "core/events/EventQueue.h"
40 #include "core/inspector/ScriptCallFrame.h"
41 #include "core/inspector/ScriptCallStack.h"
38 #include "modules/IndexedDBNames.h" 42 #include "modules/IndexedDBNames.h"
39 #include "modules/indexeddb/IDBCursorWithValue.h" 43 #include "modules/indexeddb/IDBCursorWithValue.h"
40 #include "modules/indexeddb/IDBDatabase.h" 44 #include "modules/indexeddb/IDBDatabase.h"
41 #include "modules/indexeddb/IDBEventDispatcher.h" 45 #include "modules/indexeddb/IDBEventDispatcher.h"
42 #include "modules/indexeddb/IDBTracing.h" 46 #include "modules/indexeddb/IDBTracing.h"
43 #include "modules/indexeddb/IDBValue.h" 47 #include "modules/indexeddb/IDBValue.h"
44 #include "platform/SharedBuffer.h" 48 #include "platform/SharedBuffer.h"
45 #include "public/platform/WebBlobInfo.h" 49 #include "public/platform/WebBlobInfo.h"
46 50
47 using blink::WebIDBCursor; 51 using blink::WebIDBCursor;
48 52
49 namespace blink { 53 namespace blink {
50 54
51 IDBRequest* IDBRequest::create(ScriptState* scriptState, IDBAny* source, IDBTran saction* transaction) 55 IDBRequest* IDBRequest::create(ScriptState* scriptState, IDBAny* source, IDBTran saction* transaction)
52 { 56 {
53 IDBRequest* request = new IDBRequest(scriptState, source, transaction); 57 IDBRequest* request = new IDBRequest(scriptState, source, transaction);
54 request->suspendIfNeeded(); 58 request->suspendIfNeeded();
55 // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames ) are not associated with transactions. 59 // Requests associated with IDBFactory (open/deleteDatabase/getDatabaseNames ) are not associated with transactions.
56 if (transaction) 60 if (transaction)
57 transaction->registerRequest(request); 61 transaction->registerRequest(request);
58 return request; 62 return request;
59 } 63 }
60 64
61 IDBRequest::IDBRequest(ScriptState* scriptState, IDBAny* source, IDBTransaction* transaction) 65 IDBRequest::IDBRequest(ScriptState* scriptState, IDBAny* source, IDBTransaction* transaction)
62 : ActiveDOMObject(scriptState->executionContext()) 66 : ActiveDOMObject(scriptState->executionContext())
63 , m_transaction(transaction) 67 , m_transaction(transaction)
64 , m_scriptState(scriptState) 68 , m_scriptState(scriptState)
65 , m_source(source) 69 , m_source(source)
66 { 70 {
71 m_creationStack = createScriptCallStack(ScriptCallStack::maxCallStackSizeToC apture);
72 ASSERT(m_creationStack && m_creationStack->size());
67 } 73 }
68 74
69 IDBRequest::~IDBRequest() 75 IDBRequest::~IDBRequest()
70 { 76 {
71 ASSERT(m_readyState == DONE || m_readyState == EarlyDeath || !executionConte xt()); 77 ASSERT(m_readyState == DONE || m_readyState == EarlyDeath || !executionConte xt());
72 } 78 }
73 79
74 DEFINE_TRACE(IDBRequest) 80 DEFINE_TRACE(IDBRequest)
75 { 81 {
76 visitor->trace(m_transaction); 82 visitor->trace(m_transaction);
77 visitor->trace(m_source); 83 visitor->trace(m_source);
78 visitor->trace(m_result); 84 visitor->trace(m_result);
79 visitor->trace(m_error); 85 visitor->trace(m_error);
80 visitor->trace(m_enqueuedEvents); 86 visitor->trace(m_enqueuedEvents);
81 visitor->trace(m_pendingCursor); 87 visitor->trace(m_pendingCursor);
82 visitor->trace(m_cursorKey); 88 visitor->trace(m_cursorKey);
83 visitor->trace(m_cursorPrimaryKey); 89 visitor->trace(m_cursorPrimaryKey);
90 visitor->trace(m_creationStack);
84 RefCountedGarbageCollectedEventTargetWithInlineData<IDBRequest>::trace(visit or); 91 RefCountedGarbageCollectedEventTargetWithInlineData<IDBRequest>::trace(visit or);
85 ActiveDOMObject::trace(visitor); 92 ActiveDOMObject::trace(visitor);
86 } 93 }
87 94
88 ScriptValue IDBRequest::result(ExceptionState& exceptionState) 95 ScriptValue IDBRequest::result(ExceptionState& exceptionState)
89 { 96 {
90 if (m_readyState != DONE) { 97 if (m_readyState != DONE) {
91 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request NotFinishedErrorMessage); 98 exceptionState.throwDOMException(InvalidStateError, IDBDatabase::request NotFinishedErrorMessage);
92 return ScriptValue(); 99 return ScriptValue();
93 } 100 }
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 m_didFireUpgradeNeededEvent = true; 456 m_didFireUpgradeNeededEvent = true;
450 } 457 }
451 458
452 // FIXME: When we allow custom event dispatching, this will probably need to change. 459 // FIXME: When we allow custom event dispatching, this will probably need to change.
453 ASSERT_WITH_MESSAGE(event->type() == EventTypeNames::success || event->type( ) == EventTypeNames::error || event->type() == EventTypeNames::blocked || event- >type() == EventTypeNames::upgradeneeded, "event type was %s", event->type().utf 8().data()); 460 ASSERT_WITH_MESSAGE(event->type() == EventTypeNames::success || event->type( ) == EventTypeNames::error || event->type() == EventTypeNames::blocked || event- >type() == EventTypeNames::upgradeneeded, "event type was %s", event->type().utf 8().data());
454 const bool setTransactionActive = m_transaction && (event->type() == EventTy peNames::success || event->type() == EventTypeNames::upgradeneeded || (event->ty pe() == EventTypeNames::error && !m_requestAborted)); 461 const bool setTransactionActive = m_transaction && (event->type() == EventTy peNames::success || event->type() == EventTypeNames::upgradeneeded || (event->ty pe() == EventTypeNames::error && !m_requestAborted));
455 462
456 if (setTransactionActive) 463 if (setTransactionActive)
457 m_transaction->setActive(true); 464 m_transaction->setActive(true);
458 465
459 bool dontPreventDefault = IDBEventDispatcher::dispatch(event.get(), targets) ; 466 bool shouldPerformDefault = IDBEventDispatcher::dispatch(event.get(), target s);
460 467
461 if (m_transaction) { 468 if (m_transaction) {
462 if (m_readyState == DONE) 469 if (m_readyState == DONE)
463 m_transaction->unregisterRequest(this); 470 m_transaction->unregisterRequest(this);
464 471
465 // Possibly abort the transaction. This must occur after unregistering ( so this request 472 // Possibly abort the transaction. This must occur after unregistering ( so this request
466 // doesn't receive a second error) and before deactivating (which might trigger commit). 473 // doesn't receive a second error) and before deactivating (which might trigger commit).
467 if (event->type() == EventTypeNames::error && dontPreventDefault && !m_r equestAborted) { 474 if (event->type() == EventTypeNames::error && shouldPerformDefault && !m _requestAborted) {
468 m_transaction->setError(m_error); 475 m_transaction->setError(m_error);
469 m_transaction->abort(IGNORE_EXCEPTION); 476 m_transaction->abort(IGNORE_EXCEPTION);
470 } 477 }
471 478
472 // If this was the last request in the transaction's list, it may commit here. 479 // If this was the last request in the transaction's list, it may commit here.
473 if (setTransactionActive) 480 if (setTransactionActive)
474 m_transaction->setActive(false); 481 m_transaction->setActive(false);
475 } 482 }
476 483
477 if (cursorToNotify) 484 if (cursorToNotify)
478 cursorToNotify->postSuccessHandlerCallback(); 485 cursorToNotify->postSuccessHandlerCallback();
479 486
480 // An upgradeneeded event will always be followed by a success or error even t, so must 487 // An upgradeneeded event will always be followed by a success or error even t, so must
481 // be kept alive. 488 // be kept alive.
482 if (m_readyState == DONE && event->type() != EventTypeNames::upgradeneeded) 489 if (m_readyState == DONE && event->type() != EventTypeNames::upgradeneeded)
483 m_hasPendingActivity = false; 490 m_hasPendingActivity = false;
484 491
485 return dontPreventDefault; 492 // Fire window.onerror (or the equivalent for workers) for errors that were not prevented.
493 if (!m_preventPropagation && shouldPerformDefault && event->type() == EventT ypeNames::error && m_creationStack.get() && m_creationStack->size()) {
494 const ScriptCallFrame& frame = m_creationStack->at(0);
495 const AccessControlStatus corsStatus = NotSharableCrossOrigin;
496 RefPtrWillBeRawPtr<ErrorEvent> errorEvent;
497 if (executionContext()->shouldSanitizeScriptError(frame.sourceURL(), cor sStatus))
498 errorEvent = ErrorEvent::createSanitizedError(&m_scriptState->world( ));
499 else
500 errorEvent = ErrorEvent::create(m_error->toStringForConsole(), frame .sourceURL(), frame.lineNumber(), frame.columnNumber(), &m_scriptState->world()) ;
501 executionContext()->reportException(errorEvent, frame.scriptId().toInt() , m_creationStack, corsStatus);
502 }
503
504 return shouldPerformDefault;
486 } 505 }
487 506
488 void IDBRequest::uncaughtExceptionInEventHandler() 507 void IDBRequest::uncaughtExceptionInEventHandler()
489 { 508 {
490 if (m_transaction && !m_requestAborted) { 509 if (m_transaction && !m_requestAborted) {
491 m_transaction->setError(DOMError::create(AbortError, "Uncaught exception in event handler.")); 510 m_transaction->setError(DOMError::create(AbortError, "Uncaught exception in event handler."));
492 m_transaction->abort(IGNORE_EXCEPTION); 511 m_transaction->abort(IGNORE_EXCEPTION);
493 } 512 }
494 } 513 }
495 514
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 548
530 void IDBRequest::dequeueEvent(Event* event) 549 void IDBRequest::dequeueEvent(Event* event)
531 { 550 {
532 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) { 551 for (size_t i = 0; i < m_enqueuedEvents.size(); ++i) {
533 if (m_enqueuedEvents[i].get() == event) 552 if (m_enqueuedEvents[i].get() == event)
534 m_enqueuedEvents.remove(i); 553 m_enqueuedEvents.remove(i);
535 } 554 }
536 } 555 }
537 556
538 } // namespace blink 557 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/indexeddb/IDBRequest.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698