10 ms·
I unknowingly relied on undefined behaviour in JavaScript Array.sort; worked fine/as expected in Firefox but then got bug reports that turned out to be Chrome/S
by OJFord 5y ago
I unknowingly relied on undefined behaviour in JavaScript Array.sort; worked fine/as expected in Firefox but then got bug reports that turned out to be Chrome/Safari.
Not just dark corners IMO.
- mattlondon 5y agoInteresting - what were the details? I've never heard of this and rely on this feature all the time so please do share the reproduction so we can all benefit?
- OJFord 5y ago> [2,1,3].sort((a,b) => a < b) Sorts in Firefox (gecko), but not in V8. (resp. `a > b`.) FF: Array(3) [ 3, 2, 1 ] Node: [ 2, 1, 3 ] (Obviously that's a silly example because you'd just `.sort()`, I think I was doing `a.id < b.id` or something, but it's not a significant detail.) You can even reduce the reproduction to `[1,2].sort((a,b) => 1)`. Have fun..!