paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 389 forks source link

Some JS engines don't preserve insertion order for numeric keys. #292

Closed cscott closed 9 years ago

cscott commented 9 years ago

Fixes #290.

ljharb commented 9 years ago

This means that we skip the fast path entirely for engines with this issue. I really like the "testOrder" checks. The numeric solution is clever, but what if I store the string "n1"? I think that in the !preservesNumericInsertionOrder case, we'd need to prefix every single string or numeric key, so that we could unconditionally .slice(1).

Perhaps we could use some combination of this approach, and https://github.com/ljharb/es6-shim/commit/55ce9708e1d8db101a035fce4c71d771a6e1acde, so that we're not totally abandoning the fast path for Chrome?

cscott commented 9 years ago

We're not abandoning the fast path. If you store the string n1 the key $n1 gets used. Write a test case for that if you like. ;)

We already prefix every string, so that's not an issue (nor was it a performance issue when I checked). We now have to prefix numeric keys on some engines, but there's no way around this if you want to maintain O(1) inserts and deletes. (Your ljharb@55ce970 patch doesn't handle deletion.)

ljharb commented 9 years ago

Ah, true.

ljharb commented 9 years ago

Closed via c16e85962be2efe2b8f98eb7110e9a38a89fb7e0