- Revision
- 105331
- Author
- jsb...@chromium.org
- Date
- 2012-01-18 15:07:26 -0800 (Wed, 18 Jan 2012)
Log Message
IndexedDB: Implement create-intermediate-objects semantics when injecting values via keyPaths
https://bugs.webkit.org/show_bug.cgi?id=76493
Source/WebCore:
Reviewed by Tony Chang.
Tests: storage/indexeddb/objectstore-autoincrement.html
* bindings/v8/IDBBindingUtilities.cpp:
(WebCore::injectIDBKeyIntoSerializedValue):
LayoutTests:
Per discussion on public-webapps, when injecting a key into a value, create intermediate
objects if necessary.
Reviewed by Tony Chang.
* storage/indexeddb/objectstore-autoincrement-expected.txt:
* storage/indexeddb/objectstore-autoincrement.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (105330 => 105331)
--- trunk/LayoutTests/ChangeLog 2012-01-18 23:03:04 UTC (rev 105330)
+++ trunk/LayoutTests/ChangeLog 2012-01-18 23:07:26 UTC (rev 105331)
@@ -1,5 +1,18 @@
2012-01-18 Joshua Bell <jsb...@chromium.org>
+ IndexedDB: Implement create-intermediate-objects semantics when injecting values via keyPaths
+ https://bugs.webkit.org/show_bug.cgi?id=76493
+
+ Per discussion on public-webapps, when injecting a key into a value, create intermediate
+ objects if necessary.
+
+ Reviewed by Tony Chang.
+
+ * storage/indexeddb/objectstore-autoincrement-expected.txt:
+ * storage/indexeddb/objectstore-autoincrement.html:
+
+2012-01-18 Joshua Bell <jsb...@chromium.org>
+
IndexedDB: Invalid keys yielded by key paths should raise exceptions, not error callbacks
https://bugs.webkit.org/show_bug.cgi?id=76075
Modified: trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt (105330 => 105331)
--- trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt 2012-01-18 23:03:04 UTC (rev 105330)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement-expected.txt 2012-01-18 23:07:26 UTC (rev 105331)
@@ -15,13 +15,14 @@
store = db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true})
db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true})
db.createObjectStore('PlainOldStore', {autoIncrement: false})
+db.createObjectStore('StoreWithLongKeyPath', {keyPath: 'a.b.c.id', autoIncrement: true})
storeNames = db.objectStoreNames
PASS store.name is "StoreWithKeyPath"
PASS store.keyPath is 'id'
PASS storeNames.contains('StoreWithKeyPath') is true
PASS storeNames.contains('StoreWithAutoIncrement') is true
PASS storeNames.contains('PlainOldStore') is true
-PASS storeNames.length is 3
+PASS storeNames.length is 4
setVersionCompleted():
trans = db.transaction(['StoreWithKeyPath', 'StoreWithAutoIncrement', 'PlainOldStore'], webkitIDBTransaction.READ_WRITE)
store = trans.objectStore('StoreWithKeyPath')
@@ -62,6 +63,27 @@
store.add({name: 'Adam'}, 1)
addAdamSuccess():
PASS event.target.result is 1
+testLongKeyPath():
+trans = db.transaction('StoreWithLongKeyPath', webkitIDBTransaction.READ_WRITE)
+store = trans.objectStore('StoreWithLongKeyPath')
+store.add({foo: 'bar'})
+store.add({foo: 'bar', a: {}})
+store.add({foo: 'bar', a: {b: {}}})
+store.add({foo: 'bar', a: {b: {c: {}}}})
+store.openCursor()
+expected = null
+count = 0
+expected = cursor.value.a.b.c.id + 1
+PASS cursor.value.foo is 'bar'
+PASS cursor.value.a.b.c.id is expected
+expected = cursor.value.a.b.c.id + 1
+PASS cursor.value.foo is 'bar'
+PASS cursor.value.a.b.c.id is expected
+expected = cursor.value.a.b.c.id + 1
+PASS cursor.value.foo is 'bar'
+PASS cursor.value.a.b.c.id is expected
+expected = cursor.value.a.b.c.id + 1
+PASS count is 4
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html (105330 => 105331)
--- trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html 2012-01-18 23:03:04 UTC (rev 105330)
+++ trunk/LayoutTests/storage/indexeddb/objectstore-autoincrement.html 2012-01-18 23:07:26 UTC (rev 105331)
@@ -43,6 +43,7 @@
window.store = evalAndLog("store = db.createObjectStore('StoreWithKeyPath', {keyPath: 'id', autoIncrement: true})");
evalAndLog("db.createObjectStore('StoreWithAutoIncrement', {autoIncrement: true})");
evalAndLog("db.createObjectStore('PlainOldStore', {autoIncrement: false})");
+ evalAndLog("db.createObjectStore('StoreWithLongKeyPath', {keyPath: 'a.b.c.id', autoIncrement: true})");
var storeNames = evalAndLog("storeNames = db.objectStoreNames");
shouldBeEqualToString("store.name", "StoreWithKeyPath");
@@ -50,7 +51,7 @@
shouldBe("storeNames.contains('StoreWithKeyPath')", "true");
shouldBe("storeNames.contains('StoreWithAutoIncrement')", "true");
shouldBe("storeNames.contains('PlainOldStore')", "true");
- shouldBe("storeNames.length", "3");
+ shouldBe("storeNames.length", "4");
// Let the setVersion transaction complete.
}
@@ -61,7 +62,7 @@
window.trans = evalAndLog("trans = db.transaction(['StoreWithKeyPath', 'StoreWithAutoIncrement', 'PlainOldStore'], webkitIDBTransaction.READ_WRITE)");
trans._onabort_ = unexpectedAbortCallback;
- trans._oncomplete_ = done;
+ trans._oncomplete_ = testLongKeyPath;
window.store = evalAndLog("store = trans.objectStore('StoreWithKeyPath')");
@@ -157,6 +158,45 @@
shouldBe("event.target.result", "1");
}
+function testLongKeyPath()
+{
+ debug("testLongKeyPath():");
+ trans = evalAndLog("trans = db.transaction('StoreWithLongKeyPath', webkitIDBTransaction.READ_WRITE)");
+ trans._onabort_ = unexpectedAbortCallback;
+ trans._oncomplete_ = done;
+
+ store = evalAndLog("store = trans.objectStore('StoreWithLongKeyPath')");
+ request = evalAndLog("store.add({foo: 'bar'})");
+ request._onerror_ = unexpectedErrorCallback;
+ request = evalAndLog("store.add({foo: 'bar', a: {}})");
+ request._onerror_ = unexpectedErrorCallback;
+ request = evalAndLog("store.add({foo: 'bar', a: {b: {}}})");
+ request._onerror_ = unexpectedErrorCallback;
+ request = evalAndLog("store.add({foo: 'bar', a: {b: {c: {}}}})");
+ request._onerror_ = unexpectedErrorCallback;
+ cursorRequest = evalAndLog("store.openCursor()");
+ cursorRequest._onerror_ = unexpectedErrorCallback;
+ evalAndLog("expected = null");
+ evalAndLog("count = 0");
+ cursorRequest._onsuccess_ = function () {
+ cursor = cursorRequest.result;
+ if (!cursor) {
+ shouldBe("count", "4");
+ return;
+ }
+ if (expected === null) {
+ evalAndLog("expected = cursor.value.a.b.c.id + 1");
+ } else {
+ shouldBe("cursor.value.foo", "'bar'");
+ shouldBe("cursor.value.a.b.c.id", "expected");
+ evalAndLog("expected = cursor.value.a.b.c.id + 1");
+ }
+ count++;
+ cursor.continue();
+ };
+}
+
+
test();
Modified: trunk/Source/WebCore/ChangeLog (105330 => 105331)
--- trunk/Source/WebCore/ChangeLog 2012-01-18 23:03:04 UTC (rev 105330)
+++ trunk/Source/WebCore/ChangeLog 2012-01-18 23:07:26 UTC (rev 105331)
@@ -1,5 +1,17 @@
2012-01-18 Joshua Bell <jsb...@chromium.org>
+ IndexedDB: Implement create-intermediate-objects semantics when injecting values via keyPaths
+ https://bugs.webkit.org/show_bug.cgi?id=76493
+
+ Reviewed by Tony Chang.
+
+ Tests: storage/indexeddb/objectstore-autoincrement.html
+
+ * bindings/v8/IDBBindingUtilities.cpp:
+ (WebCore::injectIDBKeyIntoSerializedValue):
+
+2012-01-18 Joshua Bell <jsb...@chromium.org>
+
IndexedDB: Invalid keys yielded by key paths should raise exceptions, not error callbacks
https://bugs.webkit.org/show_bug.cgi?id=76075
Modified: trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp (105330 => 105331)
--- trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp 2012-01-18 23:03:04 UTC (rev 105330)
+++ trunk/Source/WebCore/bindings/v8/IDBBindingUtilities.cpp 2012-01-18 23:07:26 UTC (rev 105331)
@@ -125,6 +125,25 @@
return currentValue;
}
+v8::Handle<v8::Value> ensureNthValueOnKeyPath(v8::Handle<v8::Value>& rootValue, const Vector<String>& keyPathElements, size_t index)
+{
+ v8::Handle<v8::Value> currentValue(rootValue);
+
+ ASSERT(index <= keyPathElements.size());
+ for (size_t i = 0; i < index; ++i) {
+ v8::Handle<v8::Value> parentValue(currentValue);
+ const String& keyPathElement = keyPathElements[i];
+ if (!get(currentValue, keyPathElement)) {
+ v8::Handle<v8::Object> object = v8::Object::New();
+ if (!set(parentValue, keyPathElement, object))
+ return v8::Handle<v8::Value>();
+ currentValue = object;
+ }
+ }
+
+ return currentValue;
+}
+
} // anonymous namespace
PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<String>& keyPath)
@@ -144,7 +163,7 @@
return 0;
v8::Handle<v8::Value> v8Value(value->deserialize());
- v8::Handle<v8::Value> parent(getNthValueOnKeyPath(v8Value, keyPath, keyPath.size() - 1));
+ v8::Handle<v8::Value> parent(ensureNthValueOnKeyPath(v8Value, keyPath, keyPath.size() - 1));
if (parent.IsEmpty())
return 0;