-
Notifications
You must be signed in to change notification settings - Fork 8
About Key Order Preservation
Some features of Salt rely on FIFO (first-in, first-out) objects. That is, the order in which members are added to an object will be repeated when iterating over the same object (with a for-in
loop). The FIFO concept represents the simplest method for indexing object members: a queue. Generally, this order would get compromised by duplicate or piece-meal member additions.
However, an ambiguous ECMAScript specification, cautionary documentation, and warnings from the JavaScript community, advise against depending on FIFO member order. Yet, nearly all JavaScript environments support FIFO members.
...Do we go with what's advised, or with what works?
The following features are at stake, when FIFO member order isn't assured:
-
Program Tags
_over
_bover
- Query Tokens
@child
@next
@oldest
@previous
@youngest
Developers should consider these facts and trends carefully, before using these features of the Salt library.
- The current MDC documentation states, "A for...in loop iterates over the properties of an object in an arbitrary order..."
- Section 12.6.4 of the ECMA-262 specification reads, "The mechanics of enumerating the properties ... is implementation dependent."
- It is widely considered a best-practice to ignore the order of object members.
- The architects and stakeholders of ECMAScript are speculating on preserving key order in future versions of the language.
- All JavaScript engines support FIFO object creation, though it is likely a side-effect from implementing a key index as a queue. (See "The Test" below.)
To survey the consistency of FIFO members within browsers, a jsbin.com page was created and run in over 70 web browsers. The page simply reports the order of members in two objects. The first object is defined as an object-literal. The second object is composed from individual statements.
Note that the member names are important, since changes in Chrome and future versions of the ECMAScript specification treat numeric keys differently. (Due to this behavior, Salt version 0.2.2.2 - then called "Flow" - ignores keys prefixed with an integer.)
Browser screenshots were scrutinized via browershots.com, to determine if the keys were reported in the expected order. To date, no JavaScript runtime has failed FIFO assumptions. Admittedly, the browsershots.com service did not successfully load the page in every browser environment, but the major ones worked. Anyone is free to run the jsbin.com page (or a similar test) anywhere, and report their findings.
Below are the list of environments that have successfully passed the test page.
- Avant 11.7 Windows XP
- Chrome 1.0.154.42 Windows XP
- Chrome 10.0.612.1 Windows XP
- Chrome 10.0.648.204 Ubuntu 9.10
- Chrome 11.0.696.28 Debian Unstable
- Chrome 11.0.696.65 Windows Vista
- Chrome 2.0.160.0 Windows XP
- Chrome 3.0.193.2 Windows XP
- Chrome 9.0.597.107 Windows XP
- Chrome 9.0.597.94 Arch
- Epiphany 2.22 FreeBSD 7.1
- Epiphany 2.22 Ubuntu 8.04 LTS
- Epiphany 2.30.2 Ubuntu 9.10
- Firefox 2.0.0.19 Ubuntu 8.04 LTS
- Firefox 3.0.10 FreeBSD 7.1
- Firefox 3.0.5 Ubuntu 8.04 LTS
- Firefox 3.0.6 Windows XP
- Firefox 3.5.6 Windows XP
- Firefox 3.6 Windows XP
- Firefox 3.6.16 Ubuntu 9.10
- Firefox 4.0 Ubuntu 9.04
- Firefox 4.0 Windows XP
- Flock 2.6 Windows XP
- Flock 2.6.2 Ubuntu 9.04
- Galeon 2.0.4 Ubuntu 8.04 LTS
- Iceape 1.1.13 Debian Testing
- Iceweasel 3.0.4 Debian Testing
- Iceweasel 3.5.18 Debian Unstable
- K-Meleon 1.5.0 Windows XP
- Kazehakase 0.5.2 Ubuntu 8.04 LTS
- Kazehakase 0.5.4 FreeBSD 7.1
- Konqueror 3.5 Debian Testing
- Konqueror 3.5 FreeBSD 7.1
- Konqueror 4.2 Debian Testing
- Konqueror 4.5 Ubuntu 9.04
- Konqueror 4.6 Arch
- Minefield 3.7 Ubuntu 9.10
- Minefield 3.7 Windows XP
- MSIE 6.0 Windows XP
- MSIE 7.0 Windows XP
- MSIE 8.0 Windows XP
- MSIE 9.0 Windows Vista
- Netscape 8.1.3 Windows XP
- Opera 10.00 Debian Testing
- Opera 10.5 Windows XP
- Opera 10.63 Windows XP
- Opera 11.01 Debian Unstable
- Opera 11.1 Windows XP
- Opera 11.10 Ubuntu 9.04
- Opera 11.10 Windows XP
- Opera 7.54 Windows XP
- Opera 8.54 Windows XP
- Opera 9.27 Windows XP
- Opera 9.50 Windows XP
- Opera 9.51 Windows XP
- Opera 9.52 Windows XP
- Opera 9.60 Windows XP
- Opera 9.61 Windows XP
- Opera 9.62 Windows XP
- Opera 9.63 Debian Testing
- Opera 9.63 Windows XP
- Opera 9.64 FreeBSD 7.0
- Opera 9.64 Windows XP
- Opera 9.80 Windows XP
- Safari 4.0 Windows XP
- Safari 5.0.3 Windows XP
- Safari 533.3 Arch
- SeaMonkey 1.1.12 Ubuntu 8.04 LTS
- SeaMonkey 1.1.14 Windows XP
- SeaMonkey 1.1.16 FreeBSD 7.1
- SeaMonkey 2.0 Windows XP
- SeaMonkey 2.0.13 Ubuntu 9.10
- Shiretoko 3.5 Debian Testing
- Shiretoko 3.5 Windows XP
Below are the list of JavaScript environments which have not met FIFO assumptions.
- None (so far)
If your target environment is not present, do use the test url. Add your environment to one of the lists above - so others may know.