mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-10 01:56:15 +08:00
Array.prototype.sort and toSorted with a comparator now run V8's TimSort (array-sort.tq) step for step in the runtime, in the generated sort for booleans and unions with undefined, and in the checked-value sort. The comparator is called as f(x, y) < 0 in Node's argument order, so a comparator sees Node's calls in Node's order and an inconsistent comparator yields Node's permutation. Undefined values, including a union's undefined arm, are set aside before sorting and never reach the comparator, and a checked comparator's result converts with ToNumber. Structured inputs take fewer comparator calls than the previous merge sort. Each thread reuses one sort buffer of up to 1 MiB.