- Revision
- 106830
- Author
- [email protected]
- Date
- 2012-02-06 12:00:24 -0800 (Mon, 06 Feb 2012)
Log Message
IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
https://bugs.webkit.org/show_bug.cgi?id=77374
Source/WebCore:
If a put request will use a key generator, try inserting a dummy key during the sync
put() call to check if the key insertion will succeed so an exception can be raised
early, rather than deferring to the asynchronous task.
Reviewed by Tony Chang.
Test: storage/indexeddb/keypath-edges.html
* storage/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::put):
LayoutTests:
Reviewed by Tony Chang.
* storage/indexeddb/keypath-edges-expected.txt:
* storage/indexeddb/keypath-edges.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (106829 => 106830)
--- trunk/LayoutTests/ChangeLog 2012-02-06 19:56:45 UTC (rev 106829)
+++ trunk/LayoutTests/ChangeLog 2012-02-06 20:00:24 UTC (rev 106830)
@@ -1,3 +1,13 @@
+2012-02-06 Joshua Bell <[email protected]>
+
+ IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
+ https://bugs.webkit.org/show_bug.cgi?id=77374
+
+ Reviewed by Tony Chang.
+
+ * storage/indexeddb/keypath-edges-expected.txt:
+ * storage/indexeddb/keypath-edges.html:
+
2012-02-06 Julien Chaffraix <[email protected]>
[Chromium] Test fast/forms/listbox-clear-restore.html is flaky
Modified: trunk/LayoutTests/storage/indexeddb/keypath-edges-expected.txt (106829 => 106830)
--- trunk/LayoutTests/storage/indexeddb/keypath-edges-expected.txt 2012-02-06 19:56:45 UTC (rev 106829)
+++ trunk/LayoutTests/storage/indexeddb/keypath-edges-expected.txt 2012-02-06 20:00:24 UTC (rev 106830)
@@ -45,13 +45,16 @@
transaction = db.transaction(['store-with-path-and-generator'], IDBTransaction.READ_WRITE)
store = transaction.objectStore('store-with-path-and-generator')
-Key path doesn't resolve to a value; should yield null, put request should raise error event
-store.put(null)
-PASS Error event raised: The generated key could not be inserted into the object using the keyPath.
-PASS event.target.errorCode is IDBDatabaseException.DATA_ERR
-PASS event.cancelable is true
-event.preventDefault()
+Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
+Expecting exception from store.put(null)
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.DATA_ERR
+Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception
+Expecting exception from store.put('string')
+PASS Exception was thrown.
+PASS code is IDBDatabaseException.DATA_ERR
+
Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed
store.put({})
PASS store.put succeeded
Modified: trunk/LayoutTests/storage/indexeddb/keypath-edges.html (106829 => 106830)
--- trunk/LayoutTests/storage/indexeddb/keypath-edges.html 2012-02-06 19:56:45 UTC (rev 106829)
+++ trunk/LayoutTests/storage/indexeddb/keypath-edges.html 2012-02-06 20:00:24 UTC (rev 106830)
@@ -88,32 +88,31 @@
store = evalAndLog("store = transaction.objectStore('store-with-path-and-generator')");
debug("");
- debug("Key path doesn't resolve to a value; should yield null, put request should raise error event");
- request = evalAndLog("store.put(null)");
- request._onerror_ = function (e) {
- testPassed("Error event raised: " + e.target.webkitErrorMessage);
- shouldBe("event.target.errorCode", "IDBDatabaseException.DATA_ERR");
- shouldBeTrue("event.cancelable");
- evalAndLog("event.preventDefault()");
+ debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
+ evalAndExpectException("store.put(null)", "IDBDatabaseException.DATA_ERR");
+ debug("");
+ debug("Key path doesn't resolve to a value; should yield null but insertion would fail, so put request should raise exception");
+ evalAndExpectException("store.put('string')", "IDBDatabaseException.DATA_ERR");
+
+ debug("");
+ debug("Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed");
+ request = evalAndLog("store.put({})");
+ request._onerror_ = unexpectedErrorCallback;
+ request._onsuccess_ = function () {
+ testPassed("store.put succeeded");
+
debug("");
- debug("Key path doesn't resolve to a value; should yield null, key should be generated, put request should succeed");
- request = evalAndLog("store.put({})");
+ debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
+ evalAndExpectException("store.put({foo: null})", "IDBDatabaseException.DATA_ERR");
+
+ debug("");
+ debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
+ request = evalAndLog("store.put({foo: 'zoo'})");
request._onerror_ = unexpectedErrorCallback;
request._onsuccess_ = function () {
testPassed("store.put succeeded");
- debug("");
- debug("Key path resolves to a value that is invalid key; should yield 'invalid' key, should throw DATA_ERR");
- evalAndExpectException("store.put({foo: null})", "IDBDatabaseException.DATA_ERR");
-
- debug("");
- debug("Key path resolves to a value that is valid key; should yield 'string' key, should succeed");
- request = evalAndLog("store.put({foo: 'zoo'})");
- request._onerror_ = unexpectedErrorCallback;
- request._onsuccess_ = function () {
- testPassed("store.put succeeded");
- };
};
};
Modified: trunk/Source/WebCore/ChangeLog (106829 => 106830)
--- trunk/Source/WebCore/ChangeLog 2012-02-06 19:56:45 UTC (rev 106829)
+++ trunk/Source/WebCore/ChangeLog 2012-02-06 20:00:24 UTC (rev 106830)
@@ -1,3 +1,19 @@
+2012-02-06 Joshua Bell <[email protected]>
+
+ IndexedDB: Raise exception during add/put call if autoIncrement key insertion will fail
+ https://bugs.webkit.org/show_bug.cgi?id=77374
+
+ If a put request will use a key generator, try inserting a dummy key during the sync
+ put() call to check if the key insertion will succeed so an exception can be raised
+ early, rather than deferring to the asynchronous task.
+
+ Reviewed by Tony Chang.
+
+ Test: storage/indexeddb/keypath-edges.html
+
+ * storage/IDBObjectStoreBackendImpl.cpp:
+ (WebCore::IDBObjectStoreBackendImpl::put):
+
2012-02-06 Gustavo Noronha Silva <[email protected]>
Add a null check for the gdkwindow, that will happen if the window
Modified: trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp (106829 => 106830)
--- trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp 2012-02-06 19:56:45 UTC (rev 106829)
+++ trunk/Source/WebCore/storage/IDBObjectStoreBackendImpl.cpp 2012-02-06 20:00:24 UTC (rev 106830)
@@ -153,6 +153,14 @@
ec = IDBDatabaseException::DATA_ERR;
return;
}
+ if (autoIncrement && !keyPathKey) {
+ RefPtr<IDBKey> dummyKey = IDBKey::createNumber(-1);
+ RefPtr<SerializedScriptValue> valueAfterInjection = injectKeyIntoKeyPath(dummyKey, value, objectStore->m_keyPath);
+ if (!valueAfterInjection) {
+ ec = IDBDatabaseException::DATA_ERR;
+ return;
+ }
+ }
}
if (key && !key->valid()) {
ec = IDBDatabaseException::DATA_ERR;
@@ -208,12 +216,13 @@
if (!key) {
RefPtr<IDBKey> autoIncKey = objectStore->genAutoIncrementKey();
if (hasKeyPath) {
- // FIXME: Add checks in put() to ensure this will always succeed (apart from I/O errors).
- // https://bugs.webkit.org/show_bug.cgi?id=77374
RefPtr<SerializedScriptValue> valueAfterInjection = injectKeyIntoKeyPath(autoIncKey, value, objectStore->m_keyPath);
+ ASSERT(valueAfterInjection);
if (!valueAfterInjection) {
objectStore->resetAutoIncrementKeyCache();
- callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::DATA_ERR, "The generated key could not be inserted into the object using the keyPath."));
+ // Checks in put() ensure this should only happen if I/O error occurs.
+ // FIXME: The Indexed Database specification does not have an error code dedicated to I/O errors.
+ callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UNKNOWN_ERR, "Internal error inserting generated key into the object."));
return;
}
value = valueAfterInjection;