Bug 15864 - [IndexedDB] Array as key, avoid array loops
[IndexedDB] Array as key, avoid array loops
Status: RESOLVED FIXED
Product: WebAppsWG
Classification: Unclassified
Component: Indexed Database API
unspecified
PC Linux
: P2 normal
: ---
Assigned To: Eliot Graff
public-webapps-bugzilla
:
Depends on:
Blocks:
  Show dependency treegraph
 
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:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.
http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#key-construct

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 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. 

http://lists.w3.org/Archives/Public/public-webapps/2011OctDec/0609.html

SGTM, obviously!
Comment 5 Jonas Sicking 2012-03-02 16:25:19 UTC
http://dvcs.w3.org/hg/IndexedDB/rev/b4158388d1f8

Fixed