Changeset 207832 in webkit


Ignore:
Timestamp:
Oct 25, 2016 12:17:38 PM (8 years ago)
Author:
Chris Dumez
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:

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:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207829 r207832  
     12016-10-25  Chris Dumez  <cdumez@apple.com>
     2
     3        IDBObjectStore.createIndex() should take a union in parameter
     4        https://bugs.webkit.org/show_bug.cgi?id=163935
     5
     6        Reviewed by Darin Adler.
     7
     8        IDBObjectStore.createIndex() should take a union in parameter:
     9        - https://www.w3.org/TR/IndexedDB/#idl-def-IDBObjectStore
     10
     11        No new tests, no expected Web-exposed behavior change.
     12
     13        * Modules/indexeddb/IDBDatabase.cpp:
     14        (WebCore::IDBDatabase::createObjectStore):
     15        * Modules/indexeddb/IDBKeyPath.cpp:
     16        (WebCore::isIDBKeyPathValid):
     17        (WebCore::IDBKeyPath::isValid): Deleted.
     18        * Modules/indexeddb/IDBKeyPath.h:
     19        (WebCore::IDBKeyPath::isNull):
     20        * Modules/indexeddb/IDBObjectStore.cpp:
     21        (WebCore::IDBObjectStore::createIndex):
     22        * Modules/indexeddb/IDBObjectStore.h:
     23        * Modules/indexeddb/IDBObjectStore.idl:
     24
    1252016-10-24  Sam Weinig  <sam@webkit.org>
    226
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp

    r207806 r207832  
    147147        return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists.") };
    148148
    149     IDBKeyPath keyPath(WTFMove(parameters.keyPath));
    150     if (!keyPath.isNull() && !keyPath.isValid())
     149    auto& keyPath = parameters.keyPath;
     150    if (keyPath && !isIDBKeyPathValid(keyPath.value()))
    151151        return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path.") };
    152152
    153     if (parameters.autoIncrement && ((keyPath.type() == IDBKeyPath::Type::String && keyPath.string().isEmpty()) || keyPath.type() == IDBKeyPath::Type::Array))
     153    if (keyPath && parameters.autoIncrement && ((WTF::holds_alternative<String>(keyPath.value()) && WTF::get<String>(keyPath.value()).isEmpty()) || WTF::holds_alternative<Vector<String>>(keyPath.value())))
    154154        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.") };
    155155
    156156    // Install the new ObjectStore into the connection's metadata.
    157     auto info = m_info.createNewObjectStore(name, keyPath, parameters.autoIncrement);
     157    auto info = m_info.createNewObjectStore(name, WTFMove(keyPath), parameters.autoIncrement);
    158158
    159159    // Create the actual IDBObjectStore from the transaction, which also schedules the operation server side.
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp

    r207806 r207832  
    223223}
    224224
    225 bool IDBKeyPath::isValid() const
    226 {
    227     switch (m_type) {
    228     case Type::Null:
    229         return false;
    230     case Type::String:
    231         return IDBIsValidKeyPath(m_string);
    232     case Type::Array:
    233         if (m_array.isEmpty())
     225bool isIDBKeyPathValid(const IDBKeyPathVariant& keyPath)
     226{
     227    auto visitor = WTF::makeVisitor([](const String& string) {
     228        return IDBIsValidKeyPath(string);
     229    }, [](const Vector<String>& vector) {
     230        if (vector.isEmpty())
    234231            return false;
    235         for (auto& key : m_array) {
     232        for (auto& key : vector) {
    236233            if (!IDBIsValidKeyPath(key))
    237234                return false;
    238235        }
    239236        return true;
    240     }
    241     ASSERT_NOT_REACHED();
    242     return false;
     237    });
     238    return WTF::visit(visitor, keyPath);
    243239}
    244240
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.h

    r207806 r207832  
    3535
    3636using IDBKeyPathVariant = WTF::Variant<String, Vector<String>>;
     37bool isIDBKeyPathValid(const IDBKeyPathVariant&);
    3738
    3839class KeyedDecoder;
     
    7273
    7374    bool isNull() const { return m_type == Type::Null; }
    74     bool isValid() const;
    7575    bool operator==(const IDBKeyPath& other) const;
    7676
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp

    r207761 r207832  
    372372}
    373373
    374 ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, const IDBKeyPath& keyPath, const IndexParameters& parameters)
     374ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, IDBKeyPathVariant&& keyPath, const IndexParameters& parameters)
    375375{
    376376    LOG(IndexedDB, "IDBObjectStore::createIndex %s", name.utf8().data());
     
    386386        return Exception { IDBDatabaseException::TransactionInactiveError };
    387387
    388     if (!keyPath.isValid())
     388    if (!isIDBKeyPathValid(keyPath))
    389389        return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument contains an invalid key path.") };
    390390
     
    395395        return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': An index with the specified name already exists.") };
    396396
    397     if (keyPath.type() == IDBKeyPath::Type::Array && parameters.multiEntry)
     397    if (parameters.multiEntry && WTF::holds_alternative<Vector<String>>(keyPath))
    398398        return Exception { IDBDatabaseException::InvalidAccessError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument was an array and the multiEntry option is true.") };
    399399
    400400    // Install the new Index into the ObjectStore's info.
    401     IDBIndexInfo info = m_info.createNewIndex(name, keyPath, parameters.unique, parameters.multiEntry);
     401    IDBIndexInfo info = m_info.createNewIndex(name, Optional<IDBKeyPathVariant>(WTFMove(keyPath)), parameters.unique, parameters.multiEntry);
    402402    m_transaction->database().didCreateIndexInfo(info);
    403403
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h

    r207761 r207832  
    3030#include "ActiveDOMObject.h"
    3131#include "ExceptionOr.h"
     32#include "IDBKeyPath.h"
    3233#include "IDBObjectStoreInfo.h"
    3334#include <wtf/HashSet.h>
     
    8182    ExceptionOr<Ref<IDBRequest>> deleteFunction(JSC::ExecState&, JSC::JSValue key);
    8283    ExceptionOr<Ref<IDBRequest>> clear(JSC::ExecState&);
    83     ExceptionOr<Ref<IDBIndex>> createIndex(JSC::ExecState&, const String& name, const IDBKeyPath&, const IndexParameters&);
     84    ExceptionOr<Ref<IDBIndex>> createIndex(JSC::ExecState&, const String& name, IDBKeyPathVariant&&, const IndexParameters&);
    8485    ExceptionOr<Ref<IDBIndex>> index(const String& name);
    8586    ExceptionOr<void> deleteIndex(const String& name);
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.idl

    r207641 r207832  
    4646    [CallWith=ScriptState, MayThrowException] IDBRequest openCursor(optional IDBKeyRange? range = null, optional DOMString direction = "next");
    4747    [CallWith=ScriptState, MayThrowException] IDBRequest openCursor(any key, optional DOMString direction = "next");
    48     [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, sequence<DOMString> keyPath, optional IDBIndexParameters options);
    49     [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, DOMString keyPath, optional IDBIndexParameters options);
     48    [CallWith=ScriptState, MayThrowException] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options);
    5049    [MayThrowException] IDBIndex index(DOMString name);
    5150    [MayThrowException] void deleteIndex(DOMString name);
Note: See TracChangeset for help on using the changeset viewer.