Changeset 207832 in webkit
- Timestamp:
- Oct 25, 2016 12:17:38 PM (8 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r207829 r207832 1 2016-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 1 25 2016-10-24 Sam Weinig <sam@webkit.org> 2 26 -
trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
r207806 r207832 147 147 return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': An object store with the specified name already exists.") }; 148 148 149 IDBKeyPath keyPath(WTFMove(parameters.keyPath));150 if ( !keyPath.isNull() && !keyPath.isValid())149 auto& keyPath = parameters.keyPath; 150 if (keyPath && !isIDBKeyPathValid(keyPath.value())) 151 151 return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createObjectStore' on 'IDBDatabase': The keyPath option is not a valid key path.") }; 152 152 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()))) 154 154 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.") }; 155 155 156 156 // 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); 158 158 159 159 // Create the actual IDBObjectStore from the transaction, which also schedules the operation server side. -
trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.cpp
r207806 r207832 223 223 } 224 224 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()) 225 bool 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()) 234 231 return false; 235 for (auto& key : m_array) {232 for (auto& key : vector) { 236 233 if (!IDBIsValidKeyPath(key)) 237 234 return false; 238 235 } 239 236 return true; 240 } 241 ASSERT_NOT_REACHED(); 242 return false; 237 }); 238 return WTF::visit(visitor, keyPath); 243 239 } 244 240 -
trunk/Source/WebCore/Modules/indexeddb/IDBKeyPath.h
r207806 r207832 35 35 36 36 using IDBKeyPathVariant = WTF::Variant<String, Vector<String>>; 37 bool isIDBKeyPathValid(const IDBKeyPathVariant&); 37 38 38 39 class KeyedDecoder; … … 72 73 73 74 bool isNull() const { return m_type == Type::Null; } 74 bool isValid() const;75 75 bool operator==(const IDBKeyPath& other) const; 76 76 -
trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
r207761 r207832 372 372 } 373 373 374 ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, const IDBKeyPath& keyPath, const IndexParameters& parameters)374 ExceptionOr<Ref<IDBIndex>> IDBObjectStore::createIndex(ExecState&, const String& name, IDBKeyPathVariant&& keyPath, const IndexParameters& parameters) 375 375 { 376 376 LOG(IndexedDB, "IDBObjectStore::createIndex %s", name.utf8().data()); … … 386 386 return Exception { IDBDatabaseException::TransactionInactiveError }; 387 387 388 if (! keyPath.isValid())388 if (!isIDBKeyPathValid(keyPath)) 389 389 return Exception { IDBDatabaseException::SyntaxError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument contains an invalid key path.") }; 390 390 … … 395 395 return Exception { IDBDatabaseException::ConstraintError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': An index with the specified name already exists.") }; 396 396 397 if ( keyPath.type() == IDBKeyPath::Type::Array && parameters.multiEntry)397 if (parameters.multiEntry && WTF::holds_alternative<Vector<String>>(keyPath)) 398 398 return Exception { IDBDatabaseException::InvalidAccessError, ASCIILiteral("Failed to execute 'createIndex' on 'IDBObjectStore': The keyPath argument was an array and the multiEntry option is true.") }; 399 399 400 400 // 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); 402 402 m_transaction->database().didCreateIndexInfo(info); 403 403 -
trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h
r207761 r207832 30 30 #include "ActiveDOMObject.h" 31 31 #include "ExceptionOr.h" 32 #include "IDBKeyPath.h" 32 33 #include "IDBObjectStoreInfo.h" 33 34 #include <wtf/HashSet.h> … … 81 82 ExceptionOr<Ref<IDBRequest>> deleteFunction(JSC::ExecState&, JSC::JSValue key); 82 83 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&); 84 85 ExceptionOr<Ref<IDBIndex>> index(const String& name); 85 86 ExceptionOr<void> deleteIndex(const String& name); -
trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.idl
r207641 r207832 46 46 [CallWith=ScriptState, MayThrowException] IDBRequest openCursor(optional IDBKeyRange? range = null, optional DOMString direction = "next"); 47 47 [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); 50 49 [MayThrowException] IDBIndex index(DOMString name); 51 50 [MayThrowException] void deleteIndex(DOMString name);
Note: See TracChangeset
for help on using the changeset viewer.