Bugzilla – Bug 15864
[IndexedDB] Array as key, avoid array loops
Last modified: 2012-03-02 16:25:19 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 = a;
I guess you wouldn't want to /recurse/ two of those to find which is biggest ;-)
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
Yeah, we were thinking of solving this in Firefox by simply treating cyclic keys as invalid keys.
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.)
Ah, I knew this sounded familiar.