Title: [136894] trunk
Revision
136894
Author
dgro...@chromium.org
Date
2012-12-06 14:33:57 -0800 (Thu, 06 Dec 2012)

Log Message

IndexedDB: Add webkitErrorMessage to IDBTransaction
https://bugs.webkit.org/show_bug.cgi?id=104199

Reviewed by Tony Chang.

Source/WebCore:

Don't drop error messages on the floor.

Expose an error message on IDBTransaction to give developers more
information than the opaque error code currently available. This is
exactly what is done in IDBRequest.

Tests - transaction-error.html

* Modules/indexeddb/IDBDatabaseError.h:
(WebCore::IDBDatabaseError::create):
* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::dispatchEvent):
(WebCore::IDBRequest::uncaughtExceptionInEventHandler):
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::setError):
(WebCore):
(WebCore::IDBTransaction::webkitErrorMessage):
(WebCore::IDBTransaction::onAbort):
* Modules/indexeddb/IDBTransaction.h:
(IDBTransaction):
* Modules/indexeddb/IDBTransaction.idl:

LayoutTests:

Test for webkitErrorMessage in the three circumstances that can
generate one:
1) Bubble from operation error
2) Uncaught exception in operation event handler
3) Asynchronous abort from the backend

And fix a FIXME in the test.

* storage/indexeddb/resources/transaction-error.js:
(testErrorFromRequest.trans.onabort):
(testErrorFromRequest):
(testErrorFromException.trans.onabort):
(testErrorFromException):
(testErrorFromCommit.trans.oncomplete.request.onupgradeneeded.trans.onabort):
(testErrorFromCommit.trans.oncomplete.request.onupgradeneeded):
(testErrorFromCommit.trans.oncomplete):
(testErrorFromCommit):
* storage/indexeddb/transaction-error-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136893 => 136894)


--- trunk/LayoutTests/ChangeLog	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/LayoutTests/ChangeLog	2012-12-06 22:33:57 UTC (rev 136894)
@@ -1,3 +1,29 @@
+2012-12-06  David Grogan  <dgro...@chromium.org>
+
+        IndexedDB: Add webkitErrorMessage to IDBTransaction
+        https://bugs.webkit.org/show_bug.cgi?id=104199
+
+        Reviewed by Tony Chang.
+
+        Test for webkitErrorMessage in the three circumstances that can
+        generate one:
+        1) Bubble from operation error
+        2) Uncaught exception in operation event handler
+        3) Asynchronous abort from the backend
+
+        And fix a FIXME in the test.
+
+        * storage/indexeddb/resources/transaction-error.js:
+        (testErrorFromRequest.trans.onabort):
+        (testErrorFromRequest):
+        (testErrorFromException.trans.onabort):
+        (testErrorFromException):
+        (testErrorFromCommit.trans.oncomplete.request.onupgradeneeded.trans.onabort):
+        (testErrorFromCommit.trans.oncomplete.request.onupgradeneeded):
+        (testErrorFromCommit.trans.oncomplete):
+        (testErrorFromCommit):
+        * storage/indexeddb/transaction-error-expected.txt:
+
 2012-12-06  Alexander Shalamov  <alexander.shala...@intel.com>
 
         XMLHttpRequest Content-Type should be taken from Blob type

Modified: trunk/LayoutTests/storage/indexeddb/resources/transaction-error.js (136893 => 136894)


--- trunk/LayoutTests/storage/indexeddb/resources/transaction-error.js	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/LayoutTests/storage/indexeddb/resources/transaction-error.js	2012-12-06 22:33:57 UTC (rev 136894)
@@ -48,6 +48,8 @@
     trans._onabort_ = function() {
         debug("Transaction received abort event.");
         shouldBeNonNull("trans.error");
+        debug("trans.webkitErrorMessage = " + trans.webkitErrorMessage);
+        shouldBeNonNull("trans.webkitErrorMessage");
         shouldBe("trans.error", "request_error");
         testErrorFromException();
     };
@@ -78,6 +80,8 @@
         self._onerror_ = self.originalWindowOnError;
 
         shouldBeNonNull("trans.error");
+        debug("trans.webkitErrorMessage = " + trans.webkitErrorMessage);
+        shouldBeNonNull("trans.webkitErrorMessage");
         shouldBe("trans.error.name", "'AbortError'");
         testErrorFromCommit();
     };
@@ -106,8 +110,9 @@
             trans._onabort_ = function() {
                 debug("Transaction received abort event.");
                 shouldBeNonNull("trans.error");
-                // FIXME: Test for a specific error here, when supported.
-                shouldNotBe("trans.error.name", "'AbortError'");
+                shouldBe("trans.error.name", "'ConstraintError'");
+                debug("trans.webkitErrorMessage = " + trans.webkitErrorMessage);
+                shouldBeNonNull("trans.webkitErrorMessage");
                 debug("");
                 finishJSTest();
             };

Modified: trunk/LayoutTests/storage/indexeddb/transaction-error-expected.txt (136893 => 136894)


--- trunk/LayoutTests/storage/indexeddb/transaction-error-expected.txt	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/LayoutTests/storage/indexeddb/transaction-error-expected.txt	2012-12-06 22:33:57 UTC (rev 136894)
@@ -1,4 +1,4 @@
-CONSOLE MESSAGE: line 71: Uncaught Error: This should *NOT* be caught!
+CONSOLE MESSAGE: line 73: Uncaught Error: This should *NOT* be caught!
 Test IDBTransaction.error cases.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
@@ -28,6 +28,8 @@
 request_error = request.error
 Transaction received abort event.
 PASS trans.error is non-null.
+trans.webkitErrorMessage = Key already exists in the object store.
+PASS trans.webkitErrorMessage is non-null.
 PASS trans.error is request_error
 
 If the transaction is aborted due to an exception thrown from event callback, IDBTransaction.error should be AbortError:
@@ -37,6 +39,8 @@
 Throwing exception...
 Transaction received abort event.
 PASS trans.error is non-null.
+trans.webkitErrorMessage = Uncaught exception in event handler.
+PASS trans.webkitErrorMessage is non-null.
 PASS trans.error.name is 'AbortError'
 
 If the transaction is aborted due to an error during commit, IDBTransaction.error should reflect that error:
@@ -49,7 +53,9 @@
 trans.objectStore('storeName').createIndex('indexName', 'id', {unique: true})
 Transaction received abort event.
 PASS trans.error is non-null.
-PASS trans.error.name is not 'AbortError'
+PASS trans.error.name is 'ConstraintError'
+trans.webkitErrorMessage = Duplicate index keys exist in the object store.
+PASS trans.webkitErrorMessage is non-null.
 
 PASS successfullyParsed is true
 

Modified: trunk/Source/WebCore/ChangeLog (136893 => 136894)


--- trunk/Source/WebCore/ChangeLog	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/ChangeLog	2012-12-06 22:33:57 UTC (rev 136894)
@@ -1,3 +1,32 @@
+2012-12-06  David Grogan  <dgro...@chromium.org>
+
+        IndexedDB: Add webkitErrorMessage to IDBTransaction
+        https://bugs.webkit.org/show_bug.cgi?id=104199
+
+        Reviewed by Tony Chang.
+
+        Don't drop error messages on the floor.
+
+        Expose an error message on IDBTransaction to give developers more
+        information than the opaque error code currently available. This is
+        exactly what is done in IDBRequest. 
+
+        Tests - transaction-error.html
+
+        * Modules/indexeddb/IDBDatabaseError.h:
+        (WebCore::IDBDatabaseError::create):
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::dispatchEvent):
+        (WebCore::IDBRequest::uncaughtExceptionInEventHandler):
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::setError):
+        (WebCore):
+        (WebCore::IDBTransaction::webkitErrorMessage):
+        (WebCore::IDBTransaction::onAbort):
+        * Modules/indexeddb/IDBTransaction.h:
+        (IDBTransaction):
+        * Modules/indexeddb/IDBTransaction.idl:
+
 2012-12-06  Alexander Shalamov  <alexander.shala...@intel.com>
 
         XMLHttpRequest Content-Type should be taken from Blob type

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseError.h (136893 => 136894)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseError.h	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseError.h	2012-12-06 22:33:57 UTC (rev 136894)
@@ -46,7 +46,7 @@
 
     static PassRefPtr<IDBDatabaseError> create(unsigned short code, const String& message)
     {
-        ASSERT(code >= IDBDatabaseException::IDBDatabaseExceptionOffset);
+        ASSERT_WITH_MESSAGE(code >= IDBDatabaseException::IDBDatabaseExceptionOffset, "%d >= %d", code, IDBDatabaseException::IDBDatabaseExceptionOffset);
         ASSERT(code < IDBDatabaseException::IDBDatabaseExceptionMax);
         return adoptRef(new IDBDatabaseError(code, message));
     }

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp (136893 => 136894)


--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2012-12-06 22:33:57 UTC (rev 136894)
@@ -484,7 +484,7 @@
         // Possibly abort the transaction. This must occur after unregistering (so this request
         // doesn't receive a second error) and before deactivating (which might trigger commit).
         if (event->type() == eventNames().errorEvent && dontPreventDefault && !m_requestAborted) {
-            m_transaction->setError(m_error);
+            m_transaction->setError(m_error, m_errorMessage);
             ExceptionCode unused;
             m_transaction->abort(unused);
         }
@@ -506,7 +506,7 @@
 void IDBRequest::uncaughtExceptionInEventHandler()
 {
     if (m_transaction && !m_requestAborted) {
-        m_transaction->setError(DOMError::create(IDBDatabaseException::getErrorName(IDBDatabaseException::AbortError)));
+        m_transaction->setError(DOMError::create(IDBDatabaseException::getErrorName(IDBDatabaseException::AbortError)), "Uncaught exception in event handler.");
         ExceptionCode unused;
         m_transaction->abort(unused);
     }

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp (136893 => 136894)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp	2012-12-06 22:33:57 UTC (rev 136894)
@@ -135,17 +135,24 @@
     return mode;
 }
 
-void IDBTransaction::setError(PassRefPtr<DOMError> error)
+void IDBTransaction::setError(PassRefPtr<DOMError> error, const String& errorMessage)
 {
     ASSERT(m_state != Finished);
     ASSERT(error);
 
     // The first error to be set is the true cause of the
     // transaction abort.
-    if (!m_error)
+    if (!m_error) {
         m_error = error;
+        m_errorMessage = errorMessage;
+    }
 }
 
+String IDBTransaction::webkitErrorMessage() const
+{
+    return m_errorMessage;
+}
+
 PassRefPtr<IDBObjectStore> IDBTransaction::objectStore(const String& name, ExceptionCode& ec)
 {
     if (m_state == Finished) {
@@ -288,14 +295,15 @@
     m_requestList.remove(request);
 }
 
-void IDBTransaction::onAbort(PassRefPtr<IDBDatabaseError> error)
+void IDBTransaction::onAbort(PassRefPtr<IDBDatabaseError> prpError)
 {
     IDB_TRACE("IDBTransaction::onAbort");
+    RefPtr<IDBDatabaseError> error = prpError;
     ASSERT(m_state != Finished);
 
     if (m_state != Finishing) {
         ASSERT(error.get());
-        setError(DOMError::create(error->name()));
+        setError(DOMError::create(error->name()), error->message());
 
         // Abort was not triggered by front-end, so outstanding requests must
         // be aborted now.

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h (136893 => 136894)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h	2012-12-06 22:33:57 UTC (rev 136894)
@@ -99,7 +99,8 @@
     void objectStoreCreated(const String&, PassRefPtr<IDBObjectStore>);
     void objectStoreDeleted(const String&);
     void setActive(bool);
-    void setError(PassRefPtr<DOMError>);
+    void setError(PassRefPtr<DOMError>, const String& errorMessage);
+    String webkitErrorMessage() const;
 
     DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
     DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
@@ -156,6 +157,7 @@
     bool m_hasPendingActivity;
     bool m_contextStopped;
     RefPtr<DOMError> m_error;
+    String m_errorMessage;
 
     ListHashSet<IDBRequest*> m_requestList;
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.idl (136893 => 136894)


--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.idl	2012-12-06 22:32:46 UTC (rev 136893)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.idl	2012-12-06 22:33:57 UTC (rev 136894)
@@ -35,6 +35,7 @@
     readonly attribute DOMString mode;
     readonly attribute IDBDatabase db;
     readonly attribute DOMError error;
+    [TreatReturnedNullStringAs=Undefined] readonly attribute DOMString webkitErrorMessage;
 
     // Methods
     IDBObjectStore objectStore (in DOMString name)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to