Title: [207832] trunk/Source/WebCore
Revision
207832
Author
[email protected]
Date
2016-10-25 12:17:38 -0700 (Tue, 25 Oct 2016)

Log Message

IDBObjectStore.createIndex() should take a union in parameter
https://bugs.webkit.org/show_bug.cgi?id=163935

Reviewed by Darin Adler.

IDBObjectStore.createIndex() should take a union in parameter:
- https://www.w3.org/TR/IndexedDB/#idl-def-IDBObjectStore

No new tests, no expected Web-exposed behavior change.

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::createObjectStore):
* Modules/indexeddb/IDBKeyPath.cpp:
(WebCore::isIDBKeyPathValid):
(WebCore::IDBKeyPath::isValid): Deleted.
* Modules/indexeddb/IDBKeyPath.h:
(WebCore::IDBKeyPath::isNull):
* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::createIndex):
* Modules/indexeddb/IDBObjectStore.h:
* Modules/indexeddb/IDBObjectStore.idl:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (207831 => 207832)


--- trunk/Source/WebCore/ChangeLog	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/ChangeLog	2016-10-25 19:17:38 UTC (rev 207832)
@@ -1,3 +1,27 @@
+2016-10-25  Chris Dumez  <[email protected]>
+
+        IDBObjectStore.createIndex() should take a union in parameter
+        https://bugs.webkit.org/show_bug.cgi?id=163935
+
+        Reviewed by Darin Adler.
+
+        IDBObjectStore.createIndex() should take a union in parameter:
+        - https://www.w3.org/TR/IndexedDB/#idl-def-IDBObjectStore
+
+        No new tests, no expected Web-exposed behavior change.
+
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::createObjectStore):
+        * Modules/indexeddb/IDBKeyPath.cpp:
+        (WebCore::isIDBKeyPathValid):
+        (WebCore::IDBKeyPath::isValid): Deleted.
+        * Modules/indexeddb/IDBKeyPath.h:
+        (WebCore::IDBKeyPath::isNull):
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::createIndex):
+        * Modules/indexeddb/IDBObjectStore.h:
+        * Modules/indexeddb/IDBObjectStore.idl:
+
 2016-10-24  Sam Weinig  <[email protected]>
 
         [WebIDL] Move more types over to the new JSConverter based toJS functions

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp	2016-10-25 19:17:38 UTC (rev 207832)
@@ -146,15 +146,15 @@
     if (m_info.hasObjectStore(name))
         return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists.") };
 
-    IDBKeyPath keyPath(WTFMove(parameters.keyPath));
-    if (!keyPath.isNull() && !keyPath.isValid())
+    auto& keyPath = parameters.keyPath;
+    if (keyPath && !isIDBKeyPathValid(keyPath.value()))
         return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path.") };
 
-    if (parameters.autoIncrement && ((keyPath.type() == IDBKeyPath::Type::String && keyPath.string().isEmpty()) || keyPath.type() == IDBKeyPath::Type::Array))
+    if (keyPath && parameters.autoIncrement && ((WTF::holds_alternative<String>(keyPath.value()) && WTF::get<String>(keyPath.value()).isEmpty()) || WTF::holds_alternative<Vector<String>>(keyPath.value())))
         return Exception { IDBDatabaseException::InvalidAccessError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': The autoIncrement option was set but the keyPath option was empty or an array.") };
 
     // Install the new ObjectStore into the connection's metadata.
-    auto info = m_info.createNewObjectStore(name, keyPath, parameters.autoIncrement);
+    auto info = m_info.createNewObjectStore(name, WTFMove(keyPath), parameters.autoIncrement);
 
     // Create the actual IDBObjectStore from the transaction, which also schedules the operation server side.
     return m_versionChangeTransaction->createObjectStore(info);

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp	2016-10-25 19:17:38 UTC (rev 207832)
@@ -222,24 +222,20 @@
     }
 }
 
-bool IDBKeyPath::isValid() const
+bool isIDBKeyPathValid(const IDBKeyPathVariant& keyPath)
 {
-    switch (m_type) {
-    case Type::Null:
-        return false;
-    case Type::String:
-        return IDBIsValidKeyPath(m_string);
-    case Type::Array:
-        if (m_array.isEmpty())
+    auto visitor = WTF::makeVisitor([](const String& string) {
+        return IDBIsValidKeyPath(string);
+    }, [](const Vector<String>& vector) {
+        if (vector.isEmpty())
             return false;
-        for (auto& key : m_array) {
+        for (auto& key : vector) {
             if (!IDBIsValidKeyPath(key))
                 return false;
         }
         return true;
-    }
-    ASSERT_NOT_REACHED();
-    return false;
+    });
+    return WTF::visit(visitor, keyPath);
 }
 
 bool IDBKeyPath::operator==(const IDBKeyPath& other) const

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.h (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.h	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.h	2016-10-25 19:17:38 UTC (rev 207832)
@@ -34,6 +34,7 @@
 namespace WebCore {
 
 using IDBKeyPathVariant = WTF::Variant<String, Vector<String>>;
+bool isIDBKeyPathValid(const IDBKeyPathVariant&);
 
 class KeyedDecoder;
 class KeyedEncoder;
@@ -71,7 +72,6 @@
     }
 
     bool isNull() const { return m_type == Type::Null; }
-    bool isValid() const;
     bool operator==(const IDBKeyPath& other) const;
 
     IDBKeyPath isolatedCopy() const;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp	2016-10-25 19:17:38 UTC (rev 207832)
@@ -371,7 +371,7 @@
     return m_transaction->requestClearObjectStore(execState, *this);
 }
 
-ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, const IDBKeyPath& keyPath, const IndexParameters& parameters)
+ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, IDBKeyPathVariant&& keyPath, const IndexParameters& parameters)
 {
     LOG(IndexedDB, "IDBObjectStore::createIndex %s", name.utf8().data());
     ASSERT(currentThread() == m_transaction->database().originThreadID());
@@ -385,7 +385,7 @@
     if (!m_transaction->isActive())
         return Exception { IDBDatabaseException::TransactionInactiveError };
 
-    if (!keyPath.isValid())
+    if (!isIDBKeyPathValid(keyPath))
         return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument contains an invalid key path.") };
 
     if (name.isNull())
@@ -394,11 +394,11 @@
     if (m_info.hasIndex(name))
         return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': An index with the specified name already exists.") };
 
-    if (keyPath.type() == IDBKeyPath::Type::Array && parameters.multiEntry)
+    if (parameters.multiEntry && WTF::holds_alternative<Vector<String>>(keyPath))
         return Exception { IDBDatabaseException::InvalidAccessError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument was an array and the multiEntry option is true.") };
 
     // Install the new Index into the ObjectStore's info.
-    IDBIndexInfo info = m_info.createNewIndex(name, keyPath, parameters.unique, parameters.multiEntry);
+    IDBIndexInfo info = m_info.createNewIndex(name, Optional<IDBKeyPathVariant>(WTFMove(keyPath)), parameters.unique, parameters.multiEntry);
     m_transaction->database().didCreateIndexInfo(info);
 
     // Create the actual IDBObjectStore from the transaction, which also schedules the operation server side.

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h	2016-10-25 19:17:38 UTC (rev 207832)
@@ -29,6 +29,7 @@
 
 #include "ActiveDOMObject.h"
 #include "ExceptionOr.h"
+#include "IDBKeyPath.h"
 #include "IDBObjectStoreInfo.h"
 #include <wtf/HashSet.h>
 
@@ -80,7 +81,7 @@
     ExceptionOr<Ref<IDBRequest>> deleteFunction(JSC::ExecState&, IDBKeyRange*);
     ExceptionOr<Ref<IDBRequest>> deleteFunction(JSC::ExecState&, JSC::JSValue key);
     ExceptionOr<Ref<IDBRequest>> clear(JSC::ExecState&);
-    ExceptionOr<Ref<IDBIndex>> createIndex(JSC::ExecState&, const String& name, const IDBKeyPath&, const IndexParameters&);
+    ExceptionOr<Ref<IDBIndex>> createIndex(JSC::ExecState&, const String& name, IDBKeyPathVariant&&, const IndexParameters&);
     ExceptionOr<Ref<IDBIndex>> index(const String& name);
     ExceptionOr<void> deleteIndex(const String& name);
     ExceptionOr<Ref<IDBRequest>> count(JSC::ExecState&, IDBKeyRange*);

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.idl (207831 => 207832)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.idl	2016-10-25 19:14:55 UTC (rev 207831)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.idl	2016-10-25 19:17:38 UTC (rev 207832)
@@ -45,8 +45,7 @@
     [CallWith=ScriptState, MayThrowException] IDBRequest clear();
     [CallWith=ScriptState, MayThrowException] IDBRequest openCursor(optional IDBKeyRange? range = null, optional DOMString direction = "next");
     [CallWith=ScriptState, MayThrowException] IDBRequest openCursor(any key, optional DOMString direction = "next");
-    [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, sequence<DOMString> keyPath, optional IDBIndexParameters options);
-    [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, DOMString keyPath, optional IDBIndexParameters options);
+    [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options);
     [MayThrowException] IDBIndex index(DOMString name);
     [MayThrowException] void deleteIndex(DOMString name);
     [CallWith=ScriptState, MayThrowException] IDBRequest count(optional IDBKeyRange? range = null);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to