This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 15864 - [IndexedDB] Array as key, avoid array loops
Summary: [IndexedDB] Array as key, avoid array loops
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Target Milestone: ---
Assignee: Eliot Graff
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2012-02-03 12:39 UTC by Odin Hørthe Omdal
Modified: 2012-03-02 16:25 UTC (History)
5 users (show)

See Also:


Description Odin Hørthe Omdal 2012-02-03 12:39:06 UTC
> Note that Arrays that contain other Arrays are allowed as valid keys.
> In this case the algorithm above runs recursively when comparing the
> individual values in the arrays.

Using an array embedding itself makes a loop, the spec doesn't clarify how to deal with that.

var a = [];
a[0] = a;

I guess you wouldn't want to /recurse/ two of those to find which is biggest ;-)
Comment 1 Joshua Bell 2012-02-03 16:55:51 UTC
Agreed that we should add something to "3.1.3 Keys" about this case.

Chromium treats arrays with cyclic references as non-valid keys. This occurs at any level of indirection. The spec dictates that members of an array must be valid keys for the array to be a valid key. Therefore, none of the following are valid keys in Chromium:

var a1 = []; a1.push(a1); // root directly contains self

var a2 = []; a2.push([a2]); // root indirectly contains self

var a3 = [a1]; // member contains self
Comment 2 Jonas Sicking (Not reading bugmail) 2012-02-14 05:01:51 UTC
Yeah, we were thinking of solving this in Firefox by simply treating cyclic keys as invalid keys.
Comment 3 Odin Hørthe Omdal 2012-02-14 08:26:27 UTC
So Sicking's proposal?

> 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.)
Comment 4 Joshua Bell 2012-02-14 16:22:59 UTC
Ah, I knew this sounded familiar.

SGTM, obviously!
Comment 5 Jonas Sicking (Not reading bugmail) 2012-03-02 16:25:19 UTC