[IndexedDB] Extracting keys and null/undefined

Consider an autoincrementing IDBObjectStore with keyPath "foo.bar".

Which of the following (if any) should succeed?

1. objectStore.put({foo: null});
2. objectStore.put({foo: undefined});
3. objectStore.put({foo: {bar: null}});
4. objectStore.put({foo: {bar: undefined}});

By my reading of the spec, currently #1 and #2 succeed, and #3 and #4 do
not.

First, we look at the foo property on the object.  All 4 objects have a foo
property.  We take the value of the foo property and consider that further.
Then we look for a bar property.  Because 'null' and 'undefined' do not
have that property, we return from step 5 of "the steps for extracting a
key from a value using a key path" with no value for #1 and #2.  For #3 and
#4, we return the value of the bar property, null or undefined,
respectively.
IDBObjectStore.put throws if, among other conditions, "the object store
uses in-line keys and the result of evaluating the object store's key path
yields a value and that value is not a valid key."  Since null and
undefined are not valid keys, #3 and #4 are rejected, while #1 and #2 go on
to receive autogenerated keys.

IMO, this is not intuitive behavior.

- Kyle

Received on Wednesday, 20 June 2012 04:24:37 UTC