Isiah Meadows wrote:

A polyfill could check if `A.p.sort` is stable, replacing if necessary, and
alias the old one to `A.p.fastSort` if it doesn't exist.

How does one check/test for the stability of a black-box sort? You can't, afaik.

In my opinion, you'll never be able to rely on the stability of `Array.prototype.sort` because of backward-compatibility with older implementations where it is unstable.

As ugly as it might be, I'd recommend a separate `Array.protytype.stableSort` (with an unambiguous name) therefore that can be tested for existence and polyfilled in absence.
Or at least we'd need to tag the available implementations explicitly:
```js
Array.prototype.fastSort[Symbol.isStable] = false;
Array.prototype.stableSort[Symbol.isStable] = true;
Array.prototype.sort[Symbol.isStable] = /* to be chosen by implementer */;
```
which has the benefit that a test `if (…sort[Symbol.isStable])` will yield a falsy default value (`undefined`) in legacy implementations.

Regards,
 Bergi
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to