Changeset 105891 in webkit
- Timestamp:
- Jan 25, 2012, 10:01:13 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r105890 r105891 1 2012-01-25 Joshua Bell <jsbell@chromium.org> 2 3 IndexedDB: Need to distinguish key paths that don't yield value vs. yield invalid key 4 https://bugs.webkit.org/show_bug.cgi?id=76487 5 6 Reviewed by Tony Chang. 7 8 * storage/indexeddb/keypath-edges-expected.txt: Added. 9 * storage/indexeddb/keypath-edges.html: Added. 10 * storage/indexeddb/objectstore-basics-expected.txt: 11 * storage/indexeddb/objectstore-basics.html: 12 1 13 2012-01-25 Tony Chang <tony@chromium.org> 2 14 -
trunk/LayoutTests/storage/indexeddb/objectstore-basics-expected.txt
r105329 r105891 99 99 db.transaction(['storeName'], webkitIDBTransaction.READ_WRITE) 100 100 store = transaction.objectStore('storeName') 101 store.add({x: null}, 'validkey') 102 PASS event.cancelable is true 103 addWithNullIndexFailure(): 104 PASS event.target.errorCode is webkitIDBDatabaseException.DATA_ERR 105 event.preventDefault() 101 Expecting exception from store.add({x: null}, 'validkey') 102 PASS Exception was thrown. 103 PASS code is webkitIDBDatabaseException.DATA_ERR 106 104 db.transaction(['storeName'], webkitIDBTransaction.READ_WRITE) 107 105 store = transaction.objectStore('storeName') … … 165 163 PASS Exception was thrown. 166 164 PASS code is webkitIDBDatabaseException.DATA_ERR 165 If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key. 166 Expecting exception from storeWithIndex.put({indexKey: null}, 'key') 167 PASS Exception was thrown. 168 PASS code is webkitIDBDatabaseException.DATA_ERR 167 169 168 170 IDBObjectStore.add() … … 187 189 PASS Exception was thrown. 188 190 PASS code is webkitIDBDatabaseException.DATA_ERR 191 If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key. 192 Expecting exception from storeWithIndex.add({indexKey: null}, 'key') 193 PASS Exception was thrown. 194 PASS code is webkitIDBDatabaseException.DATA_ERR 189 195 PASS successfullyParsed is true 190 196 -
trunk/LayoutTests/storage/indexeddb/objectstore-basics.html
r105329 r105891 216 216 var store = evalAndLog("store = transaction.objectStore('storeName')"); 217 217 218 request = evalAndLog("store.add({x: null}, 'validkey')"); 219 request.onsuccess = unexpectedSuccessCallback; 220 request.onerror = addWithNullIndexFailure; 221 } 222 223 function addWithNullIndexFailure() 224 { 225 shouldBeTrue("event.cancelable"); 226 debug("addWithNullIndexFailure():"); 227 shouldBe("event.target.errorCode", "webkitIDBDatabaseException.DATA_ERR"); 228 229 evalAndLog("event.preventDefault()"); 218 evalAndExpectException("store.add({x: null}, 'validkey')", "webkitIDBDatabaseException.DATA_ERR"); 230 219 231 220 transaction = evalAndLog("db.transaction(['storeName'], webkitIDBTransaction.READ_WRITE)"); … … 319 308 evalAndExpectException("storeWithOutOfLineKeys.put({}, null)", "webkitIDBDatabaseException.DATA_ERR"); 320 309 321 // FIXME: Add precondition checks for put() with index key paths that yield invalid keys.322 // https://bugs.webkit.org/show_bug.cgi?id=76487310 debug("If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key."); 311 evalAndExpectException("storeWithIndex.put({indexKey: null}, 'key')", "webkitIDBDatabaseException.DATA_ERR"); 323 312 324 313 debug(""); … … 339 328 evalAndExpectException("storeWithOutOfLineKeys.add({}, null)", "webkitIDBDatabaseException.DATA_ERR"); 340 329 341 // FIXME: Add precondition checks for add() with index key paths that yield invalid keys.342 // https://bugs.webkit.org/show_bug.cgi?id=76487330 debug("If there are any indexes referencing this object store whose key path is a string, evaluating their key path on the value parameter yields a value, and that value is not a valid key."); 331 evalAndExpectException("storeWithIndex.add({indexKey: null}, 'key')", "webkitIDBDatabaseException.DATA_ERR"); 343 332 344 333 done(); -
trunk/Source/WebCore/ChangeLog
r105885 r105891 1 2012-01-25 Joshua Bell <jsbell@chromium.org> 2 3 IndexedDB: Need to distinguish key paths that don't yield value vs. yield invalid key 4 https://bugs.webkit.org/show_bug.cgi?id=76487 5 6 Implement the precondition checks for IDBObjectStore.add/put operations: raise an error 7 if there is a key generator (autoIncrement) and the path yields a value and the value 8 is not a valid key; raise an error if any of the index key paths yield a value which 9 is not a valid key. 10 11 Reviewed by Tony Chang. 12 13 Tests: storage/indexeddb/keypath-edges.html 14 storage/indexeddb/objectstore-basics.html 15 16 * storage/IDBObjectStoreBackendImpl.cpp: 17 (WebCore::IDBObjectStoreBackendImpl::put): 18 1 19 2012-01-25 Yong Li <yoli@rim.com> 2 20 -
trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp
r105329 r105891 132 132 RefPtr<IDBTransactionBackendInterface> transaction = transactionPtr; 133 133 134 if (key && (key->type() == IDBKey::InvalidType)) {135 ec = IDBDatabaseException::DATA_ERR;136 return;137 }138 139 const bool autoIncrement = objectStore->autoIncrement();140 const bool hasKeyPath = !objectStore->m_keyPath.isNull();141 142 134 if (putMode != CursorUpdate) { 135 if (key && !key->valid()) { 136 ec = IDBDatabaseException::DATA_ERR; 137 return; 138 } 139 const bool autoIncrement = objectStore->autoIncrement(); 140 const bool hasKeyPath = !objectStore->m_keyPath.isNull(); 143 141 if (!key && !autoIncrement && !hasKeyPath) { 144 142 ec = IDBDatabaseException::DATA_ERR; … … 146 144 } 147 145 if (hasKeyPath) { 148 if (key && key->valid()) {146 if (key) { 149 147 ec = IDBDatabaseException::DATA_ERR; 150 148 return; 151 149 } 150 151 RefPtr<IDBKey> keyPathKey = fetchKeyFromKeyPath(value.get(), objectStore->m_keyPath); 152 152 if (!autoIncrement) { 153 RefPtr<IDBKey> keyPathKey = fetchKeyFromKeyPath(value.get(), objectStore->m_keyPath);154 153 if (!keyPathKey || !keyPathKey->valid()) { 155 154 ec = IDBDatabaseException::DATA_ERR; 156 155 return; 157 156 } 157 } else if (keyPathKey && !keyPathKey->valid()) { 158 ec = IDBDatabaseException::DATA_ERR; 159 return; 158 160 } 159 161 } 160 // FIXME: Add precondition checks for index key paths that yield invalid keys. 161 // https://bugs.webkit.org/show_bug.cgi?id=76487 162 } 162 for (IndexMap::iterator it = m_indexes.begin(); it != m_indexes.end(); ++it) { 163 const RefPtr<IDBIndexBackendImpl>& index = it->second; 164 RefPtr<IDBKey> indexKey = fetchKeyFromKeyPath(value.get(), index->keyPath()); 165 if (indexKey && !indexKey->valid()) { 166 ec = IDBDatabaseException::DATA_ERR; 167 return; 168 } 169 } 170 } 163 171 164 172 if (!transaction->scheduleTask(createCallbackTask(&IDBObjectStoreBackendImpl::putInternal, objectStore, value, key, putMode, callbacks, transaction))) … … 173 181 const bool autoIncrement = objectStore->autoIncrement(); 174 182 const bool hasKeyPath = !objectStore->m_keyPath.isNull(); 175 176 if (hasKeyPath && key && putMode != CursorUpdate) {177 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "A key was supplied for an objectStore that has a keyPath."));178 return 0;179 }180 183 181 184 if (autoIncrement && key) { … … 208 211 RefPtr<IDBKey> keyPathKey = fetchKeyFromKeyPath(value.get(), objectStore->m_keyPath); 209 212 210 if (!keyPathKey) { 211 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "The key could not be fetched from the keyPath.")); 212 return 0; 213 } 214 213 // FIXME: This check should be moved to put() and raise an exception. WK76952 215 214 if (putMode == CursorUpdate && !keyPathKey->isEqual(key)) { 216 215 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "The key fetched from the keyPath does not match the key of the cursor.")); … … 235 234 if (!key) 236 235 return; 237 238 if (key->type() == IDBKey::InvalidType) { 239 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "Not a valid key.")); 240 return; 241 } 236 ASSERT(key->valid()); 242 237 243 238 Vector<RefPtr<IDBKey> > indexKeys; … … 250 245 continue; 251 246 } 252 if (indexKey->type() == IDBKey::InvalidType) { 253 callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "One of the derived (from a keyPath) keys for an index is not valid.")); 254 return; 255 } 247 ASSERT(indexKey->valid()); 256 248 257 249 if ((!index->multiEntry() || indexKey->type() != IDBKey::ArrayType) && !index->addingKeyAllowed(indexKey.get(), key.get())) { … … 340 332 RefPtr<IDBKey> key = prpKey; 341 333 RefPtr<IDBCallbacks> callbacks = prpCallbacks; 342 if ( key->type() == IDBKey::InvalidType) {334 if (!key || !key->valid()) { 343 335 ec = IDBDatabaseException::DATA_ERR; 344 336 return; -
trunk/Source/WebKit/chromium/ChangeLog
r105846 r105891 1 2012-01-25 Joshua Bell <jsbell@chromium.org> 2 3 IndexedDB: Need to distinguish key paths that don't yield value vs. yield invalid key 4 https://bugs.webkit.org/show_bug.cgi?id=76487 5 6 Added a NullType to represent a null IDBKey pointer. This is needed to distinguish the 7 cases in the spec where the key resolution algorithm returns no value (null) versus 8 returns a value but that value is not a valid key (invalid). 9 10 Reviewed by Tony Chang. 11 12 * public/WebIDBKey.h: 13 * src/WebIDBKey.cpp: 14 (WebKit::WebIDBKey::createNull): Added. 15 (WebKit::WebIDBKey::createFromValueAndKeyPath): Now returns null if value is null. 16 (WebKit::convertFromWebIDBKeyArray): Null keys should never exist within arrays. 17 (WebKit::WebIDBKey::assignInvalid): 18 (WebKit::WebIDBKey::assignNull): 19 (WebKit::WebIDBKey::type): 20 1 21 2012-01-24 Vsevolod Vlasov <vsevik@chromium.org> 2 22 -
trunk/Source/WebKit/chromium/public/WebIDBKey.h
r101122 r105891 50 50 WEBKIT_EXPORT static WebIDBKey createNumber(double); 51 51 WEBKIT_EXPORT static WebIDBKey createInvalid(); 52 WEBKIT_EXPORT static WebIDBKey createNull(); 52 53 WEBKIT_EXPORT static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&); 53 54 WEBKIT_EXPORT static WebSerializedScriptValue injectIDBKeyIntoSerializedValue(const WebIDBKey&, const WebSerializedScriptValue&, const WebIDBKeyPath&); … … 66 67 WEBKIT_EXPORT void assignNumber(double); 67 68 WEBKIT_EXPORT void assignInvalid(); 69 WEBKIT_EXPORT void assignNull(); 68 70 WEBKIT_EXPORT void reset(); 69 71 … … 73 75 StringType, 74 76 DateType, 75 NumberType 77 NumberType, 78 NullType, 76 79 }; 77 80 -
trunk/Source/WebKit/chromium/src/WebIDBKey.cpp
r102044 r105891 77 77 } 78 78 79 WebIDBKey WebIDBKey::createNull() 80 { 81 WebIDBKey key; 82 key.assignNull(); 83 return key; 84 } 85 79 86 WebIDBKey WebIDBKey::createFromValueAndKeyPath(const WebSerializedScriptValue& serializedScriptValue, const WebIDBKeyPath& idbKeyPath) 80 87 { 88 // FIXME: If key path is empty string, this should return invalid key instead 81 89 if (serializedScriptValue.isNull()) 82 return WebIDBKey::create Invalid();90 return WebIDBKey::createNull(); 83 91 return createIDBKeyFromSerializedValueAndKeyPath(serializedScriptValue, idbKeyPath); 84 92 } … … 113 121 break; 114 122 case WebIDBKey::InvalidType: 123 case WebIDBKey::NullType: 115 124 ASSERT_NOT_REACHED(); 116 125 break; … … 171 180 void WebIDBKey::assignInvalid() 172 181 { 182 m_private = IDBKey::createInvalid(); 183 } 184 185 void WebIDBKey::assignNull() 186 { 173 187 m_private = 0; 174 188 } … … 182 196 { 183 197 if (!m_private.get()) 184 return InvalidType;198 return NullType; 185 199 return Type(m_private->type()); 186 200 }
Note:
See TracChangeset
for help on using the changeset viewer.