W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: [IndexedDB] Array keys / circular references

From: Jonas Sicking <jonas@sicking.cc>
Date: Tue, 1 Nov 2011 10:35:07 -0700
Message-ID: <CA+c2ei_wXsQp=dBrEEMN0SdaQG3-0DWkxPzPf06ewiokX+4sqw@mail.gmail.com>
To: Joshua Bell <jsbell@chromium.org>
Cc: public-webapps@w3.org
On Tue, Nov 1, 2011 at 9:24 AM, Joshua Bell <jsbell@chromium.org> wrote:
> So far as I can see, Section "3.1.3 Keys" doesn't seem to forbid circular
> references in keys which are Array objects, but this will obviously cause
> infinite loops in the comparison algorithm. This is in contrast to values,
> where the structured clone algorithm explicitly deals with cyclic
> references.
> Example:
> var circular_reference = [];
> circular_reference.push(circular_reference); // directly cyclical
> indexedDB.cmp(circular_reference, 0); // Expected behavior?
> var circular_reference2 = [];
> circular_reference2.push([circular_reference2]); // indirectly cyclical
> indexedDB.cmp(circular_reference2, 0); // Expected behavior?
> var circular_reference3 = [];
> circular_reference3.push(circular_reference); // root is fine but child is
> cyclical
> indexedDB.cmp(circular_reference3, 0); // Expected behavior?
> var circular_reference4 = [];
> circular_reference4.non_numeric_property = circular_reference4;
> indexedDB.cmp(circular_reference4, 0); // This should be fine, though.
> I suggest an addition to the text e.g. "However, an Array values is only a
> valid key if every item in the array is defined, if every item in the array
> is a valid key (i.e. sparse arrays can not be valid keys), and if Array
> value is not an item in the Array itself or any other Arrays within the
> value. (i.e. arrays with cyclic references are not valid keys)." (That could
> use a sprinkling of rigor, though.)

Sparse arrays are already defined as invalid keys given that they
contain the value <undefined> which isn't a valid key.

I do agree that we should add some explicit wording saying that cyclic
arrays are invalid keys though. For example calling .get() or creating
a key-range should throw even before that key is used in a comparison.

/ Jonas
Received on Tuesday, 1 November 2011 17:36:12 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:48 GMT