W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2012

Re: [IndexedDB] Extracting keys and null/undefined

From: Jonas Sicking <jonas@sicking.cc>
Date: Sat, 30 Jun 2012 04:04:55 +0200
Message-ID: <CA+c2ei-FinhQ_ic-GsbGK4fN8jTCovKzCO2AH-TFve6zODRtCQ@mail.gmail.com>
To: Kyle Huey <me@kylehuey.com>
Cc: Web Applications Working Group WG <public-webapps@w3.org>
On Wed, Jun 20, 2012 at 6:24 AM, Kyle Huey <me@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
Received on Saturday, 30 June 2012 02:05:52 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:41 UTC