IDBRequest and IDBTransaction error properties should be DOMExceptions
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 05:20:12 +0000 (05:20 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Sep 2017 05:20:12 +0000 (05:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177201

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

Rebaseline WPT now that it is passing.

* web-platform-tests/IndexedDB/error-attributes-expected.txt:

Source/WebCore:

IDBRequest and IDBTransaction error properties should be DOMExceptions:
- https://w3c.github.io/IndexedDB/#idbrequest
- https://w3c.github.io/IndexedDB/#transaction

Previously, we used a DOMError type, which is obsolete.

No new tests, rebaselined existing test.

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::onError):
(WebCore::IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion):
* Modules/indexeddb/IDBRequest.cpp:
(WebCore:: const):
(WebCore::IDBRequest::uncaughtExceptionInEventHandler):
(WebCore::IDBRequest::onError):
* Modules/indexeddb/IDBRequest.h:
* Modules/indexeddb/IDBRequest.idl:
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::error const):
(WebCore::IDBTransaction::abortDueToFailedRequest):
(WebCore::IDBTransaction::didCreateIndexOnServer):
(WebCore::IDBTransaction::connectionClosedFromServer):
* Modules/indexeddb/IDBTransaction.h:
* Modules/indexeddb/IDBTransaction.idl:
* Modules/indexeddb/shared/IDBError.cpp:
(WebCore::IDBError::toDOMException const):
* Modules/indexeddb/shared/IDBError.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@222250 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/IndexedDB/error-attributes-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.h
Source/WebCore/Modules/indexeddb/IDBRequest.idl
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp
Source/WebCore/Modules/indexeddb/IDBTransaction.h
Source/WebCore/Modules/indexeddb/IDBTransaction.idl
Source/WebCore/Modules/indexeddb/shared/IDBError.cpp
Source/WebCore/Modules/indexeddb/shared/IDBError.h
Source/WebCore/bindings/js/JSDOMExceptionHandling.cpp
Source/WebCore/bindings/js/JSDOMExceptionHandling.h
Source/WebCore/dom/DOMException.cpp
Source/WebCore/dom/DOMException.h

index c58ad1e..aad99c0 100644 (file)
@@ -1,3 +1,14 @@
+2017-09-19  Chris Dumez  <cdumez@apple.com>
+
+        IDBRequest and IDBTransaction error properties should be DOMExceptions
+        https://bugs.webkit.org/show_bug.cgi?id=177201
+
+        Reviewed by Alex Christensen.
+
+        Rebaseline WPT now that it is passing.
+
+        * web-platform-tests/IndexedDB/error-attributes-expected.txt:
+
 2017-09-19  Joseph Pecoraro  <pecoraro@apple.com>
 
         Move non-upstreamed Resource Timing tests out of web-platform-tests
index 1714eb4..5bdd0fa 100644 (file)
@@ -1,3 +1,3 @@
 
-FAIL IDBRequest and IDBTransaction error properties should be DOMExceptions assert_true: expected true got false
+PASS IDBRequest and IDBTransaction error properties should be DOMExceptions 
 
index 59ff913..01bc200 100644 (file)
@@ -1,3 +1,38 @@
+2017-09-19  Chris Dumez  <cdumez@apple.com>
+
+        IDBRequest and IDBTransaction error properties should be DOMExceptions
+        https://bugs.webkit.org/show_bug.cgi?id=177201
+
+        Reviewed by Alex Christensen.
+
+        IDBRequest and IDBTransaction error properties should be DOMExceptions:
+        - https://w3c.github.io/IndexedDB/#idbrequest
+        - https://w3c.github.io/IndexedDB/#transaction
+
+        Previously, we used a DOMError type, which is obsolete.
+
+        No new tests, rebaselined existing test.
+
+        * Modules/indexeddb/IDBOpenDBRequest.cpp:
+        (WebCore::IDBOpenDBRequest::onError):
+        (WebCore::IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion):
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore:: const):
+        (WebCore::IDBRequest::uncaughtExceptionInEventHandler):
+        (WebCore::IDBRequest::onError):
+        * Modules/indexeddb/IDBRequest.h:
+        * Modules/indexeddb/IDBRequest.idl:
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::error const):
+        (WebCore::IDBTransaction::abortDueToFailedRequest):
+        (WebCore::IDBTransaction::didCreateIndexOnServer):
+        (WebCore::IDBTransaction::connectionClosedFromServer):
+        * Modules/indexeddb/IDBTransaction.h:
+        * Modules/indexeddb/IDBTransaction.idl:
+        * Modules/indexeddb/shared/IDBError.cpp:
+        (WebCore::IDBError::toDOMException const):
+        * Modules/indexeddb/shared/IDBError.h:
+
 2017-09-19  Daewoong Jang  <daewoong.jang@naverlabs.com>
 
         [Curl] Fix r222147
index 0bf6f94..268cea1 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "DOMError.h"
+#include "DOMException.h"
 #include "EventNames.h"
 #include "IDBConnectionProxy.h"
 #include "IDBConnectionToServer.h"
@@ -70,7 +70,7 @@ void IDBOpenDBRequest::onError(const IDBResultData& data)
 {
     ASSERT(currentThread() == originThreadID());
 
-    m_domError = DOMError::create(data.error().name(), data.error().message());
+    m_domError = data.error().toDOMException();
     enqueueEvent(IDBRequestCompletionEvent::create(eventNames().errorEvent, true, true, *this));
 }
 
@@ -105,7 +105,7 @@ void IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion()
     ASSERT(hasPendingActivity());
 
     IDBError idbError(AbortError);
-    m_domError = DOMError::create(idbError.name(), idbError.message());
+    m_domError = DOMException::create(AbortError);
     setResultToUndefined();
 
     m_transaction->addRequest(*this);
index 605692e..6b14f5a 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "DOMError.h"
+#include "DOMException.h"
 #include "Event.h"
 #include "EventNames.h"
 #include "EventQueue.h"
@@ -161,7 +161,7 @@ ExceptionOr<std::optional<IDBRequest::Result>> IDBRequest::result() const
     return std::optional<IDBRequest::Result> { m_result };
 }
 
-ExceptionOr<DOMError*> IDBRequest::error() const
+ExceptionOr<DOMException*> IDBRequest::error() const
 {
     ASSERT(currentThread() == originThreadID());
 
@@ -354,7 +354,7 @@ void IDBRequest::uncaughtExceptionInEventHandler()
     ASSERT(currentThread() == originThreadID());
 
     if (m_transaction && m_idbError.code() != AbortError)
-        m_transaction->abortDueToFailedRequest(DOMError::create("AbortError", ASCIILiteral("IDBTransaction will abort due to uncaught exception in an event handler")));
+        m_transaction->abortDueToFailedRequest(DOMException::create(AbortError, ASCIILiteral("IDBTransaction will abort due to uncaught exception in an event handler")));
 }
 
 void IDBRequest::setResult(const IDBKeyData& keyData)
@@ -531,7 +531,7 @@ void IDBRequest::onError()
     ASSERT(currentThread() == originThreadID());
     ASSERT(!m_idbError.isNull());
 
-    m_domError = DOMError::create(m_idbError.name(), m_idbError.message());
+    m_domError = m_idbError.toDOMException();
     enqueueEvent(Event::create(eventNames().errorEvent, true, true));
 }
 
index 3949889..c2ae36f 100644 (file)
@@ -37,7 +37,7 @@
 
 namespace WebCore {
 
-class DOMError;
+class DOMException;
 class Event;
 class IDBCursor;
 class IDBDatabase;
@@ -73,7 +73,7 @@ public:
     using Source = Variant<RefPtr<IDBObjectStore>, RefPtr<IDBIndex>, RefPtr<IDBCursor>>;
     const std::optional<Source>& source() const { return m_source; }
 
-    ExceptionOr<DOMError*> error() const;
+    ExceptionOr<DOMException*> error() const;
 
     RefPtr<IDBTransaction> transaction() const;
     
@@ -128,7 +128,7 @@ protected:
     ReadyState m_readyState { ReadyState::Pending };
     RefPtr<IDBTransaction> m_transaction;
     bool m_shouldExposeTransactionToDOM { true };
-    RefPtr<DOMError> m_domError;
+    RefPtr<DOMException> m_domError;
     IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
     bool m_contextStopped { false };
     Event* m_openDatabaseSuccessEvent { nullptr };
index c1ec27b..3c53fd6 100644 (file)
@@ -34,7 +34,7 @@
     SkipVTableValidation,
 ] interface IDBRequest : EventTarget {
     [GetterMayThrowException] readonly attribute (IDBCursor or IDBDatabase or any)? result;
-    [GetterMayThrowException] readonly attribute DOMError? error;
+    [GetterMayThrowException] readonly attribute DOMException? error;
     readonly attribute (IDBObjectStore or IDBIndex or IDBCursor)? source;
     readonly attribute IDBTransaction transaction;
     readonly attribute IDBRequestReadyState readyState;
index e91abc9..b126da4 100644 (file)
@@ -28,7 +28,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "DOMError.h"
+#include "DOMException.h"
 #include "DOMStringList.h"
 #include "DOMWindow.h"
 #include "Event.h"
@@ -134,7 +134,7 @@ IDBDatabase* IDBTransaction::db()
     return m_database.ptr();
 }
 
-DOMError* IDBTransaction::error() const
+DOMException* IDBTransaction::error() const
 {
     ASSERT(currentThread() == m_database->originThreadID());
     return m_domError.get();
@@ -181,7 +181,7 @@ ExceptionOr<Ref<IDBObjectStore>> IDBTransaction::objectStore(const String& objec
 }
 
 
-void IDBTransaction::abortDueToFailedRequest(DOMError& error)
+void IDBTransaction::abortDueToFailedRequest(DOMException& error)
 {
     LOG(IndexedDB, "IDBTransaction::abortDueToFailedRequest");
     ASSERT(currentThread() == m_database->originThreadID());
@@ -759,7 +759,7 @@ void IDBTransaction::didCreateIndexOnServer(const IDBResultData& resultData)
         return;
 
     // Otherwise, failure to create an index forced abortion of the transaction.
-    abortDueToFailedRequest(DOMError::create(resultData.error().name(), resultData.error().message()));
+    abortDueToFailedRequest(DOMException::create(resultData.error().message(), resultData.error().name()));
 }
 
 void IDBTransaction::renameIndex(IDBIndex& index, const String& newName)
@@ -1385,7 +1385,7 @@ void IDBTransaction::connectionClosedFromServer(const IDBError& error)
     m_transactionOperationMap.clear();
 
     m_idbError = error;
-    m_domError = error.toDOMError();
+    m_domError = error.toDOMException();
     fireOnAbort();
 }
 
index af96c4c..fdb267d 100644 (file)
@@ -43,7 +43,7 @@
 
 namespace WebCore {
 
-class DOMError;
+class DOMException;
 class DOMStringList;
 class IDBCursor;
 class IDBCursorInfo;
@@ -76,7 +76,7 @@ public:
     Ref<DOMStringList> objectStoreNames() const;
     IDBTransactionMode mode() const { return m_info.mode(); }
     IDBDatabase* db();
-    DOMError* error() const;
+    DOMException* error() const;
     ExceptionOr<Ref<IDBObjectStore>> objectStore(const String& name);
     ExceptionOr<void> abort();
 
@@ -133,7 +133,7 @@ public:
     void addRequest(IDBRequest&);
     void removeRequest(IDBRequest&);
 
-    void abortDueToFailedRequest(DOMError&);
+    void abortDueToFailedRequest(DOMException&);
 
     void activate();
     void deactivate();
@@ -235,7 +235,7 @@ private:
     bool m_startedOnServer { false };
 
     IDBError m_idbError;
-    RefPtr<DOMError> m_domError;
+    RefPtr<DOMException> m_domError;
 
     Timer m_pendingOperationTimer;
     Timer m_completedOperationTimer;
index 769e919..b6731a3 100644 (file)
@@ -33,7 +33,7 @@
     readonly attribute DOMStringList objectStoreNames;
     readonly attribute IDBTransactionMode mode;
     readonly attribute IDBDatabase db;
-    readonly attribute DOMError error;
+    readonly attribute DOMException error;
 
     [MayThrowException] IDBObjectStore objectStore(DOMString name);
     [MayThrowException] void abort();
index c747c55..ae314b2 100644 (file)
@@ -64,9 +64,12 @@ String IDBError::message() const
     return DOMException::message(m_code.value());
 }
 
-RefPtr<DOMError> IDBError::toDOMError() const
+RefPtr<DOMException> IDBError::toDOMException() const
 {
-    return DOMError::create(name(), m_message);
+    if (!m_code)
+        return nullptr;
+
+    return DOMException::create(*m_code, m_message);
 }
 
 } // namespace WebCore
index 4c6e0ca..62a76c8 100644 (file)
@@ -27,7 +27,7 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "DOMError.h"
+#include "DOMException.h"
 #include "ExceptionCode.h"
 #include <wtf/text/WTFString.h>
 
@@ -44,7 +44,7 @@ public:
 
     WEBCORE_EXPORT IDBError& operator=(const IDBError&);
 
-    RefPtr<DOMError> toDOMError() const;
+    RefPtr<DOMException> toDOMException() const;
 
     std::optional<ExceptionCode> code() const { return m_code; }
     String name() const;
index 730d13b..73a5b4c 100644 (file)
@@ -122,22 +122,22 @@ void reportCurrentException(ExecState* exec)
     reportException(exec, exception);
 }
 
-static JSValue createDOMException(ExecState* exec, ExceptionCode ec, const String* message = nullptr)
+JSValue createDOMException(ExecState* exec, ExceptionCode ec, const String& message)
 {
     if (ec == ExistingExceptionError)
         return jsUndefined();
 
     // FIXME: Handle other WebIDL exception types.
     if (ec == TypeError) {
-        if (!message || message->isEmpty())
+        if (message.isEmpty())
             return createTypeError(exec);
-        return createTypeError(exec, *message);
+        return createTypeError(exec, message);
     }
 
     if (ec == RangeError) {
-        if (!message || message->isEmpty())
+        if (message.isEmpty())
             return createRangeError(exec, ASCIILiteral("Bad value"));
-        return createRangeError(exec, *message);
+        return createRangeError(exec, message);
     }
 
     if (ec == StackOverflowError)
@@ -154,11 +154,6 @@ static JSValue createDOMException(ExecState* exec, ExceptionCode ec, const Strin
     return errorObject;
 }
 
-JSValue createDOMException(ExecState* exec, ExceptionCode ec, const String& message)
-{
-    return createDOMException(exec, ec, &message);
-}
-
 JSValue createDOMException(ExecState& state, Exception&& exception)
 {
     return createDOMException(&state, exception.code(), exception.releaseMessage());
@@ -216,15 +211,13 @@ void throwNotSupportedError(JSC::ExecState& state, JSC::ThrowScope& scope)
 void throwNotSupportedError(JSC::ExecState& state, JSC::ThrowScope& scope, const char* message)
 {
     scope.assertNoException();
-    String messageString(message);
-    throwException(&state, scope, createDOMException(&state, NotSupportedError, &messageString));
+    throwException(&state, scope, createDOMException(&state, NotSupportedError, message));
 }
 
 void throwInvalidStateError(JSC::ExecState& state, JSC::ThrowScope& scope, const char* message)
 {
     scope.assertNoException();
-    String messageString(message);
-    throwException(&state, scope, createDOMException(&state, InvalidStateError, &messageString));
+    throwException(&state, scope, createDOMException(&state, InvalidStateError, message));
 }
 
 void throwSecurityError(JSC::ExecState& state, JSC::ThrowScope& scope, const String& message)
index cd1aa28..2808c8f 100644 (file)
@@ -83,7 +83,7 @@ WEBCORE_EXPORT void reportException(JSC::ExecState*, JSC::Exception*, CachedScri
 void reportCurrentException(JSC::ExecState*);
 
 JSC::JSValue createDOMException(JSC::ExecState&, Exception&&);
-JSC::JSValue createDOMException(JSC::ExecState*, ExceptionCode, const String&);
+JSC::JSValue createDOMException(JSC::ExecState*, ExceptionCode, const String& = emptyString());
 
 // Convert a DOM implementation exception into a JavaScript exception in the execution state.
 WEBCORE_EXPORT void propagateExceptionSlowPath(JSC::ExecState&, JSC::ThrowScope&, Exception&&);
index c98ffc1..c44a0a4 100644 (file)
@@ -90,10 +90,10 @@ static DOMException::LegacyCode legacyCodeFromName(const String& name)
     return 0;
 }
 
-Ref<DOMException> DOMException::create(ExceptionCode ec, const String* message)
+Ref<DOMException> DOMException::create(ExceptionCode ec, const String& message)
 {
     auto& description = DOMException::description(ec);
-    return adoptRef(*new DOMException(description.legacyCode, description.name, message && !message->isEmpty() ? *message : ASCIILiteral(description.message)));
+    return adoptRef(*new DOMException(description.legacyCode, description.name, !message.isEmpty() ? message : ASCIILiteral(description.message)));
 }
 
 Ref<DOMException> DOMException::create(const String& message, const String& name)
index dabe930..2c77070 100644 (file)
@@ -37,7 +37,7 @@ class Exception;
 
 class DOMException : public RefCounted<DOMException> {
 public:
-    static Ref<DOMException> create(ExceptionCode, const String* message = nullptr);
+    static Ref<DOMException> create(ExceptionCode, const String& message = emptyString());
     static Ref<DOMException> create(const Exception&);
 
     // For DOM bindings.