Re: [IndexedDB] Extracting keys and null/undefined

2012-06-29 Thread Jonas Sicking
On Wed, Jun 20, 2012 at 6:24 AM, Kyle Huey m...@kylehuey.com wrote:
 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.

My reading of the spec is that all of the above fail.

 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,

With you so far. 3 and 4 throw due to yielding values which are not valid keys.

 while #1 and #2 go on to receive
 autogenerated keys.

#1 and #2 indeed go on to receive an autogenerated key. This happens
in section 5.1 step 2. This step invokes the algorithm defined in 4.14
in order to modify the value to insert the autogenerated key value.

The algorithm in 4.14 will in step 5 grab the 'foo' property which
will give us 'null' and 'undefined' respectively. We then go back up
to step 2. However this step will result in a DataError being thrown
since 'null' and 'undefined' aren't Object or Array objects.

Hence these will throw too.

(Looking at our tests, this appears to match Firefox behavior)

/ Jonas



[IndexedDB] Extracting keys and null/undefined

2012-06-19 Thread Kyle Huey
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